@@ -152,6 +152,28 @@ static int le_imap;
152
152
RETURN_FALSE; \
153
153
} \
154
154
155
+ #define PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS (msgindex , arg_pos ) \
156
+ if (msgindex < 1) { \
157
+ zend_argument_value_error(arg_pos, "must be greater than 0"); \
158
+ RETURN_THROWS(); \
159
+ } \
160
+
161
+ #define PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS (msgindex , arg_pos , func_flags , uid_flag ) \
162
+ if (func_flags & uid_flag) { \
163
+ /* This should be cached; if it causes an extra RTT to the IMAP server, */ \
164
+ /* then that's the price we pay for making sure we don't crash. */ \
165
+ unsigned int msg_no_from_uid = mail_msgno(imap_le_struct->imap_stream, msgindex); \
166
+ if (msg_no_from_uid == 0) { \
167
+ php_error_docref(NULL, E_WARNING, "UID does not exist"); \
168
+ RETURN_FALSE; \
169
+ } \
170
+ } else { \
171
+ if (((unsigned) msgindex) > imap_le_struct->imap_stream->nmsgs) { \
172
+ php_error_docref(NULL, E_WARNING, "Bad message number"); \
173
+ RETURN_FALSE; \
174
+ } \
175
+ } \
176
+
155
177
/* {{{ mail_close_it */
156
178
static void mail_close_it (zend_resource * rsrc )
157
179
{
@@ -1258,7 +1280,6 @@ PHP_FUNCTION(imap_body)
1258
1280
zval * streamind ;
1259
1281
zend_long msgno , flags = 0 ;
1260
1282
pils * imap_le_struct ;
1261
- unsigned long msgindex ;
1262
1283
char * body ;
1263
1284
unsigned long body_len = 0 ;
1264
1285
@@ -1270,32 +1291,15 @@ PHP_FUNCTION(imap_body)
1270
1291
RETURN_THROWS ();
1271
1292
}
1272
1293
1273
- if (msgno < 1 ) {
1274
- zend_argument_value_error (2 , "must be greater than 0" );
1275
- RETURN_THROWS ();
1276
- }
1294
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS (msgno , 2 );
1277
1295
1278
1296
if (flags && ((flags & ~(FT_UID |FT_PEEK |FT_INTERNAL )) != 0 )) {
1279
1297
zend_argument_value_error (3 , "must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL" );
1280
1298
RETURN_THROWS ();
1281
1299
}
1282
1300
1283
- if (flags && (flags & FT_UID )) {
1284
- /* This should be cached; if it causes an extra RTT to the
1285
- IMAP server, then that's the price we pay for making
1286
- sure we don't crash. */
1287
- msgindex = mail_msgno (imap_le_struct -> imap_stream , msgno );
1288
- if (msgindex == 0 ) {
1289
- php_error_docref (NULL , E_WARNING , "UID does not exist" );
1290
- RETURN_FALSE ;
1291
- }
1292
- } else {
1293
- msgindex = (unsigned long ) msgno ;
1294
- }
1295
-
1296
- PHP_IMAP_CHECK_MSGNO (msgindex , 2 );
1301
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS (msgno , 2 , flags , FT_UID );
1297
1302
1298
- /* TODO Shouldn't this pass msgindex??? */
1299
1303
body = mail_fetchtext_full (imap_le_struct -> imap_stream , msgno , & body_len , flags );
1300
1304
if (body_len == 0 ) {
1301
1305
RETVAL_EMPTY_STRING ();
@@ -1305,6 +1309,7 @@ PHP_FUNCTION(imap_body)
1305
1309
}
1306
1310
/* }}} */
1307
1311
1312
+ /* TODO UID Tests */
1308
1313
/* {{{ Copy specified message to a mailbox */
1309
1314
PHP_FUNCTION (imap_mail_copy )
1310
1315
{
@@ -1334,6 +1339,7 @@ PHP_FUNCTION(imap_mail_copy)
1334
1339
}
1335
1340
/* }}} */
1336
1341
1342
+ /* TODO UID Tests */
1337
1343
/* {{{ Move specified message to a mailbox */
1338
1344
PHP_FUNCTION (imap_mail_move )
1339
1345
{
@@ -1605,13 +1611,15 @@ PHP_FUNCTION(imap_delete)
1605
1611
RETURN_THROWS ();
1606
1612
}
1607
1613
1614
+ // TODO Check sequence validity?
1615
+
1608
1616
if (flags && ((flags & ~FT_UID ) != 0 )) {
1609
1617
zend_argument_value_error (3 , "must be FT_UID or 0" );
1610
1618
RETURN_THROWS ();
1611
1619
}
1612
1620
1613
1621
mail_setflag_full (imap_le_struct -> imap_stream , ZSTR_VAL (sequence ), "\\DELETED" , flags );
1614
- RETVAL_TRUE ;
1622
+ RETURN_TRUE ;
1615
1623
}
1616
1624
/* }}} */
1617
1625
@@ -1882,7 +1890,6 @@ PHP_FUNCTION(imap_fetchstructure)
1882
1890
zend_long msgno , flags = 0 ;
1883
1891
pils * imap_le_struct ;
1884
1892
BODY * body ;
1885
- int msgindex ;
1886
1893
1887
1894
if (zend_parse_parameters (ZEND_NUM_ARGS (), "rl|l" , & streamind , & msgno , & flags ) == FAILURE ) {
1888
1895
RETURN_THROWS ();
@@ -1892,34 +1899,18 @@ PHP_FUNCTION(imap_fetchstructure)
1892
1899
RETURN_THROWS ();
1893
1900
}
1894
1901
1895
- if (msgno < 1 ) {
1896
- zend_argument_value_error (2 , "must be greater than 0" );
1897
- RETURN_THROWS ();
1898
- }
1902
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS (msgno , 2 );
1899
1903
1900
1904
if (flags && ((flags & ~FT_UID ) != 0 )) {
1901
1905
zend_argument_value_error (3 , "must be FT_UID or 0" );
1902
1906
RETURN_THROWS ();
1903
1907
}
1904
1908
1905
- object_init ( return_value );
1909
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS ( msgno , 2 , flags , FT_UID );
1906
1910
1907
- if (flags & FT_UID ) {
1908
- /* This should be cached; if it causes an extra RTT to the
1909
- IMAP server, then that's the price we pay for making
1910
- sure we don't crash. */
1911
- msgindex = mail_msgno (imap_le_struct -> imap_stream , msgno );
1912
- if (msgindex == 0 ) {
1913
- php_error_docref (NULL , E_WARNING , "UID does not exist" );
1914
- RETURN_FALSE ;
1915
- }
1916
- } else {
1917
- msgindex = msgno ;
1918
- }
1919
- PHP_IMAP_CHECK_MSGNO (msgindex , 2 );
1911
+ object_init (return_value );
1920
1912
1921
- /* TODO Shouldn't this pass msgindex??? */
1922
- mail_fetchstructure_full (imap_le_struct -> imap_stream , msgno , & body , (ZEND_NUM_ARGS () == 3 ? flags : NIL ));
1913
+ mail_fetchstructure_full (imap_le_struct -> imap_stream , msgno , & body , flags );
1923
1914
1924
1915
if (!body ) {
1925
1916
php_error_docref (NULL , E_WARNING , "No body information available" );
@@ -1948,20 +1939,14 @@ PHP_FUNCTION(imap_fetchbody)
1948
1939
RETURN_THROWS ();
1949
1940
}
1950
1941
1951
- if (msgno < 1 ) {
1952
- zend_argument_value_error (2 , "must be greater than 0" );
1953
- RETURN_THROWS ();
1954
- }
1942
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS (msgno , 2 );
1955
1943
1956
1944
if (flags && ((flags & ~(FT_UID |FT_PEEK |FT_INTERNAL )) != 0 )) {
1957
1945
zend_argument_value_error (4 , "must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL" );
1958
1946
RETURN_THROWS ();
1959
1947
}
1960
1948
1961
- if (!(flags & FT_UID )) {
1962
- /* only perform the check if the msgno is a message number and not a UID */
1963
- PHP_IMAP_CHECK_MSGNO (msgno , 2 );
1964
- }
1949
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS (msgno , 2 , flags , FT_UID );
1965
1950
1966
1951
body = mail_fetchbody_full (imap_le_struct -> imap_stream , msgno , ZSTR_VAL (sec ), & len , flags );
1967
1952
@@ -1989,24 +1974,18 @@ PHP_FUNCTION(imap_fetchmime)
1989
1974
RETURN_THROWS ();
1990
1975
}
1991
1976
1992
- if (msgno < 1 ) {
1993
- zend_argument_value_error (2 , "must be greater than 0" );
1977
+ if ((imap_le_struct = (pils * )zend_fetch_resource (Z_RES_P (streamind ), "imap" , le_imap )) == NULL ) {
1994
1978
RETURN_THROWS ();
1995
1979
}
1996
1980
1981
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS (msgno , 2 );
1982
+
1997
1983
if (flags && ((flags & ~(FT_UID |FT_PEEK |FT_INTERNAL )) != 0 )) {
1998
1984
zend_argument_value_error (4 , "must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL" );
1999
1985
RETURN_THROWS ();
2000
1986
}
2001
1987
2002
- if ((imap_le_struct = (pils * )zend_fetch_resource (Z_RES_P (streamind ), "imap" , le_imap )) == NULL ) {
2003
- RETURN_THROWS ();
2004
- }
2005
-
2006
- if (!(flags & FT_UID )) {
2007
- /* only perform the check if the msgno is a message number and not a UID */
2008
- PHP_IMAP_CHECK_MSGNO (msgno , 2 );
2009
- }
1988
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS (msgno , 2 , flags , FT_UID );
2010
1989
2011
1990
body = mail_fetch_mime (imap_le_struct -> imap_stream , msgno , ZSTR_VAL (sec ), & len , flags );
2012
1991
@@ -2037,18 +2016,14 @@ PHP_FUNCTION(imap_savebody)
2037
2016
RETURN_THROWS ();
2038
2017
}
2039
2018
2040
- // TODO Fix for UID and normal MSGNO
2041
- //PHP_IMAP_CHECK_MSGNO(msgno, 3);
2019
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS (msgno , 3 )
2042
2020
2043
2021
if (flags && ((flags & ~(FT_UID |FT_PEEK |FT_INTERNAL )) != 0 )) {
2044
2022
zend_argument_value_error (5 , "must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL" );
2045
2023
RETURN_THROWS ();
2046
2024
}
2047
2025
2048
- // TODO Drop this?
2049
- if (!imap_le_struct ) {
2050
- RETURN_FALSE ;
2051
- }
2026
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS (msgno , 3 , flags , FT_UID );
2052
2027
2053
2028
switch (Z_TYPE_P (out ))
2054
2029
{
@@ -2772,9 +2747,8 @@ PHP_FUNCTION(imap_sort)
2772
2747
PHP_FUNCTION (imap_fetchheader )
2773
2748
{
2774
2749
zval * streamind ;
2775
- zend_long msgno , flags = 0L ;
2750
+ zend_long msgno , flags = 0 ;
2776
2751
pils * imap_le_struct ;
2777
- int msgindex ;
2778
2752
2779
2753
if (zend_parse_parameters (ZEND_NUM_ARGS (), "rl|l" , & streamind , & msgno , & flags ) == FAILURE ) {
2780
2754
RETURN_THROWS ();
@@ -2784,30 +2758,16 @@ PHP_FUNCTION(imap_fetchheader)
2784
2758
RETURN_THROWS ();
2785
2759
}
2786
2760
2787
- // TODO Check for msgno < 1 now or wait later for PHP_IMAP_CHECK_MSGNO check?
2761
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS ( msgno , 2 );
2788
2762
2789
2763
if (flags && ((flags & ~(FT_UID |FT_INTERNAL |FT_PREFETCHTEXT )) != 0 )) {
2790
2764
zend_argument_value_error (3 , "must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL" );
2791
2765
RETURN_THROWS ();
2792
2766
}
2793
2767
2794
- if (flags & FT_UID ) {
2795
- /* This should be cached; if it causes an extra RTT to the
2796
- IMAP server, then that's the price we pay for making sure
2797
- we don't crash. */
2798
- msgindex = mail_msgno (imap_le_struct -> imap_stream , msgno );
2799
- if (msgindex == 0 ) {
2800
- php_error_docref (NULL , E_WARNING , "UID does not exist" );
2801
- RETURN_FALSE ;
2802
- }
2803
- } else {
2804
- msgindex = msgno ;
2805
- }
2806
-
2807
- PHP_IMAP_CHECK_MSGNO (msgindex , 2 );
2768
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS (msgno , 2 , flags , FT_UID );
2808
2769
2809
- /* TODO Check shouldn't this pass msgindex???? */
2810
- RETVAL_STRING (mail_fetchheader_full (imap_le_struct -> imap_stream , msgno , NIL , NIL , (ZEND_NUM_ARGS () == 3 ? flags : NIL )));
2770
+ RETVAL_STRING (mail_fetchheader_full (imap_le_struct -> imap_stream , msgno , NIL , NIL , flags ));
2811
2771
}
2812
2772
/* }}} */
2813
2773
0 commit comments