Re: Re: Function to retrieve headers for message/rfc822 attachments

From: Date: Tue, 05 Mar 2002 03:00:20 +0000
Subject: Re: Re: Function to retrieve headers for message/rfc822 attachments
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-80714@lists.php.net to get a copy of this message
Sorry, I'm just catching up with email backlog, so this email might be irrelevant by now, but just in case it isn't: imap_fetch_header() is probably not a very good name because we already have imap_fetchheader() and I believe they might be a bit too similar in names (I don't know what the proposed function does, if it is good or not, I just don't like the name). IMAP extension has already got a good share of confusingly similar function names IMHO. $.02 Vlad Brad Fisher wrote:
Here is my attempt at a unified diff against the current CVS. Let me know if I need to do anything differently. -Brad ---------------------- diff for php_imap.c ----------------------- --- php_imap.c +++ php_imap.c Tue Feb 26 23:00:58 2002 @@ -91,6 +91,7 @@ PHP_FE(imap_bodystruct, NULL) PHP_FE(imap_fetchbody, NULL) PHP_FE(imap_fetchheader, NULL) + PHP_FE(imap_fetch_header, NULL) PHP_FE(imap_fetchstructure, NULL) PHP_FE(imap_expunge, NULL) PHP_FE(imap_delete, NULL) @@ -2582,6 +2583,99 @@
       RETVAL_STRING(mail_fetchheader_full(imap_le_struct->imap_stream,
Z_LVAL_PP(msgno), NIL, NIL, (myargc == 3 ? Z_LVAL_PP(flags) : NIL)), 1); } /* }}} */ + + + +/* {{{ proto string imap_fetch_header(int stream_id, int msg_no [, string section [, array lines [, int options]]]) + Get the (optionally filtered) header for a given section of a message */ +PHP_FUNCTION(imap_fetch_header) +{ +/* + NOTE: You need to explicitly set FT_PEEK to not mark message as READ when calling this function. + Empty strings are ignored in the lines array. +*/
+        zval **streamind, **msgno, **sec = NIL, **lines = NIL, **flags,
**tmp;
+        int i, ind, ind_type, msgindex;
+        pils *imap_le_struct;
+        int myargc = ZEND_NUM_ARGS();
+        HashPosition pos;
+        STRINGLIST *cur_lines = NIL, *cur;
+
+        if (myargc < 2 ||
+            myargc > 5 ||
+            zend_get_parameters_ex(myargc, &streamind, &msgno, &sec,
&lines, &flags) == FAILURE)
+        {
+                ZEND_WRONG_PARAM_COUNT();
+        } //if
+
+        convert_to_long_ex(streamind);
+        convert_to_long_ex(msgno);
+
+        if (myargc > 2) {
+                convert_to_string_ex(sec);
+        } //if
+
+        /* Convert the <lines> array to a STRINGLIST */
+        if (myargc > 3) {
+                convert_to_array_ex(lines);
+
+                zend_hash_internal_pointer_reset_ex((*lines)->value.ht,
&pos);
+                while
(zend_hash_get_current_data_ex((*lines)->value.ht, (void **) &tmp, &pos) == SUCCESS) {
+                        convert_to_string_ex(tmp);
+
+                        // Only add to the filter list if not an empty
string
+                        if (*Z_STRVAL_PP(tmp)) {
+                                if (cur_lines) {
+                                        cur->next =
mail_newstringlist();
+                                        cur = cur->next;
+                                } else {
+                                        cur_lines =
mail_newstringlist();
+                                        cur = cur_lines;
+                                } //if
+
+                                cur->LSIZE = (*tmp)->value.str.len;
+                                cur->LTEXT = (char*)
cpystr((*tmp)->value.str.val);
+                        } //if
+
+                        zend_hash_move_forward_ex((*lines)->value.ht,
&pos);
+                } //while
+        } //if
+
+        if (myargc == 5) {
+                convert_to_long_ex(flags);
+        } //if
+        ind = Z_LVAL_PP(streamind);
+
+        imap_le_struct = (pils *) zend_list_find(ind, &ind_type);
+//      if (!imap_le_struct || !IS_STREAM(ind_type)) {
+        if (!imap_le_struct) {
+                php_error(E_WARNING, "Unable to find stream pointer");
+                RETURN_FALSE;
+        } //if
+
+        if ((myargc == 5) && (Z_LVAL_PP(flags) & 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,
Z_LVAL_PP(msgno));
+        } else {
+                msgindex = Z_LVAL_PP(msgno);
+        } //if
+        if ((msgindex < 1) || ((unsigned) msgindex >
imap_le_struct->imap_stream->nmsgs)) {
+                php_error(E_WARNING, "Bad message number");
+                RETURN_FALSE;
+        } //if
+
+        /* Perform the header fetch */
+        RETVAL_STRING(mail_fetch_header(imap_le_struct->imap_stream,
Z_LVAL_PP(msgno), Z_STRVAL_PP(sec),
+                                        cur_lines, NIL, myargc==5 ?
Z_LVAL_PP(flags) : NIL), 1); +
+        /* Free the temporary string list */
+        mail_free_stringlist(&cur_lines);
+} // PHP_FUNCTION(imap_fetch_header) +/* }}} */ + + /* {{{ proto int imap_uid(int stream_id, int msg_no) Get the unique message id associated with a standard sequential message number */ ---------------------- diff for php_imap.h ----------------------- --- php_imap.h +++ php_imap.h Tue Feb 26 23:01:17 2002 @@ -149,6 +149,7 @@ PHP_FUNCTION(imap_setflag_full); PHP_FUNCTION(imap_clearflag_full); PHP_FUNCTION(imap_sort); +PHP_FUNCTION(imap_fetch_header); PHP_FUNCTION(imap_fetchheader); PHP_FUNCTION(imap_fetchtext); PHP_FUNCTION(imap_uid); ------------------------------------------------------------------------ --- php_imap.c +++ php_imap.c Tue Feb 26 23:00:58 2002 @@ -91,6 +91,7 @@
       PHP_FE(imap_bodystruct,                                                 NULL)
       PHP_FE(imap_fetchbody,                                                  NULL)
       PHP_FE(imap_fetchheader,                                                NULL)
+       PHP_FE(imap_fetch_header,                                               NULL)        PHP_FE(imap_fetchstructure,                                             NULL)
       PHP_FE(imap_expunge,                                                    NULL)
       PHP_FE(imap_delete,                                                             NULL)
@@ -2582,6 +2583,99 @@
       RETVAL_STRING(mail_fetchheader_full(imap_le_struct->imap_stream, Z_LVAL_PP(msgno), NIL, NIL, (myargc == 3 ? Z_LVAL_PP(flags) : NIL)), 1);
} /* }}} */ + + + +/* {{{ proto string imap_fetch_header(int stream_id, int msg_no [, string section [, array lines [, int options]]]) + Get the (optionally filtered) header for a given section of a message */ +PHP_FUNCTION(imap_fetch_header) +{ +/* + NOTE: You need to explicitly set FT_PEEK to not mark message as READ when calling this function. + Empty strings are ignored in the lines array. +*/
+        zval **streamind, **msgno, **sec = NIL, **lines = NIL, **flags, **tmp;
+        int i, ind, ind_type, msgindex;
+        pils *imap_le_struct;
+        int myargc = ZEND_NUM_ARGS();
+        HashPosition pos;
+        STRINGLIST *cur_lines = NIL, *cur;
+
+        if (myargc < 2 ||
+            myargc > 5 ||
+            zend_get_parameters_ex(myargc, &streamind, &msgno, &sec, &lines, &flags) == FAILURE)
+        {
+                ZEND_WRONG_PARAM_COUNT();
+        } //if
+
+        convert_to_long_ex(streamind);
+        convert_to_long_ex(msgno);
+
+        if (myargc > 2) {
+                convert_to_string_ex(sec);
+        } //if
+
+        /* Convert the <lines> array to a STRINGLIST */
+        if (myargc > 3) {
+                convert_to_array_ex(lines);
+
+                zend_hash_internal_pointer_reset_ex((*lines)->value.ht, &pos);
+                while (zend_hash_get_current_data_ex((*lines)->value.ht, (void **) &tmp, &pos) == SUCCESS) {
+                        convert_to_string_ex(tmp);
+
+                        // Only add to the filter list if not an empty string
+                        if (*Z_STRVAL_PP(tmp)) {
+                                if (cur_lines) {
+                                        cur->next = mail_newstringlist();
+                                        cur = cur->next;
+                                } else {
+                                        cur_lines = mail_newstringlist();
+                                        cur = cur_lines;
+                                } //if
+
+                                cur->LSIZE = (*tmp)->value.str.len;
+                                cur->LTEXT = (char*) cpystr((*tmp)->value.str.val);
+                        } //if
+
+                        zend_hash_move_forward_ex((*lines)->value.ht, &pos);
+                } //while
+        } //if
+
+        if (myargc == 5) {
+                convert_to_long_ex(flags);
+        } //if
+        ind = Z_LVAL_PP(streamind);
+
+        imap_le_struct = (pils *) zend_list_find(ind, &ind_type);
+//      if (!imap_le_struct || !IS_STREAM(ind_type)) {
+        if (!imap_le_struct) {
+                php_error(E_WARNING, "Unable to find stream pointer");
+                RETURN_FALSE;
+        } //if
+
+        if ((myargc == 5) && (Z_LVAL_PP(flags) & 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, Z_LVAL_PP(msgno));
+        } else {
+                msgindex = Z_LVAL_PP(msgno);
+        } //if
+        if ((msgindex < 1) || ((unsigned) msgindex > imap_le_struct->imap_stream->nmsgs)) {
+                php_error(E_WARNING, "Bad message number");
+                RETURN_FALSE;
+        } //if
+
+        /* Perform the header fetch */
+        RETVAL_STRING(mail_fetch_header(imap_le_struct->imap_stream, Z_LVAL_PP(msgno), Z_STRVAL_PP(sec),
+                                        cur_lines, NIL, myargc==5 ?  Z_LVAL_PP(flags) : NIL), 1);
+
+        /* Free the temporary string list */
+        mail_free_stringlist(&cur_lines);
+} // PHP_FUNCTION(imap_fetch_header) +/* }}} */ + + /* {{{ proto int imap_uid(int stream_id, int msg_no) Get the unique message id associated with a standard sequential message number */ ------------------------------------------------------------------------ --- php_imap.h +++ php_imap.h Tue Feb 26 23:01:17 2002 @@ -149,6 +149,7 @@ PHP_FUNCTION(imap_setflag_full); PHP_FUNCTION(imap_clearflag_full); PHP_FUNCTION(imap_sort); +PHP_FUNCTION(imap_fetch_header); PHP_FUNCTION(imap_fetchheader); PHP_FUNCTION(imap_fetchtext); PHP_FUNCTION(imap_uid);


« previous php.dev (#80714) next »