summaryrefslogtreecommitdiff
path: root/ext/imap/php_imap.c
diff options
context:
space:
mode:
authorTed Rolle Jr <tedp@php.net>2000-04-28 14:24:38 +0000
committerTed Rolle Jr <tedp@php.net>2000-04-28 14:24:38 +0000
commitb7f2d80a2865623a1e45bca7cdcc6f7c476459d9 (patch)
treea134e68dd292448d0994746b5ae7961826123213 /ext/imap/php_imap.c
parent105be1513d27b87e85eb5db02c42d666f01e1ae2 (diff)
downloadphp-git-b7f2d80a2865623a1e45bca7cdcc6f7c476459d9.tar.gz
Removed bug that prevented it to work on longer strings.
Changed commenting to c-style commenting.
Diffstat (limited to 'ext/imap/php_imap.c')
-rw-r--r--ext/imap/php_imap.c51
1 files 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 <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 @@ PHP_FUNCTION(imap_mime_header_decode)
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 @@ PHP_FUNCTION(imap_mime_header_decode)
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 @@ 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+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 @@ PHP_FUNCTION(imap_mime_header_decode)
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 @@ 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;
}