Re: patch to add imap_search

From: Date: Sat, 24 Jul 1999 03:16:56 +0000
Subject: Re: patch to add imap_search
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-9085@lists.php.net to get a copy of this message
Quoting Chuck Hagenbuch <chagenbu@wso.williams.edu>: > Hi. Attached is a patch to add imap_search to php3. *sigh* I don't think I've managed to get this right yet. Severe brain block. I'll throw in a test script this time for good measure... -chuck -- Charles Hagenbuch, <chagenbu@wso.williams.edu> -- must... find... acorns... *thud*

Index: functions/imap.c =================================================================== RCS file: /repository/php3/functions/imap.c,v retrieving revision 1.57 diff -u -r1.57 imap.c --- functions/imap.c 1999/07/02 21:05:17 1.57 +++ functions/imap.c 1999/07/24 03:03:27 @@ -118,6 +118,10 @@ struct php3_imap_error_struct *next; } ERRORLIST; +typedef struct php3_imap_message_struct { + unsigned long msgid; + struct php3_imap_message_struct *next; +} MESSAGELIST; MAILSTREAM *mail_close_it (pils *imap_le_struct); #ifdef OP_RELOGIN @@ -188,6 +192,7 @@ {"imap_alerts", php3_imap_alerts, NULL}, {"imap_errors", php3_imap_errors, NULL}, {"imap_last_error", php3_imap_last_error, NULL}, + {"imap_search", php3_imap_search, NULL}, {NULL, NULL, NULL} }; @@ -213,7 +218,7 @@ } folderlist_style_t; /* - I beleive since this global is used ONLY within this module, + I believe since this global is used ONLY within this module, and nothing will link to this module, we can use the simple thread local storage */ @@ -224,10 +229,15 @@ #endif char imap_user[80]=""; char imap_password[80]=""; +#ifdef HAVE_IMSP +extern char imsp_user[80]; +extern char imsp_password[80]; +#endif STRINGLIST *imap_folders=NIL; STRINGLIST *imap_sfolders=NIL; STRINGLIST *imap_alertstack=NIL; ERRORLIST *imap_errorstack=NIL; +MESSAGELIST *imap_messages=NIL; FOBJECTLIST *imap_folder_objects=NIL; FOBJECTLIST *imap_sfolder_objects=NIL; folderlist_style_t folderlist_style = FLIST_ARRAY; @@ -337,6 +347,27 @@ } } +/* Mail instantiate MESSAGELIST + * Returns: new MESSAGELIST list + * Author: CJH + */ +MESSAGELIST *mail_newmessagelist (void) +{ + return (MESSAGELIST *) memset(fs_get(sizeof(MESSAGELIST)),0, + sizeof(MESSAGELIST)); +} + +/* Mail garbage collect MESSAGELIST + * Accepts: pointer to MESSAGELIST pointer + * Author: CJH + */ +void mail_free_messagelist (MESSAGELIST **msglist) +{ + if (*msglist) { /* only free if exists */ + mail_free_messagelist (&(*msglist)->next); + fs_give ((void **) msglist); /* return string to free storage */ + } +} /* Author: CJH */ int imap_init_request (INIT_FUNC_ARGS) { @@ -598,8 +629,6 @@ pval *options; MAILSTREAM *imap_stream; pils *imap_le_struct; - list_entry new_le; - list_entry *le; long flags=NIL; long cl_flags=NIL; #ifdef OP_RELOGIN @@ -1987,7 +2016,7 @@ } mail_free_foblist (&imap_sfolder_objects); efree(delim); - folderlist_style = FLIST_ARRAY; // reset to default + folderlist_style = FLIST_ARRAY; /* reset to default */ } /* }}} */ @@ -3109,12 +3138,77 @@ /* }}} */ +/* {{{ proto array imap_search(int stream_id, string criteria [, long flags]) + Return a list of messages matching the criteria. */ +void php3_imap_search(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *streamind, *criteria, *search_flags; + int ind, ind_type, args; + pils *imap_le_struct; + long flags; + MESSAGELIST *cur; + + args = ARG_COUNT(ht); + if (args < 2 || args > 3 || getParameters(ht, args, &streamind, &criteria, &search_flags) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(streamind); + convert_to_string(criteria); + + if (args == 2) { + flags = SE_FREE; + } else { + convert_to_long(search_flags); + flags = search_flags->value.lval; + } + + ind = streamind->value.lval; + imap_le_struct = (pils *)php3_list_find(ind, &ind_type); + if (!imap_le_struct || !IS_STREAM(ind_type)) { + php3_error(E_WARNING, "Unable to find stream pointer"); + RETURN_FALSE; + } + + imap_messages = NIL; + mail_search_full(imap_le_struct->imap_stream, NIL, mail_criteria(criteria->value.str.val), flags); + if (imap_messages == NIL) { + RETURN_FALSE; + } + + array_init(return_value); + cur = imap_messages; + while (cur != NIL) { + add_next_index_long(return_value, cur->msgid); + cur = cur->next; + } + mail_free_messagelist(&imap_messages); +} +/* }}} */ + + /* Interfaces to C-client */ void mm_searched (MAILSTREAM *stream,unsigned long number) { + MESSAGELIST *cur = NIL; + + if (imap_messages == NIL) { + imap_messages = mail_newmessagelist(); + imap_messages->msgid = number; + imap_messages->next = NIL; + } else { + cur = imap_messages; + while (cur->next != NIL) { + cur = cur->next; + } + cur->next = mail_newmessagelist(); + cur = cur->next; + cur->msgid = number; + cur->next = NIL; + } } @@ -3298,14 +3392,29 @@ php debugger? */ } +/* CJH: check the service name in order to allow different IMSP + usernames & passwords */ void mm_login (NETMBX *mb,char *user,char *pwd,long trial) { - if (*mb->user) { - strcpy (user,mb->user); +#ifdef HAVE_IMSP + if (*mb->service && strcmp(mb->service, "imsp") == 0) { + if (*mb->user) { + strcpy(user, mb->user); + } else { + strcpy(user, imsp_user); + } + strcpy (pwd,imsp_password); } else { - strcpy (user,imap_user); +#endif + if (*mb->user) { + strcpy(user, mb->user); + } else { + strcpy(user, imap_user); + } + strcpy(pwd, imap_password); +#ifdef HAVE_IMSP } - strcpy (pwd,imap_password); +#endif } Index: functions/imap.h =================================================================== RCS file: /repository/php3/functions/imap.h,v retrieving revision 1.11 diff -u -r1.11 imap.h --- functions/imap.h 1999/07/02 21:05:17 1.11 +++ functions/imap.h 1999/07/24 03:03:29 @@ -76,6 +76,7 @@ void php3_imap_alerts(INTERNAL_FUNCTION_PARAMETERS); void php3_imap_errors(INTERNAL_FUNCTION_PARAMETERS); void php3_imap_last_error(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_search(INTERNAL_FUNCTION_PARAMETERS); #else #define php3_imap_module_ptr NULL Attachment: [application/x-httpd-php3] search.php3
« previous php.dev (#9085) next »