From b7f2d80a2865623a1e45bca7cdcc6f7c476459d9 Mon Sep 17 00:00:00 2001 From: Ted Rolle Jr Date: Fri, 28 Apr 2000 14:24:38 +0000 Subject: [PATCH] Removed bug that prevented it to work on longer strings. Changed commenting to c-style commenting. --- ext/imap/php_imap.c | 51 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 2f75f0fc6f..c68235b756 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -3425,6 +3425,7 @@ PHP_FUNCTION(imap_last_error) Decode mime header element in accordance with RFC 2047 and return array of objects containing 'charset' encoding and decoded 'text' */ PHP_FUNCTION(imap_mime_header_decode) { + /* Author: Ted Parnefors */ zval **str, *myobject; char *string, *charset, encoding, *text, *decode; long charset_token, encoding_token, end_token, end, offset=0, i; @@ -3445,11 +3446,11 @@ PHP_FUNCTION(imap_mime_header_decode) if ((charset=((char *)emalloc((end+1)*2)))) { text=&charset[end+1]; - while(offsetvalue.ht,(void *)&myobject,sizeof(zval *),NULL); } - if ((encoding_token=(long) php_memnstr(&string[charset_token+2], "?", 1, string+end))) { // Find token for encoding + if ((encoding_token=(long) php_memnstr(&string[charset_token+2], "?", 1, string+end))) { /* Find token for encoding */ encoding_token -= (long) string; - if ((end_token=(long) php_memnstr(&string[encoding_token+1], "?=", 2, string+end))) { // Find token for end of encoded data + if ((end_token=(long) php_memnstr(&string[encoding_token+1], "?=", 2, string+end))) { /* Find token for end of encoded data */ end_token -= (long) string; - memcpy(charset, &string[charset_token+2], encoding_token-(charset_token+2)); // Extract charset encoding + memcpy(charset, &string[charset_token+2], encoding_token-(charset_token+2)); /* Extract charset encoding */ charset[encoding_token-(charset_token+2)]=0x00; - encoding=string[encoding_token+1]; // Extract encoding from string - memcpy(text, &string[encoding_token+3], end_token-(encoding_token+3)); // Extract text + encoding=string[encoding_token+1]; /* Extract encoding from string */ + memcpy(text, &string[encoding_token+3], end_token-(encoding_token+3)); /* Extract text */ text[end_token-(encoding_token+3)]=0x00; decode=text; - if (encoding=='q' || encoding=='Q') { // Decode 'q' encoded data - for(i=0;text[i]!=0x00;i++) if (text[i]=='_') text[i]=' '; // Replace all *_' with space. + if (encoding=='q' || encoding=='Q') { /* Decode 'q' encoded data */ + for(i=0;text[i]!=0x00;i++) if (text[i]=='_') text[i]=' '; /* Replace all *_' with space. */ decode = (char *) rfc822_qprint((unsigned char *) text, strlen(text), &newlength); } else if (encoding=='b' || encoding=='B') { - decode = (char *) rfc822_base64((unsigned char *) text, strlen(text), &newlength); // Decode 'B' encoded data + decode = (char *) rfc822_base64((unsigned char *) text, strlen(text), &newlength); /* Decode 'B' encoded data */ } MAKE_STD_ZVAL(myobject); object_init(myobject); @@ -3481,22 +3482,21 @@ PHP_FUNCTION(imap_mime_header_decode) zend_hash_next_index_insert(return_value->value.ht,(void *)&myobject,sizeof(zval *),NULL); fs_give((void**) &decode); - offset+=end_token+2; - if (string[offset]==' ' && string[offset+1]=='=' && string[offset+2]=='?') { - offset++; // Remove required space between encoded segments - } - continue; // Iterate the loop again please. + offset=end_token+2; + for(i=0;(string[offset+i]==' ') || (string[offset+i]==0x0a) || (string[offset+i]==0x0d);i++); + if((string[offset+i]=='=') && (string[offset+i+1]=='?') && (offset+ivalue.ht,(void *)&myobject,sizeof(zval *),NULL); - offset=end; // We have reached the end of the string. + offset=end; /* We have reached the end of the string. */ } efree(charset); } else { @@ -3538,8 +3538,7 @@ void _php_imap_parse_address (ADDRESS *addresslist, char *fulladdress, zval *pad } else { /* no */ ok = 0; /* stop looping */ strcat(fulladdress, ", ..."); - } - /* DO NOT optimize this out - changing it breaks things */ + } /* DO NOT optimize this out - changing it breaks things */ addresstmp->next = addresstmp2; /* reset the pointer to the next address first! */ addresstmp = addresstmp->next; } -- 2.40.0