--- src/imapd/imapd.c.orig	Wed Mar  5 04:19:17 1997
+++ src/imapd/imapd.c	Fri Mar 14 22:14:44 1997
@@ -44,6 +44,7 @@
 extern int errno;		/* just in case */
 #include <sys/stat.h>
 #include "misc.h"
+#include "libtrans.h"
 
 
 /* Autologout timer */
@@ -2428,7 +2429,11 @@
 void ptext (char *s,unsigned long i)
 {
   unsigned long j;
-  for (j = 0; i -= j; j = fwrite (s + j,1,i,stdout));
+  unsigned long k;
+  char *p = (char*)fs_get(i);
+  for (k = 0; k < i; k++) p[k] = TR_OUT(s[k]);
+  for (j = 0; i -= j; j = fwrite (p + j,1,i,stdout));
+  fs_give((void**)&p);
 }
 
 /* Anonymous users may only use these mailboxes in these namespaces */
--- src/ipopd/ipop3d.c.orig	Wed Mar  5 04:19:07 1997
+++ src/ipopd/ipop3d.c	Fri Mar 14 22:14:44 1997
@@ -45,6 +45,7 @@
 #include <signal.h>
 #include "misc.h"
 
+#include "libtrans.h"
 
 /* Autologout timer */
 #define TIMEOUT 60*30
@@ -454,7 +455,7 @@
   if (c == '.') putchar ('.');	/* double string-leading dot if necessary */
   while (lines && --size) {	/* copy loop */
     e = *text++;		/* get next byte */
-    putchar (c);		/* output character */
+    putchar (TR_OUT(c));	/* output character */
     if (c == '\012') {		/* end of line? */
       ret++; --lines;		/* count another line */
 				/* double leading dot as necessary */
--- src/ipopd/ipop2d.c.orig	Wed Mar  5 04:19:12 1997
+++ src/ipopd/ipop2d.c	Fri Mar 14 22:17:12 1997
@@ -43,6 +43,7 @@
 #include <errno.h>
 extern int errno;		/* just in case */
 #include "misc.h"
+#include "libtrans.h"
 
 
 /* Autologout timer */
@@ -341,6 +342,8 @@
 
 short c_retr (char *t)
 {
+  char *p;
+
   if (t) {			/* disallow argument */
     puts ("- Bogus argument given to RETR\015");
     return DONE;
@@ -348,6 +351,7 @@
   if (size) {			/* message size valid? */
     unsigned long i,j;
     t = mail_fetch_header (stream,msg[current],NIL,NIL,&i,FT_PEEK);
+    for (p=t;p<t+i;p++) *p=TR_OUT(*p);
     if (i > 2) {		/* only if there is something */
       i -= 2;			/* lop off last two octets */
       while (i) {		/* blat the header */
@@ -358,6 +362,7 @@
     fputs (status,stdout);	/* yes, output message */
     puts ("\015");		/* delimit header from text */
     t = mail_fetch_text (stream,msg[current],NIL,&i,NIL);
+    for (p=t;p<t+i;p++) *p=TR_OUT(*p);
     while (i) {			/* blat the text */
       j = fwrite (t,sizeof (char),i,stdout);
       if (i -= j) t += j;	/* advance to incomplete data */
--- src/osdep/unix/env_unix.c.orig	Thu Nov 28 08:15:39 1996
+++ src/osdep/unix/env_unix.c	Fri Mar 14 22:14:44 1997
@@ -82,6 +82,7 @@
 #include <signal.h>
 #include <sys/wait.h>
 #include "write.c"		/* include safe writing routines */
+#include "libtrans.h"
 
 /* Get all authenticators */
 
@@ -400,11 +401,30 @@
 char *mylocalhost ()
 {
   char tmp[MAILTMPLEN];
+  struct sockaddr_in sck;
+  int scksz=sizeof(sck);
   struct hostent *host_name;
+  char lang[4];
   if (!myLocalHost) {
-    gethostname(tmp,MAILTMPLEN);/* get local host name */
-    myLocalHost = cpystr ((host_name = gethostbyname (tmp)) ?
-			  host_name->h_name : tmp);
+    if (getsockname(0,(struct sockaddr*)&sck,&scksz) < 0) {
+      if ((errno == ENOTSOCK) || (errno == EINVAL)) {
+	/* this was a redirected connection */
+	gethostname(tmp,MAILTMPLEN);
+	myLocalHost = cpystr ((host_name = gethostbyname (tmp)) ?
+			host_name->h_name : tmp);
+      } else {
+	perror("getsockname");
+      }
+    } else { /* the other end is a socket - back-resolve */
+      host_name=gethostbyaddr((char *)&sck.sin_addr.s_addr,
+			sizeof(sck.sin_addr.s_addr),sck.sin_family);
+      if (host_name)
+	myLocalHost = cpystr(host_name->h_name);
+    }
+    if (myLocalHost == NULL) fatal("Cannot resolve local host name");
+    strncpy(lang,myLocalHost,3);
+    lang[4]='\0';
+    settrtab_byname(lang);
   }
   return myLocalHost;
 }
