Article delegate-en/3475 of [1-5098] on the server localhost:119
  upper oldest olders older1 this newer1 newers latest
search
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
[Reference:<_A3473@delegate-en.ML_>]
Newsgroups: mail-lists.delegate-en

Re: Pop3proxy -- Timeout with malformed MimeMessages
30 Aug 2006 15:37:12 GMT     feedback@delegate.org (Yutaka Sato)
The DeleGate Project

Hi,

In message <_A3473@delegate-en.ML_> on 08/30/06(21:04:13)
you Gateman <pz4dabdyi-e6c2bbnaf5h6.ml@delegate.org> wrote:
 |we use delegate(V9.1.1)as a pop3proxy and have problems with some
 |malformed mime messages.
 |Delegate strips of some part of the message so that the client doesn't 
 |see the end of the message.
 |
 |Connecting direct to the pop3-Server  the mail is transfer without 
 |problems.
 |
 |
 |The original message has  after the last mine boundary  about 1500 
 |spaces (0x20) and then the EOF-Sequenz,  0D0A0E0D0A.

Your dump shows it's not 0x20 but 0x00 which is a string terminator
of C, and not 0E0D0A but 2E0D0A which is a message terminator of POP
(and SMTP, NNTP).

 |Delegate strips away all the spaces and sends then only 0E0D0A.
 |The client wait  for 0D0A0E0D0A   as EOF-mark,
 |so after  60 sec he has a timeout and disconnects the session.

The problem is caused because DeleGate uses fgets() and fputs() to
get and put the message on POP.
A simple workaround to escape the problem is encoding '\0' into
0xC0 0x80 (or \300\200, UTF-8 string which represents zero) at
the input, and decoding it at the output.  It can be done like the
enclosed patch (a patch to be applied to DeleGate/9.2.4-pre19).

Cheers,
Yutaka
--
  9 9   Yutaka Sato <y.sato@delegate.org> http://delegate.org/y.sato/
 ( ~ )  National Institute of Advanced Industrial Science and Technology
_<   >_ 1-1-4 Umezono, Tsukuba, Ibaraki, 305-8568 Japan
Do the more with the less -- B. Fuller


diff -cr ../arc/delegate9.2.4-pre19/mimekit/mime.c ./mimekit/mime.c
*** ../arc/delegate9.2.4-pre19/mimekit/mime.c	Wed Aug 23 17:46:50 2006
--- ./mimekit/mime.c	Thu Aug 31 00:18:10 2006
***************
*** 24,29 ****
--- 24,72 ----
  #define strid_alloc(s)	stralloc(s)
  #endif
  
+ /* represent zero in UTF-8 {0xC0 0x80} without string terminator '\0' */
+ const char *fgetsZ(PVStr(str),int siz,FILE *fp){
+ 	int ch;
+ 	refQStr(sp,str);
+ 	const char *sx;
+ 
+ 	sx = &str[siz-1];
+ 	for( sp = str; sp < sx; ){
+ 		ch = getc(fp);
+ 		if( ch == EOF )
+ 			break;
+ 		if( ch == 0 ){
+ 			setVStrPtrInc(sp,0xC0);
+ 			setVStrPtrInc(sp,0x80);
+ 		}else{
+ 			setVStrPtrInc(sp,ch);
+ 		}
+ 	}
+ 	setVStrEnd(sp,0);
+ 	if( sp == str && feof(fp) )
+ 		return NULL;
+ 	return str;
+ }
+ int fputsZ(PCStr(str),FILE *fp){
+ 	const unsigned char *sp;
+ 	unsigned char ch;
+ 
+ 	for( sp = (const unsigned char*)str; ch = *sp; sp++ ){
+ 		if( ch == 0xC0 && sp[1] == 0x80 ){
+ 			putc(0,fp);
+ 			sp++;
+ 		}else{
+ 			putc(ch,fp);
+ 		}
+ 	}
+ 	return 0;
+ }
+ #undef fgets
+ #undef fputs
+ const char *fgetsZ(PVStr(str),int siz,FILE *fp);
+ #define fgets(s,z,f)	fgetsZ(AVStr(s),z,f)
+ #define fputs(s,f)	fputsZ(s,f)
+ 
  static int encodeMIMEpart(const char *boundaries[],FILE*fc,FILE*ts,FILE*cache,int filter,int _);
  static int decodeMIMEpart(const char *boundaries[],FILE*fs,FILE*tc,FILE*cache,int filter,int enHTML);
  
***************
*** 598,604 ****
--- 641,650 ----
  			}
  			skipping = 0;
  
+ 			/*
  			wordscanY(hp,AVStr(cur_field),sizeof(cur_field),"^: \t\r\n");
+ 			*/
+ 			wordscanY(hp,AVStr(cur_field),sizeof(cur_field),"^: \300\t\r\n");
  			conv_field = strncasecmp(hp,"Subject:",8) == 0
  				  || strncasecmp(hp,"From:",5) == 0;
  
diff -cr ../arc/delegate9.2.4-pre19/mimekit/rfc822.c ./mimekit/rfc822.c
*** ../arc/delegate9.2.4-pre19/mimekit/rfc822.c	Thu May  4 03:11:12 2006
--- ./mimekit/rfc822.c	Thu Aug 31 00:13:55 2006
***************
*** 24,29 ****
--- 24,35 ----
  void RFC822_strip_lwsp(PCStr(src),PVStr(dst),int size);
  int replace_charset_value(PVStr(ctype),PCStr(charset),int force);
  
+ #undef fgets
+ const char *fgetsZ(PVStr(str),int siz,FILE *fp);
+ int fputsZ(PCStr(str),FILE *fp);
+ #define fgets(s,z,f)	fgetsZ(AVStr(s),z,f)
+ #define fputs(s,f)	fputsZ(s,f)
+ 
  #define getFieldValue(str,fld,buf,siz) getFieldValue2(str,fld,buf,siz)
  
  char *findField(PCStr(head),PCStr(field),const char **value)
  admin search upper oldest olders older1 this newer1 newers latest
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
Generated:07/28 21:20:07 (0 sec) Expires:07/28 21:20:07 @_@V