cvs: /php4/ext/imap php_imap.c
| From: | tedp | Date: | Fri, 28 Apr 2000 14:25:09 +0000 |
| Subject: | cvs: /php4/ext/imap php_imap.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-14149@lists.php.net to get a copy of this message | ||
tedp Fri Apr 28 07:25:09 2000 EDT
Modified files:
/php4/ext/imap php_imap.c
Log:
Removed bug that prevented it to work on longer strings.
Changed commenting to c-style commenting.
Index: php4/ext/imap/php_imap.c
diff -u php4/ext/imap/php_imap.c:1.19 php4/ext/imap/php_imap.c:1.20
--- php4/ext/imap/php_imap.c:1.19 Mon Apr 24 15:21:34 2000
+++ php4/ext/imap/php_imap.c Fri Apr 28 07:24:38 2000
@@ -23,7 +23,7 @@
| PHP 4.0 updates: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_imap.c,v 1.19 2000/04/24 22:21:34 askalski Exp $ */
+/* $Id: php_imap.c,v 1.20 2000/04/28 14:24:38 tedp Exp $ */
#define IMAP41
@@ -3425,6 +3425,7 @@
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 <ted@mtv.se> */
zval **str, *myobject;
char *string, *charset, encoding, *text, *decode;
long charset_token, encoding_token, end_token, end, offset=0, i;
@@ -3445,11 +3446,11 @@
if ((charset=((char *)emalloc((end+1)*2)))) {
text=&charset[end+1];
- while(offset<end) { // Reached end of the string?
- if ((charset_token=(long) php_memnstr(&string[offset], "=?", 2, string+end)))
{ // Is there anything encoded in the string?
+ while(offset<end) { /* Reached end of the string? */
+ if ((charset_token=(long) php_memnstr(&string[offset], "=?", 2, string+end))) { /*
Is there anything encoded in the string? */
charset_token -= (long)string;
- if (offset!=charset_token) { // Is there anything before the encoded data?
- // Retrieve unencoded data that is found at the beginning
+ if (offset!=charset_token) { /* Is there anything before the encoded data? */
+ /* Retrieve unencoded data that is found before encoded data */
memcpy(text, &string[offset], charset_token-offset);
text[charset_token-offset]=0x00;
MAKE_STD_ZVAL(myobject);
@@ -3458,21 +3459,21 @@
add_property_string(myobject, "text", text, 1);
zend_hash_next_index_insert(return_value->value.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 @@
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+i<end)) offset+=i;
+ continue; /*/ Iterate the loop again please. */
}
}
} else {
- // Just some tweaking to optimize the code, and get the end statements work in a general
manner.
- // If we end up here we didn't find a position for "charset_token",
- // so we need to set it to the start of the yet unextracted data.
+ /* Just some tweaking to optimize the code, and get the end statements work in a general
manner.
+ If we end up here we didn't find a position for "charset_token",
+ so we need to set it to the start of the yet unextracted data. */
charset_token=offset;
}
- // Return the rest of the data as unencoded, as it was either unencoded or was missing
separators
- // which rendered the the remainder of the string impossible for us to decode.
- memcpy(text, &string[charset_token], end-charset_token); // Extract unencoded text from
string
+ /* Return the rest of the data as unencoded, as it was either unencoded or was missing
separators
+ which rendered the the remainder of the string impossible for us to decode. */
+ memcpy(text, &string[charset_token], end-charset_token); /* Extract unencoded text from
string */
text[end-charset_token]=0x00;
MAKE_STD_ZVAL(myobject);
object_init(myobject);
@@ -3504,7 +3504,7 @@
add_property_string(myobject, "text", text, 1);
zend_hash_next_index_insert(return_value->value.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 @@
} 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;
}