Add _php_imap_parse_address(), which replaces a lot of duplicated,

hard-to-follow code in imap_headerinfo(). This code also happened to be
broken, causing the $h->to, $h->from, etc arrays to contain only the first
address, not every address. This is fixed now.
This commit is contained in:
Chuck Hagenbuch 2000-03-01 01:35:15 +00:00
parent c87f13951f
commit f19fe37dec

View file

@ -70,9 +70,7 @@ MAILSTREAM DEFAULTPROTO;
#define PHP_EXPUNGE 32768
/* type casts left out, put here to remove warnings in
msvc
*/
/* type casts left out, put here to remove warnings in msvc */
void rfc822_date(char *date);
extern char *cpystr(const char *str);
extern unsigned long find_rightmost_bit (unsigned long *valptr);
@ -80,7 +78,8 @@ void fs_give (void **block);
void *fs_get (size_t size);
static int add_assoc_object(pval *arg, char *key, pval *tmp);
int add_next_index_object(pval *arg, pval *tmp);
void imap_add_body( pval *arg, BODY *body );
void _php_imap_add_body(pval *arg, BODY *body);
void _php_imap_parse_address(ADDRESS *addresslist, char *fulladdress, pval *paddress);
int imap_mail(char *to, char *subject, char *message, char *headers, char *cc, char *bcc, char *rpath);
typedef struct php_imap_le_struct {
@ -834,7 +833,6 @@ void imap_do_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
RETURN_LONG(ind);
}
/* {{{ proto int imap_open(string mailbox, string user, string password [, int options])
Open an IMAP stream to a mailbox */
PHP_FUNCTION(imap_open)
@ -856,7 +854,6 @@ PHP_FUNCTION(imap_popen)
}
/* }}} */
/* {{{ proto int imap_reopen(int stream_id, string mailbox [, int options])
Reopen IMAP stream to new mailbox */
PHP_FUNCTION(imap_reopen)
@ -1387,7 +1384,6 @@ PHP_FUNCTION(imap_list)
/* }}} */
/* {{{ proto array imap_getmailboxes(int stream_id, string ref, string pattern)
Reads the list of mailboxes and returns a full array of objects containing name, attributes, and delimiter */
/* Author: CJH */
@ -1449,7 +1445,6 @@ PHP_FUNCTION(imap_list_full)
/* }}} */
/* {{{ proto array imap_scan(int stream_id, string ref, string pattern, string content)
Read list of mailboxes containing a certain string */
PHP_FUNCTION(imap_listscan)
@ -1593,52 +1588,51 @@ PHP_FUNCTION(imap_undelete)
Read the header of the message */
PHP_FUNCTION(imap_headerinfo)
{
pval *streamind, *msgno, *to, *tovals, *from, *fromvals, *reply_to, *reply_tovals, *sender;
pval *fromlength;
pval *subjectlength;
pval *sendervals, *return_path, *return_pathvals;
pval *cc, *ccvals, *bcc, *bccvals;
pval *defaulthost;
pval *streamind, *msgno, *paddress, *fromlength, *subjectlength, *defaulthost;
int ind, ind_type;
unsigned long length;
pils *imap_le_struct;
MESSAGECACHE * cache;
char *mystring;
char dummy[2000];
char fulladdress[MAILTMPLEN],tempaddress[MAILTMPLEN];
char fulladdress[MAILTMPLEN];
ENVELOPE *en;
ADDRESS *addresstmp,*addresstmp2;
int myargc;
myargc=ARG_COUNT(ht);
int myargc = ARG_COUNT(ht);
if (myargc < 2 || myargc > 5 || getParameters(ht,myargc,&streamind,&msgno,&fromlength,&subjectlength,&defaulthost)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(streamind);
convert_to_long(msgno);
if(myargc >= 3) convert_to_long(fromlength); else fromlength=0x00;;
if (myargc >= 3) convert_to_long(fromlength); else fromlength = 0x00;
if (myargc >= 4) convert_to_long(subjectlength); else subjectlength = 0x00;
if (myargc == 5) convert_to_string(defaulthost);
ind = streamind->value.lval;
ind = streamind->value.lval;
imap_le_struct = (pils *)zend_list_find(ind, &ind_type);
if (!imap_le_struct || !IS_STREAM(ind_type)) {
php_error(E_WARNING, "Unable to find stream pointer");
RETURN_FALSE;
}
if(msgno->value.lval && msgno->value.lval <= imap_le_struct->imap_stream->nmsgs && mail_fetchstructure (imap_le_struct->imap_stream,msgno->value.lval,NIL))
if (!msgno->value.lval || msgno->value.lval < 1 || msgno->value.lval > imap_le_struct->imap_stream->nmsgs) {
php_error(E_WARNING, "Bad message number");
}
if (mail_fetchstructure(imap_le_struct->imap_stream, msgno->value.lval, NIL)) {
cache = mail_elt(imap_le_struct->imap_stream, msgno->value.lval);
else
} else {
RETURN_FALSE;
}
object_init(return_value);
mystring = mail_fetchheader_full(imap_le_struct->imap_stream, msgno->value.lval, NIL, &length, NIL);
if(myargc ==5)
if (myargc == 5) {
rfc822_parse_msg(&en, NULL, mystring, length, NULL, defaulthost->value.str.val, NIL);
else
} else {
rfc822_parse_msg(&en, NULL, mystring, length, NULL, "UNKNOWN", NIL);
}
if (en->remail) add_property_string(return_value, "remail", en->remail,1);
if (en->date) add_property_string(return_value, "date", en->date,1);
@ -1652,264 +1646,77 @@ PHP_FUNCTION(imap_headerinfo)
if (en->references) add_property_string(return_value, "references", en->references,1);
if (en->to) {
int ok=1;
addresstmp=en->to;
fulladdress[0]=0x00;
while(ok && addresstmp) { /* while length < 1000 and we are not at the end of the list */
addresstmp2=addresstmp->next; /* save the pointer to the next address */
addresstmp->next=NULL; /* make this address the only one now. */
tempaddress[0]=0x00; /* reset tempaddress buffer */
rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */
if((strlen(tempaddress) + strlen(fulladdress)) < 1000) { /* is the new address + total address < 1000 */
if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */
strcat(fulladdress,tempaddress); /* put in the new address */
} else { /* no */
ok=0; /* stop looping */
strcat(fulladdress,", ...");
}
addresstmp=addresstmp2; /* reset the pointer to the next address first! */
}
MAKE_STD_ZVAL(paddress);
array_init(paddress);
_php_imap_parse_address(en->to, fulladdress, paddress);
if (fulladdress) add_property_string(return_value, "toaddress", fulladdress, 1);
addresstmp=en->to;
MAKE_STD_ZVAL(to);
array_init(to);
do {
MAKE_STD_ZVAL(tovals);
object_init(tovals);
if(addresstmp->personal) add_property_string(tovals, "personal", addresstmp->personal, 1);
if(addresstmp->adl) add_property_string(tovals, "adl", addresstmp->adl, 1);
if(addresstmp->mailbox) add_property_string(tovals, "mailbox", addresstmp->mailbox, 1);
if(addresstmp->host) add_property_string(tovals, "host", addresstmp->host, 1);
add_next_index_object(to, tovals);
} while ((addresstmp = addresstmp->next));
add_assoc_object(return_value, "to", to);
add_assoc_object(return_value, "to", paddress);
}
if (en->from) {
int ok=1;
addresstmp=en->from;
fulladdress[0]=0x00;
while(ok && addresstmp) { /* while length < 1000 and we are not at the end of the list */
addresstmp2=addresstmp->next; /* save the pointer to the next address */
addresstmp->next=NULL; /* make this address the only one now. */
tempaddress[0]=0x00; /* reset tempaddress buffer */
rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */
if ((strlen(tempaddress) + strlen(fulladdress)) < 1000) { /* is the new address + total address < 1000 */
if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */
strcat(fulladdress,tempaddress); /* put in the new address */
} else { /* no */
ok=0; /* stop looping */
strcat(fulladdress,", ...");
}
addresstmp=addresstmp2; /* reset the pointer to the next address first! */
}
MAKE_STD_ZVAL(paddress);
array_init(paddress);
_php_imap_parse_address(en->from, fulladdress, paddress);
if (fulladdress) add_property_string(return_value, "fromaddress", fulladdress, 1);
addresstmp=en->from;
MAKE_STD_ZVAL(from);
array_init(from);
do {
MAKE_STD_ZVAL(fromvals);
object_init(fromvals);
if(addresstmp->personal) add_property_string(fromvals, "personal", addresstmp->personal, 1);
if(addresstmp->adl) add_property_string(fromvals, "adl", addresstmp->adl, 1);
if(addresstmp->mailbox) add_property_string(fromvals, "mailbox", addresstmp->mailbox, 1);
if(addresstmp->host) add_property_string(fromvals, "host", addresstmp->host, 1);
add_next_index_object(from, fromvals);
} while ((addresstmp = addresstmp->next));
add_assoc_object(return_value, "from", from);
add_assoc_object(return_value, "from", paddress);
}
if (en->cc) {
int ok=1;
addresstmp=en->cc;
fulladdress[0]=0x00;
while(ok && addresstmp) { /* while length < 1000 and we are not at the end of the list */
addresstmp2=addresstmp->next; /* save the pointer to the next address */
addresstmp->next=NULL; /* make this address the only one now. */
tempaddress[0]=0x00; /* reset tempaddress buffer */
rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */
if((strlen(tempaddress) + strlen(fulladdress)) < 1000) { /* is the new address + total address < 1000 */
if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */
strcat(fulladdress,tempaddress); /* put in the new address */
} else { /* no */
ok=0; /* stop looping */
strcat(fulladdress,", ...");
}
addresstmp=addresstmp2; /* reset the pointer to the next address first! */
}
MAKE_STD_ZVAL(paddress);
array_init(paddress);
_php_imap_parse_address(en->cc, fulladdress, paddress);
if (fulladdress) add_property_string(return_value, "ccaddress", fulladdress, 1);
addresstmp=en->cc;
MAKE_STD_ZVAL(cc);
array_init(cc);
do {
MAKE_STD_ZVAL(ccvals);
object_init(ccvals);
if(addresstmp->personal) add_property_string(ccvals, "personal", addresstmp->personal, 1);
if(addresstmp->adl) add_property_string(ccvals, "adl", addresstmp->adl, 1);
if(addresstmp->mailbox) add_property_string(ccvals, "mailbox", addresstmp->mailbox, 1);
if(addresstmp->host) add_property_string(ccvals, "host", addresstmp->host, 1);
add_next_index_object(cc, ccvals);
} while ( (addresstmp = addresstmp->next) );
add_assoc_object(return_value, "cc", cc);
add_assoc_object(return_value, "cc", paddress);
}
if (en->bcc) {
int ok=1;
addresstmp=en->bcc;
fulladdress[0]=0x00;
while(ok && addresstmp) { /* while length < 1000 and we are not at the end of the list */
addresstmp2=addresstmp->next; /* save the pointer to the next address */
addresstmp->next=NULL; /* make this address the only one now. */
tempaddress[0]=0x00; /* reset tempaddress buffer */
rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */
if((strlen(tempaddress) + strlen(fulladdress)) < 1000) { /* is the new address + total address < 1000 */
if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */
strcat(fulladdress,tempaddress); /* put in the new address */
} else { /* no */
ok=0; /* stop looping */
strcat(fulladdress,", ...");
}
addresstmp=addresstmp2; /* reset the pointer to the next address first! */
}
MAKE_STD_ZVAL(paddress);
array_init(paddress);
_php_imap_parse_address(en->bcc, fulladdress, paddress);
if (fulladdress) add_property_string(return_value, "bccaddress", fulladdress, 1);
addresstmp=en->bcc;
MAKE_STD_ZVAL(bcc);
array_init(bcc);
do {
MAKE_STD_ZVAL(bccvals);
object_init(bccvals);
if(addresstmp->personal) add_property_string(bccvals, "personal", addresstmp->personal, 1);
if(addresstmp->adl) add_property_string(bccvals, "adl", addresstmp->adl, 1);
if(addresstmp->mailbox) add_property_string(bccvals, "mailbox", addresstmp->mailbox, 1);
if(addresstmp->host) add_property_string(bccvals, "host", addresstmp->host, 1);
add_next_index_object(bcc, bccvals);
} while ( (addresstmp = addresstmp->next) );
add_assoc_object( return_value, "bcc", bcc );
add_assoc_object(return_value, "bcc", paddress);
}
if (en->reply_to) {
int ok=1;
addresstmp=en->reply_to;
fulladdress[0]=0x00;
while(ok && addresstmp) { /* while length < 1000 and we are not at the end of the list */
addresstmp2=addresstmp->next; /* save the pointer to the next address */
addresstmp->next=NULL; /* make this address the only one now. */
tempaddress[0]=0x00; /* reset tempaddress buffer */
rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */
if((strlen(tempaddress) + strlen(fulladdress)) < 1000) { /* is the new address + total address < 1000 */
if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */
strcat(fulladdress,tempaddress); /* put in the new address */
} else { /* no */
ok=0; /* stop looping */
strcat(fulladdress,", ...");
}
addresstmp=addresstmp2; /* reset the pointer to the next address first! */
}
MAKE_STD_ZVAL(paddress);
array_init(paddress);
_php_imap_parse_address(en->reply_to, fulladdress, paddress);
if (fulladdress) add_property_string(return_value, "reply_toaddress", fulladdress, 1);
addresstmp=en->reply_to;
MAKE_STD_ZVAL(reply_to);
array_init(reply_to);
do {
MAKE_STD_ZVAL(reply_tovals);
object_init(reply_tovals);
if(addresstmp->personal) add_property_string(reply_tovals, "personal", addresstmp->personal, 1);
if(addresstmp->adl) add_property_string(reply_tovals, "adl", addresstmp->adl, 1);
if(addresstmp->mailbox) add_property_string(reply_tovals, "mailbox", addresstmp->mailbox, 1);
if(addresstmp->host) add_property_string(reply_tovals, "host", addresstmp->host, 1);
add_next_index_object(reply_to, reply_tovals );
} while ( (addresstmp = addresstmp->next) );
add_assoc_object( return_value, "reply_to", reply_to );
add_assoc_object(return_value, "reply_to", paddress);
}
if (en->sender) {
int ok=1;
addresstmp=en->sender;
fulladdress[0]=0x00;
while(ok && addresstmp) { /* while length < 1000 and we are not at the end of the list */
addresstmp2=addresstmp->next; /* save the pointer to the next address */
addresstmp->next=NULL; /* make this address the only one now. */
tempaddress[0]=0x00; /* reset tempaddress buffer */
rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */
if((strlen(tempaddress) + strlen(fulladdress)) < 1000) { /* is the new address + total address < 1000 */
if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */
strcat(fulladdress,tempaddress); /* put in the new address */
} else { /* no */
ok=0; /* stop looping */
strcat(fulladdress,", ...");
}
addresstmp=addresstmp2; /* reset the pointer to the next address first! */
}
MAKE_STD_ZVAL(paddress);
array_init(paddress);
_php_imap_parse_address(en->sender, fulladdress, paddress);
if (fulladdress) add_property_string(return_value, "senderaddress", fulladdress, 1);
addresstmp=en->sender;
MAKE_STD_ZVAL(sender);
array_init(sender);
do {
MAKE_STD_ZVAL(sendervals);
object_init(sendervals);
if(addresstmp->personal) add_property_string(sendervals, "personal", addresstmp->personal, 1);
if(addresstmp->adl) add_property_string(sendervals, "adl", addresstmp->adl, 1);
if(addresstmp->mailbox) add_property_string(sendervals, "mailbox", addresstmp->mailbox, 1);
if(addresstmp->host) add_property_string(sendervals, "host", addresstmp->host, 1);
add_next_index_object(sender, sendervals );
} while ( (addresstmp = addresstmp->next) );
add_assoc_object( return_value, "sender", sender );
add_assoc_object(return_value, "sender", paddress);
}
if (en->return_path) {
int ok=1;
addresstmp=en->return_path;
fulladdress[0]=0x00;
while (ok && addresstmp) { /* while length < 1000 and we are not at the end of the list */
addresstmp2=addresstmp->next; /* save the pointer to the next address */
addresstmp->next=NULL; /* make this address the only one now. */
tempaddress[0]=0x00; /* reset tempaddress buffer */
rfc822_write_address(tempaddress,addresstmp); /* ok, write the address into tempaddress string */
if ((strlen(tempaddress) + strlen(fulladdress)) < 1000) { /* is the new address + total address < 1000 */
if(strlen(fulladdress)) strcat(fulladdress,","); /* put in a comma */
strcat(fulladdress,tempaddress); /* put in the new address */
} else { /* no */
ok=0; /* stop looping */
strcat(fulladdress,", ...");
}
addresstmp=addresstmp2; /* reset the pointer to the next address first! */
MAKE_STD_ZVAL(paddress);
array_init(paddress);
_php_imap_parse_address(en->return_path, fulladdress, paddress);
if (fulladdress) add_property_string(return_value, "return_pathaddress", fulladdress, 1);
add_assoc_object(return_value, "return_path", paddress);
}
if(fulladdress) add_property_string( return_value, "return_pathaddress", fulladdress, 1);
addresstmp=en->return_path;
MAKE_STD_ZVAL(return_path);
array_init(return_path);
do {
MAKE_STD_ZVAL(return_pathvals);
object_init(return_pathvals);
if(addresstmp->personal) add_property_string(return_pathvals, "personal", addresstmp->personal, 1);
if(addresstmp->adl) add_property_string(return_pathvals, "adl", addresstmp->adl, 1);
if(addresstmp->mailbox) add_property_string(return_pathvals, "mailbox", addresstmp->mailbox, 1);
if(addresstmp->host) add_property_string(return_pathvals, "host", addresstmp->host, 1);
add_next_index_object(return_path, return_pathvals );
} while ((addresstmp = addresstmp->next));
add_assoc_object( return_value, "return_path", return_path );
}
add_property_string(return_value, "Recent", cache->recent ? (cache->seen ? "R": "N") : " ", 1);
add_property_string(return_value, "Unseen", (cache->recent | cache->seen) ? " " : "U", 1);
add_property_string(return_value, "Flagged", cache->flagged ? "F" : " ", 1);
add_property_string(return_value, "Answered", cache->answered ? "A" : " ", 1);
add_property_string(return_value, "Deleted", cache->deleted ? "D" : " ", 1);
add_property_string(return_value, "Draft", cache->draft ? "X" : " ", 1);
sprintf(dummy, "%4ld", cache->msgno);
add_property_string(return_value, "Msgno",dummy,1);
mail_date(dummy, cache);
add_property_string(return_value, "MailDate", dummy,1);
sprintf(dummy, "%ld", cache->rfc822_size);
add_property_string(return_value, "Size", dummy, 1);
add_property_long(return_value, "udate", mail_longdate(cache));
if (en->from && fromlength) {
@ -1923,10 +1730,8 @@ PHP_FUNCTION(imap_headerinfo)
add_property_string(return_value, "fetchsubject", fulladdress, 1);
}
}
/* }}} */
/* KMLANG */
/* {{{ proto array imap_lsub(int stream_id, string ref, string pattern)
Return a list of subscribed mailboxes */
@ -1971,7 +1776,6 @@ PHP_FUNCTION(imap_lsub)
}
/* }}} */
/* {{{ proto array imap_getsubscribed(int stream_id, string ref, string pattern)
Return a list of subscribed mailboxes */
/* Author: CJH */
@ -2091,111 +1895,6 @@ PHP_FUNCTION(imap_unsubscribe)
}
/* }}} */
void imap_add_body( pval *arg, BODY *body )
{
pval *parametres, *param, *dparametres, *dparam;
PARAMETER *par, *dpar;
PART *part;
if(body->type) add_property_long( arg, "type", body->type );
if(body->encoding) add_property_long( arg, "encoding", body->encoding );
if ( body->subtype ){
add_property_long( arg, "ifsubtype", 1 );
add_property_string( arg, "subtype", body->subtype, 1 );
} else {
add_property_long( arg, "ifsubtype", 0 );
}
if ( body->description ){
add_property_long( arg, "ifdescription", 1 );
add_property_string( arg, "description", body->description, 1 );
} else {
add_property_long( arg, "ifdescription", 0 );
}
if ( body->id ){
add_property_long( arg, "ifid", 1 );
add_property_string( arg, "id", body->id, 1 );
} else {
add_property_long( arg, "ifid", 0 );
}
if(body->size.lines) add_property_long( arg, "lines", body->size.lines );
if(body->size.bytes) add_property_long( arg, "bytes", body->size.bytes );
#ifdef IMAP41
if ( body->disposition.type ){
add_property_long( arg, "ifdisposition", 1);
add_property_string( arg, "disposition", body->disposition.type, 1);
} else {
add_property_long( arg, "ifdisposition", 0);
}
if ( body->disposition.parameter ) {
dpar = body->disposition.parameter;
add_property_long( arg, "ifdparameters", 1);
MAKE_STD_ZVAL(dparametres);
array_init(dparametres);
do {
MAKE_STD_ZVAL(dparam);
object_init(dparam);
add_property_string(dparam, "attribute", dpar->attribute, 1);
add_property_string(dparam, "value", dpar->value, 1);
add_next_index_object(dparametres, dparam );
} while ( (dpar = dpar->next) );
add_assoc_object( arg, "dparameters", dparametres );
} else {
add_property_long( arg, "ifdparameters", 0);
}
#endif
if ( (par = body->parameter) ) {
add_property_long( arg, "ifparameters", 1 );
MAKE_STD_ZVAL(parametres);
array_init(parametres);
do {
MAKE_STD_ZVAL(param);
object_init(param);
if(par->attribute) add_property_string(param, "attribute", par->attribute, 1 );
if(par->value) add_property_string(param, "value", par->value, 1 );
add_next_index_object(parametres, param);
} while ( (par = par->next) );
} else {
MAKE_STD_ZVAL(parametres);
object_init(parametres);
add_property_long( arg, "ifparameters", 0 );
}
add_assoc_object( arg, "parameters", parametres );
/* multipart message ? */
if ( body->type == TYPEMULTIPART ) {
MAKE_STD_ZVAL(parametres);
array_init(parametres);
for ( part = body->CONTENT_PART; part; part = part->next ) {
MAKE_STD_ZVAL(param);
object_init(param);
imap_add_body(param, &part->body );
add_next_index_object(parametres, param );
}
add_assoc_object( arg, "parts", parametres );
}
/* encapsulated message ? */
if ((body->type == TYPEMESSAGE) && (!strcasecmp(body->subtype, "rfc822"))) {
body = body->CONTENT_MSG_BODY;
MAKE_STD_ZVAL(parametres);
array_init(parametres);
MAKE_STD_ZVAL(param);
object_init(param);
imap_add_body(param, body);
add_next_index_object(parametres, param );
add_assoc_object( arg, "parts", parametres );
}
}
/* {{{ proto object imap_fetchstructure(int stream_id, int msg_no [, int options])
Read the full structure of a message */
PHP_FUNCTION(imap_fetchstructure)
@ -2233,7 +1932,7 @@ PHP_FUNCTION(imap_fetchstructure)
RETURN_FALSE;
}
imap_add_body( return_value, body );
_php_imap_add_body(return_value, body);
}
/* }}} */
@ -2904,7 +2603,7 @@ PHP_FUNCTION(imap_sort)
PHP_FUNCTION(imap_fetchheader)
{
pval *streamind, *msgno, *flags;
int ind, ind_type;
int ind, ind_type, msgindex;
pils *imap_le_struct;
int myargc = ARG_COUNT(ht);
if (myargc < 2 || myargc > 3 || getParameters(ht,myargc,&streamind,&msgno,&flags) == FAILURE) {
@ -2922,7 +2621,15 @@ PHP_FUNCTION(imap_fetchheader)
RETURN_FALSE;
}
if ((msgno->value.lval < 1) || (msgno->value.lval > imap_le_struct->imap_stream->nmsgs)) {
if ((myargc == 3) && (flags->value.lval & FT_UID)) {
/* This should be cached; if it causes an extra RTT to the
IMAP server, then that's the price we pay for making sure
we don't crash. */
msgindex = mail_msgno(imap_le_struct->imap_stream, msgno->value.lval);
} else {
msgindex = msgno->value.lval;
}
if ((msgindex < 1) || (msgindex > imap_le_struct->imap_stream->nmsgs)) {
php_error(E_WARNING, "Bad message number");
RETURN_FALSE;
}
@ -3218,11 +2925,12 @@ PHP_FUNCTION(imap_mail_compose)
PART *mypart=NULL, *toppart=NULL, *part;
PARAMETER *param;
char tmp[8*MAILTMPLEN], *mystring=NULL, *t, *tempstring;
int myargc=ARG_COUNT(ht);
int myargc = ARG_COUNT(ht);
if (myargc != 2 || getParameters(ht,myargc,&envelope,&body) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_array(envelope);
convert_to_array(body);
env=mail_newenvelope();
@ -3558,7 +3266,6 @@ PHP_FUNCTION(imap_mail)
}
}
/* }}} */
#endif
/* {{{ proto array imap_search(int stream_id, string criteria [, long flags])
@ -3610,7 +3317,6 @@ PHP_FUNCTION(imap_search)
/* }}} */
/* {{{ proto array imap_alerts(void)
Returns an array of all IMAP alerts that have been generated */
/* Returns an array of all IMAP alerts that have been generated either
@ -3643,7 +3349,6 @@ PHP_FUNCTION(imap_alerts)
}
/* }}} */
/* {{{ proto array imap_errors(void)
Returns an array of all IMAP errors generated */
/* Returns an array of all IMAP errors generated either since the last
@ -3675,7 +3380,6 @@ PHP_FUNCTION(imap_errors)
}
/* }}} */
/* {{{ proto string imap_last_error(void)
Returns the last error that was generated by an IMAP function. The error stack is NOT cleared after this call. */
/* Author: CJH */
@ -3704,10 +3408,150 @@ PHP_FUNCTION(imap_last_error)
/* }}} */
/* Support Functions */
void _php_imap_parse_address (ADDRESS *addresslist, char *fulladdress, pval *paddress)
{
ADDRESS *addresstmp, *addresstmp2;
char tempaddress[MAILTMPLEN];
pval *tmpvals;
int ok = 1;
addresstmp = addresslist;
fulladdress[0] = 0x00;
while (ok && addresstmp) { /* while length < 1000 and we are not at the end of the list */
addresstmp2 = addresstmp->next; /* save the pointer to the next address */
addresstmp->next = NULL; /* make this address the only one now. */
tempaddress[0] = 0x00; /* reset tempaddress buffer */
rfc822_write_address(tempaddress, addresstmp); /* ok, write the address into tempaddress string */
if ((strlen(tempaddress) + strlen(fulladdress)) < 1000) { /* is the new address + total address < 1000 */
if (strlen(fulladdress)) strcat(fulladdress, ","); /* put in a comma */
strcat(fulladdress, tempaddress); /* put in the new address */
} else { /* no */
ok = 0; /* stop looping */
strcat(fulladdress, ", ...");
}
/* DO NOT optimize this out - changing it breaks things */
addresstmp->next = addresstmp2; /* reset the pointer to the next address first! */
addresstmp = addresstmp->next;
}
addresstmp = addresslist;
do {
MAKE_STD_ZVAL(tmpvals);
object_init(tmpvals);
if (addresstmp->personal) add_property_string(tmpvals, "personal", addresstmp->personal, 1);
if (addresstmp->adl) add_property_string(tmpvals, "adl", addresstmp->adl, 1);
if (addresstmp->mailbox) add_property_string(tmpvals, "mailbox", addresstmp->mailbox, 1);
if (addresstmp->host) add_property_string(tmpvals, "host", addresstmp->host, 1);
add_next_index_object(paddress, tmpvals);
} while ((addresstmp = addresstmp->next));
}
void _php_imap_add_body(pval *arg, BODY *body)
{
pval *parametres, *param, *dparametres, *dparam;
PARAMETER *par, *dpar;
PART *part;
if(body->type) add_property_long( arg, "type", body->type );
if(body->encoding) add_property_long( arg, "encoding", body->encoding );
if ( body->subtype ){
add_property_long( arg, "ifsubtype", 1 );
add_property_string( arg, "subtype", body->subtype, 1 );
} else {
add_property_long( arg, "ifsubtype", 0 );
}
if ( body->description ){
add_property_long( arg, "ifdescription", 1 );
add_property_string( arg, "description", body->description, 1 );
} else {
add_property_long( arg, "ifdescription", 0 );
}
if ( body->id ){
add_property_long( arg, "ifid", 1 );
add_property_string( arg, "id", body->id, 1 );
} else {
add_property_long( arg, "ifid", 0 );
}
if(body->size.lines) add_property_long( arg, "lines", body->size.lines );
if(body->size.bytes) add_property_long( arg, "bytes", body->size.bytes );
#ifdef IMAP41
if ( body->disposition.type ){
add_property_long( arg, "ifdisposition", 1);
add_property_string( arg, "disposition", body->disposition.type, 1);
} else {
add_property_long( arg, "ifdisposition", 0);
}
if (body->disposition.parameter) {
dpar = body->disposition.parameter;
add_property_long( arg, "ifdparameters", 1);
MAKE_STD_ZVAL(dparametres);
array_init(dparametres);
do {
MAKE_STD_ZVAL(dparam);
object_init(dparam);
add_property_string(dparam, "attribute", dpar->attribute, 1);
add_property_string(dparam, "value", dpar->value, 1);
add_next_index_object(dparametres, dparam );
} while ( (dpar = dpar->next) );
add_assoc_object( arg, "dparameters", dparametres );
} else {
add_property_long( arg, "ifdparameters", 0);
}
#endif
if ((par = body->parameter)) {
add_property_long( arg, "ifparameters", 1);
MAKE_STD_ZVAL(parametres);
array_init(parametres);
do {
MAKE_STD_ZVAL(param);
object_init(param);
if(par->attribute) add_property_string(param, "attribute", par->attribute, 1 );
if(par->value) add_property_string(param, "value", par->value, 1 );
add_next_index_object(parametres, param);
} while ( (par = par->next) );
} else {
MAKE_STD_ZVAL(parametres);
object_init(parametres);
add_property_long( arg, "ifparameters", 0);
}
add_assoc_object( arg, "parameters", parametres );
/* multipart message ? */
if (body->type == TYPEMULTIPART) {
MAKE_STD_ZVAL(parametres);
array_init(parametres);
for (part = body->CONTENT_PART; part; part = part->next) {
MAKE_STD_ZVAL(param);
object_init(param);
_php_imap_add_body(param, &part->body);
add_next_index_object(parametres, param);
}
add_assoc_object(arg, "parts", parametres);
}
/* encapsulated message ? */
if ((body->type == TYPEMESSAGE) && (!strcasecmp(body->subtype, "rfc822"))) {
body = body->CONTENT_MSG_BODY;
MAKE_STD_ZVAL(parametres);
array_init(parametres);
MAKE_STD_ZVAL(param);
object_init(param);
_php_imap_add_body(param, body);
add_next_index_object(parametres, param);
add_assoc_object(arg, "parts", parametres);
}
}
/* Interfaces to C-client */
void mm_searched (MAILSTREAM *stream,unsigned long number)
{
MESSAGELIST *cur = NIL;
@ -3728,22 +3572,18 @@ void mm_searched (MAILSTREAM *stream,unsigned long number)
}
}
void mm_exists (MAILSTREAM *stream,unsigned long number)
{
}
void mm_expunged (MAILSTREAM *stream,unsigned long number)
{
}
void mm_flags (MAILSTREAM *stream,unsigned long number)
{
}
/* Author: CJH */
void mm_notify (MAILSTREAM *stream,char *str, long errflg)
{
@ -3932,23 +3772,19 @@ void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
#endif
}
void mm_critical (MAILSTREAM *stream)
{
}
void mm_nocritical (MAILSTREAM *stream)
{
}
long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
{
return 1;
}
void mm_fatal (char *str)
{
}