PageRenderTime 62ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 1ms

/ext/imap/php_imap.c

http://github.com/infusion/PHP
C | 5095 lines | 3811 code | 702 blank | 582 comment | 869 complexity | 19aaaebfa2eb11f6332dff5a49519ba6 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2011 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Rex Logan <veebert@dimensional.com> |
  16. | Mark Musone <musone@afterfive.com> |
  17. | Brian Wang <brian@vividnet.com> |
  18. | Kaj-Michael Lang <milang@tal.org> |
  19. | Antoni Pamies Olive <toni@readysoft.net> |
  20. | Rasmus Lerdorf <rasmus@php.net> |
  21. | Chuck Hagenbuch <chuck@horde.org> |
  22. | Andrew Skalski <askalski@chekinc.com> |
  23. | Hartmut Holzgraefe <hholzgra@php.net> |
  24. | Jani Taskinen <jani.taskinen@iki.fi> |
  25. | Daniel R. Kalowsky <kalowsky@php.net> |
  26. | PHP 4.0 updates: Zeev Suraski <zeev@zend.com> |
  27. +----------------------------------------------------------------------+
  28. */
  29. /* $Id: php_imap.c 307691 2011-01-24 03:52:00Z stas $ */
  30. #define IMAP41
  31. #ifdef HAVE_CONFIG_H
  32. #include "config.h"
  33. #endif
  34. #include "php.h"
  35. #include "php_ini.h"
  36. #include "php_streams.h"
  37. #include "ext/standard/php_string.h"
  38. #include "ext/standard/info.h"
  39. #include "ext/standard/file.h"
  40. #include "ext/standard/php_smart_str.h"
  41. #include "ext/pcre/php_pcre.h"
  42. #ifdef ERROR
  43. #undef ERROR
  44. #endif
  45. #include "php_imap.h"
  46. #include <time.h>
  47. #include <stdio.h>
  48. #include <ctype.h>
  49. #include <signal.h>
  50. #ifdef PHP_WIN32
  51. #include <winsock2.h>
  52. #include <stdlib.h>
  53. #include "win32/sendmail.h"
  54. MAILSTREAM DEFAULTPROTO;
  55. #endif
  56. #define CRLF "\015\012"
  57. #define CRLF_LEN sizeof("\015\012") - 1
  58. #define PHP_EXPUNGE 32768
  59. #define PHP_IMAP_ADDRESS_SIZE_BUF 10
  60. #ifndef SENDBUFLEN
  61. #define SENDBUFLEN 16385
  62. #endif
  63. #if defined(__GNUC__) && __GNUC__ >= 4
  64. # define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
  65. #else
  66. # define PHP_IMAP_EXPORT
  67. #endif
  68. static void _php_make_header_object(zval *myzvalue, ENVELOPE *en TSRMLS_DC);
  69. static void _php_imap_add_body(zval *arg, BODY *body TSRMLS_DC);
  70. static char* _php_imap_parse_address(ADDRESS *addresslist, zval *paddress TSRMLS_DC);
  71. static char* _php_rfc822_write_address(ADDRESS *addresslist TSRMLS_DC);
  72. /* the gets we use */
  73. static char *php_mail_gets(readfn_t f, void *stream, unsigned long size, GETS_DATA *md);
  74. /* These function declarations are missing from the IMAP header files... */
  75. void rfc822_date(char *date);
  76. char *cpystr(const char *str);
  77. char *cpytxt(SIZEDTEXT *dst, char *text, unsigned long size);
  78. #ifndef HAVE_NEW_MIME2TEXT
  79. long utf8_mime2text(SIZEDTEXT *src, SIZEDTEXT *dst);
  80. #else
  81. long utf8_mime2text (SIZEDTEXT *src, SIZEDTEXT *dst, long flags);
  82. #endif
  83. unsigned long find_rightmost_bit(unsigned long *valptr);
  84. void fs_give(void **block);
  85. void *fs_get(size_t size);
  86. ZEND_DECLARE_MODULE_GLOBALS(imap)
  87. static PHP_GINIT_FUNCTION(imap);
  88. /* {{{ arginfo */
  89. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_open, 0, 0, 3)
  90. ZEND_ARG_INFO(0, mailbox)
  91. ZEND_ARG_INFO(0, user)
  92. ZEND_ARG_INFO(0, password)
  93. ZEND_ARG_INFO(0, options)
  94. ZEND_ARG_INFO(0, n_retries)
  95. ZEND_ARG_INFO(0, params)
  96. ZEND_END_ARG_INFO()
  97. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_reopen, 0, 0, 2)
  98. ZEND_ARG_INFO(0, stream_id)
  99. ZEND_ARG_INFO(0, mailbox)
  100. ZEND_ARG_INFO(0, options)
  101. ZEND_ARG_INFO(0, n_retries)
  102. ZEND_END_ARG_INFO()
  103. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_append, 0, 0, 3)
  104. ZEND_ARG_INFO(0, stream_id)
  105. ZEND_ARG_INFO(0, folder)
  106. ZEND_ARG_INFO(0, message)
  107. ZEND_ARG_INFO(0, options)
  108. ZEND_ARG_INFO(0, date)
  109. ZEND_END_ARG_INFO()
  110. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_num_msg, 0, 0, 1)
  111. ZEND_ARG_INFO(0, stream_id)
  112. ZEND_END_ARG_INFO()
  113. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_ping, 0, 0, 1)
  114. ZEND_ARG_INFO(0, stream_id)
  115. ZEND_END_ARG_INFO()
  116. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_num_recent, 0, 0, 1)
  117. ZEND_ARG_INFO(0, stream_id)
  118. ZEND_END_ARG_INFO()
  119. #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
  120. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_get_quota, 0, 0, 2)
  121. ZEND_ARG_INFO(0, stream_id)
  122. ZEND_ARG_INFO(0, qroot)
  123. ZEND_END_ARG_INFO()
  124. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_get_quotaroot, 0, 0, 2)
  125. ZEND_ARG_INFO(0, stream_id)
  126. ZEND_ARG_INFO(0, mbox)
  127. ZEND_END_ARG_INFO()
  128. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_set_quota, 0, 0, 3)
  129. ZEND_ARG_INFO(0, stream_id)
  130. ZEND_ARG_INFO(0, qroot)
  131. ZEND_ARG_INFO(0, mailbox_size)
  132. ZEND_END_ARG_INFO()
  133. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_setacl, 0, 0, 4)
  134. ZEND_ARG_INFO(0, stream_id)
  135. ZEND_ARG_INFO(0, mailbox)
  136. ZEND_ARG_INFO(0, id)
  137. ZEND_ARG_INFO(0, rights)
  138. ZEND_END_ARG_INFO()
  139. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_getacl, 0, 0, 2)
  140. ZEND_ARG_INFO(0, stream_id)
  141. ZEND_ARG_INFO(0, mailbox)
  142. ZEND_END_ARG_INFO()
  143. #endif
  144. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_expunge, 0, 0, 1)
  145. ZEND_ARG_INFO(0, stream_id)
  146. ZEND_END_ARG_INFO()
  147. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_gc, 0, 0, 1)
  148. ZEND_ARG_INFO(0, stream_id)
  149. ZEND_ARG_INFO(0, flags)
  150. ZEND_END_ARG_INFO()
  151. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_close, 0, 0, 1)
  152. ZEND_ARG_INFO(0, stream_id)
  153. ZEND_ARG_INFO(0, options)
  154. ZEND_END_ARG_INFO()
  155. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_headers, 0, 0, 1)
  156. ZEND_ARG_INFO(0, stream_id)
  157. ZEND_END_ARG_INFO()
  158. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_body, 0, 0, 2)
  159. ZEND_ARG_INFO(0, stream_id)
  160. ZEND_ARG_INFO(0, msg_no)
  161. ZEND_ARG_INFO(0, options)
  162. ZEND_END_ARG_INFO()
  163. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mail_copy, 0, 0, 3)
  164. ZEND_ARG_INFO(0, stream_id)
  165. ZEND_ARG_INFO(0, msglist)
  166. ZEND_ARG_INFO(0, mailbox)
  167. ZEND_ARG_INFO(0, options)
  168. ZEND_END_ARG_INFO()
  169. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mail_move, 0, 0, 3)
  170. ZEND_ARG_INFO(0, stream_id)
  171. ZEND_ARG_INFO(0, sequence)
  172. ZEND_ARG_INFO(0, mailbox)
  173. ZEND_ARG_INFO(0, options)
  174. ZEND_END_ARG_INFO()
  175. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_createmailbox, 0, 0, 2)
  176. ZEND_ARG_INFO(0, stream_id)
  177. ZEND_ARG_INFO(0, mailbox)
  178. ZEND_END_ARG_INFO()
  179. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_renamemailbox, 0, 0, 3)
  180. ZEND_ARG_INFO(0, stream_id)
  181. ZEND_ARG_INFO(0, old_name)
  182. ZEND_ARG_INFO(0, new_name)
  183. ZEND_END_ARG_INFO()
  184. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_deletemailbox, 0, 0, 2)
  185. ZEND_ARG_INFO(0, stream_id)
  186. ZEND_ARG_INFO(0, mailbox)
  187. ZEND_END_ARG_INFO()
  188. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_list, 0, 0, 3)
  189. ZEND_ARG_INFO(0, stream_id)
  190. ZEND_ARG_INFO(0, ref)
  191. ZEND_ARG_INFO(0, pattern)
  192. ZEND_END_ARG_INFO()
  193. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_getmailboxes, 0, 0, 3)
  194. ZEND_ARG_INFO(0, stream_id)
  195. ZEND_ARG_INFO(0, ref)
  196. ZEND_ARG_INFO(0, pattern)
  197. ZEND_END_ARG_INFO()
  198. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_listscan, 0, 0, 4)
  199. ZEND_ARG_INFO(0, stream_id)
  200. ZEND_ARG_INFO(0, ref)
  201. ZEND_ARG_INFO(0, pattern)
  202. ZEND_ARG_INFO(0, content)
  203. ZEND_END_ARG_INFO()
  204. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_check, 0, 0, 1)
  205. ZEND_ARG_INFO(0, stream_id)
  206. ZEND_END_ARG_INFO()
  207. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_delete, 0, 0, 2)
  208. ZEND_ARG_INFO(0, stream_id)
  209. ZEND_ARG_INFO(0, msg_no)
  210. ZEND_ARG_INFO(0, options)
  211. ZEND_END_ARG_INFO()
  212. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_undelete, 0, 0, 2)
  213. ZEND_ARG_INFO(0, stream_id)
  214. ZEND_ARG_INFO(0, msg_no)
  215. ZEND_ARG_INFO(0, flags)
  216. ZEND_END_ARG_INFO()
  217. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_headerinfo, 0, 0, 2)
  218. ZEND_ARG_INFO(0, stream_id)
  219. ZEND_ARG_INFO(0, msg_no)
  220. ZEND_ARG_INFO(0, from_length)
  221. ZEND_ARG_INFO(0, subject_length)
  222. ZEND_ARG_INFO(0, default_host)
  223. ZEND_END_ARG_INFO()
  224. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_rfc822_parse_headers, 0, 0, 1)
  225. ZEND_ARG_INFO(0, headers)
  226. ZEND_ARG_INFO(0, default_host)
  227. ZEND_END_ARG_INFO()
  228. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_lsub, 0, 0, 3)
  229. ZEND_ARG_INFO(0, stream_id)
  230. ZEND_ARG_INFO(0, ref)
  231. ZEND_ARG_INFO(0, pattern)
  232. ZEND_END_ARG_INFO()
  233. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_getsubscribed, 0, 0, 3)
  234. ZEND_ARG_INFO(0, stream_id)
  235. ZEND_ARG_INFO(0, ref)
  236. ZEND_ARG_INFO(0, pattern)
  237. ZEND_END_ARG_INFO()
  238. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_subscribe, 0, 0, 2)
  239. ZEND_ARG_INFO(0, stream_id)
  240. ZEND_ARG_INFO(0, mailbox)
  241. ZEND_END_ARG_INFO()
  242. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_unsubscribe, 0, 0, 2)
  243. ZEND_ARG_INFO(0, stream_id)
  244. ZEND_ARG_INFO(0, mailbox)
  245. ZEND_END_ARG_INFO()
  246. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_fetchstructure, 0, 0, 2)
  247. ZEND_ARG_INFO(0, stream_id)
  248. ZEND_ARG_INFO(0, msg_no)
  249. ZEND_ARG_INFO(0, options)
  250. ZEND_END_ARG_INFO()
  251. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_fetchbody, 0, 0, 3)
  252. ZEND_ARG_INFO(0, stream_id)
  253. ZEND_ARG_INFO(0, msg_no)
  254. ZEND_ARG_INFO(0, section)
  255. ZEND_ARG_INFO(0, options)
  256. ZEND_END_ARG_INFO()
  257. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_savebody, 0, 0, 3)
  258. ZEND_ARG_INFO(0, stream_id)
  259. ZEND_ARG_INFO(0, file)
  260. ZEND_ARG_INFO(0, msg_no)
  261. ZEND_ARG_INFO(0, section)
  262. ZEND_ARG_INFO(0, options)
  263. ZEND_END_ARG_INFO()
  264. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_base64, 0, 0, 1)
  265. ZEND_ARG_INFO(0, text)
  266. ZEND_END_ARG_INFO()
  267. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_qprint, 0, 0, 1)
  268. ZEND_ARG_INFO(0, text)
  269. ZEND_END_ARG_INFO()
  270. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_8bit, 0, 0, 1)
  271. ZEND_ARG_INFO(0, text)
  272. ZEND_END_ARG_INFO()
  273. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_binary, 0, 0, 1)
  274. ZEND_ARG_INFO(0, text)
  275. ZEND_END_ARG_INFO()
  276. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mailboxmsginfo, 0, 0, 1)
  277. ZEND_ARG_INFO(0, stream_id)
  278. ZEND_END_ARG_INFO()
  279. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_rfc822_write_address, 0, 0, 3)
  280. ZEND_ARG_INFO(0, mailbox)
  281. ZEND_ARG_INFO(0, host)
  282. ZEND_ARG_INFO(0, personal)
  283. ZEND_END_ARG_INFO()
  284. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_rfc822_parse_adrlist, 0, 0, 2)
  285. ZEND_ARG_INFO(0, address_string)
  286. ZEND_ARG_INFO(0, default_host)
  287. ZEND_END_ARG_INFO()
  288. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf8, 0, 0, 1)
  289. ZEND_ARG_INFO(0, mime_encoded_text)
  290. ZEND_END_ARG_INFO()
  291. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf7_decode, 0, 0, 1)
  292. ZEND_ARG_INFO(0, buf)
  293. ZEND_END_ARG_INFO()
  294. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf7_encode, 0, 0, 1)
  295. ZEND_ARG_INFO(0, buf)
  296. ZEND_END_ARG_INFO()
  297. #ifdef HAVE_IMAP_MUTF7
  298. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf8_to_mutf7, 0, 0, 1)
  299. ZEND_ARG_INFO(0, in)
  300. ZEND_END_ARG_INFO()
  301. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mutf7_to_utf8, 0, 0, 1)
  302. ZEND_ARG_INFO(0, in)
  303. ZEND_END_ARG_INFO()
  304. #endif
  305. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_setflag_full, 0, 0, 3)
  306. ZEND_ARG_INFO(0, stream_id)
  307. ZEND_ARG_INFO(0, sequence)
  308. ZEND_ARG_INFO(0, flag)
  309. ZEND_ARG_INFO(0, options)
  310. ZEND_END_ARG_INFO()
  311. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_clearflag_full, 0, 0, 3)
  312. ZEND_ARG_INFO(0, stream_id)
  313. ZEND_ARG_INFO(0, sequence)
  314. ZEND_ARG_INFO(0, flag)
  315. ZEND_ARG_INFO(0, options)
  316. ZEND_END_ARG_INFO()
  317. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_sort, 0, 0, 3)
  318. ZEND_ARG_INFO(0, stream_id)
  319. ZEND_ARG_INFO(0, criteria)
  320. ZEND_ARG_INFO(0, reverse)
  321. ZEND_ARG_INFO(0, options)
  322. ZEND_ARG_INFO(0, search_criteria)
  323. ZEND_ARG_INFO(0, charset)
  324. ZEND_END_ARG_INFO()
  325. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_fetchheader, 0, 0, 2)
  326. ZEND_ARG_INFO(0, stream_id)
  327. ZEND_ARG_INFO(0, msg_no)
  328. ZEND_ARG_INFO(0, options)
  329. ZEND_END_ARG_INFO()
  330. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_uid, 0, 0, 2)
  331. ZEND_ARG_INFO(0, stream_id)
  332. ZEND_ARG_INFO(0, msg_no)
  333. ZEND_END_ARG_INFO()
  334. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_msgno, 0, 0, 2)
  335. ZEND_ARG_INFO(0, stream_id)
  336. ZEND_ARG_INFO(0, unique_msg_id)
  337. ZEND_END_ARG_INFO()
  338. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_status, 0, 0, 3)
  339. ZEND_ARG_INFO(0, stream_id)
  340. ZEND_ARG_INFO(0, mailbox)
  341. ZEND_ARG_INFO(0, options)
  342. ZEND_END_ARG_INFO()
  343. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_bodystruct, 0, 0, 3)
  344. ZEND_ARG_INFO(0, stream_id)
  345. ZEND_ARG_INFO(0, msg_no)
  346. ZEND_ARG_INFO(0, section)
  347. ZEND_END_ARG_INFO()
  348. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_fetch_overview, 0, 0, 2)
  349. ZEND_ARG_INFO(0, stream_id)
  350. ZEND_ARG_INFO(0, sequence)
  351. ZEND_ARG_INFO(0, options)
  352. ZEND_END_ARG_INFO()
  353. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mail_compose, 0, 0, 2)
  354. ZEND_ARG_INFO(0, envelope)
  355. ZEND_ARG_INFO(0, body)
  356. ZEND_END_ARG_INFO()
  357. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mail, 0, 0, 3)
  358. ZEND_ARG_INFO(0, to)
  359. ZEND_ARG_INFO(0, subject)
  360. ZEND_ARG_INFO(0, message)
  361. ZEND_ARG_INFO(0, additional_headers)
  362. ZEND_ARG_INFO(0, cc)
  363. ZEND_ARG_INFO(0, bcc)
  364. ZEND_ARG_INFO(0, rpath)
  365. ZEND_END_ARG_INFO()
  366. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_search, 0, 0, 2)
  367. ZEND_ARG_INFO(0, stream_id)
  368. ZEND_ARG_INFO(0, criteria)
  369. ZEND_ARG_INFO(0, options)
  370. ZEND_ARG_INFO(0, charset)
  371. ZEND_END_ARG_INFO()
  372. ZEND_BEGIN_ARG_INFO(arginfo_imap_alerts, 0)
  373. ZEND_END_ARG_INFO()
  374. ZEND_BEGIN_ARG_INFO(arginfo_imap_errors, 0)
  375. ZEND_END_ARG_INFO()
  376. ZEND_BEGIN_ARG_INFO(arginfo_imap_last_error, 0)
  377. ZEND_END_ARG_INFO()
  378. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mime_header_decode, 0, 0, 1)
  379. ZEND_ARG_INFO(0, str)
  380. ZEND_END_ARG_INFO()
  381. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_thread, 0, 0, 1)
  382. ZEND_ARG_INFO(0, stream_id)
  383. ZEND_ARG_INFO(0, options)
  384. ZEND_END_ARG_INFO()
  385. ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_timeout, 0, 0, 1)
  386. ZEND_ARG_INFO(0, timeout_type)
  387. ZEND_ARG_INFO(0, timeout)
  388. ZEND_END_ARG_INFO()
  389. /* }}} */
  390. /* {{{ imap_functions[]
  391. */
  392. const zend_function_entry imap_functions[] = {
  393. PHP_FE(imap_open, arginfo_imap_open)
  394. PHP_FE(imap_reopen, arginfo_imap_reopen)
  395. PHP_FE(imap_close, arginfo_imap_close)
  396. PHP_FE(imap_num_msg, arginfo_imap_num_msg)
  397. PHP_FE(imap_num_recent, arginfo_imap_num_recent)
  398. PHP_FE(imap_headers, arginfo_imap_headers)
  399. PHP_FE(imap_headerinfo, arginfo_imap_headerinfo)
  400. PHP_FE(imap_rfc822_parse_headers, arginfo_imap_rfc822_parse_headers)
  401. PHP_FE(imap_rfc822_write_address, arginfo_imap_rfc822_write_address)
  402. PHP_FE(imap_rfc822_parse_adrlist, arginfo_imap_rfc822_parse_adrlist)
  403. PHP_FE(imap_body, arginfo_imap_body)
  404. PHP_FE(imap_bodystruct, arginfo_imap_bodystruct)
  405. PHP_FE(imap_fetchbody, arginfo_imap_fetchbody)
  406. PHP_FE(imap_fetchmime, arginfo_imap_fetchbody)
  407. PHP_FE(imap_savebody, arginfo_imap_savebody)
  408. PHP_FE(imap_fetchheader, arginfo_imap_fetchheader)
  409. PHP_FE(imap_fetchstructure, arginfo_imap_fetchstructure)
  410. PHP_FE(imap_gc, arginfo_imap_gc)
  411. PHP_FE(imap_expunge, arginfo_imap_expunge)
  412. PHP_FE(imap_delete, arginfo_imap_delete)
  413. PHP_FE(imap_undelete, arginfo_imap_undelete)
  414. PHP_FE(imap_check, arginfo_imap_check)
  415. PHP_FE(imap_listscan, arginfo_imap_listscan)
  416. PHP_FE(imap_mail_copy, arginfo_imap_mail_copy)
  417. PHP_FE(imap_mail_move, arginfo_imap_mail_move)
  418. PHP_FE(imap_mail_compose, arginfo_imap_mail_compose)
  419. PHP_FE(imap_createmailbox, arginfo_imap_createmailbox)
  420. PHP_FE(imap_renamemailbox, arginfo_imap_renamemailbox)
  421. PHP_FE(imap_deletemailbox, arginfo_imap_deletemailbox)
  422. PHP_FE(imap_subscribe, arginfo_imap_subscribe)
  423. PHP_FE(imap_unsubscribe, arginfo_imap_unsubscribe)
  424. PHP_FE(imap_append, arginfo_imap_append)
  425. PHP_FE(imap_ping, arginfo_imap_ping)
  426. PHP_FE(imap_base64, arginfo_imap_base64)
  427. PHP_FE(imap_qprint, arginfo_imap_qprint)
  428. PHP_FE(imap_8bit, arginfo_imap_8bit)
  429. PHP_FE(imap_binary, arginfo_imap_binary)
  430. PHP_FE(imap_utf8, arginfo_imap_utf8)
  431. PHP_FE(imap_status, arginfo_imap_status)
  432. PHP_FE(imap_mailboxmsginfo, arginfo_imap_mailboxmsginfo)
  433. PHP_FE(imap_setflag_full, arginfo_imap_setflag_full)
  434. PHP_FE(imap_clearflag_full, arginfo_imap_clearflag_full)
  435. PHP_FE(imap_sort, arginfo_imap_sort)
  436. PHP_FE(imap_uid, arginfo_imap_uid)
  437. PHP_FE(imap_msgno, arginfo_imap_msgno)
  438. PHP_FE(imap_list, arginfo_imap_list)
  439. PHP_FE(imap_lsub, arginfo_imap_lsub)
  440. PHP_FE(imap_fetch_overview, arginfo_imap_fetch_overview)
  441. PHP_FE(imap_alerts, arginfo_imap_alerts)
  442. PHP_FE(imap_errors, arginfo_imap_errors)
  443. PHP_FE(imap_last_error, arginfo_imap_last_error)
  444. PHP_FE(imap_search, arginfo_imap_search)
  445. PHP_FE(imap_utf7_decode, arginfo_imap_utf7_decode)
  446. PHP_FE(imap_utf7_encode, arginfo_imap_utf7_encode)
  447. #ifdef HAVE_IMAP_MUTF7
  448. PHP_FE(imap_utf8_to_mutf7, arginfo_imap_utf8_to_mutf7)
  449. PHP_FE(imap_mutf7_to_utf8, arginfo_imap_mutf7_to_utf8)
  450. #endif
  451. PHP_FE(imap_mime_header_decode, arginfo_imap_mime_header_decode)
  452. PHP_FE(imap_thread, arginfo_imap_thread)
  453. PHP_FE(imap_timeout, arginfo_imap_timeout)
  454. #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
  455. PHP_FE(imap_get_quota, arginfo_imap_get_quota)
  456. PHP_FE(imap_get_quotaroot, arginfo_imap_get_quotaroot)
  457. PHP_FE(imap_set_quota, arginfo_imap_set_quota)
  458. PHP_FE(imap_setacl, arginfo_imap_setacl)
  459. PHP_FE(imap_getacl, arginfo_imap_getacl)
  460. #endif
  461. PHP_FE(imap_mail, arginfo_imap_mail)
  462. PHP_FALIAS(imap_header, imap_headerinfo, arginfo_imap_headerinfo)
  463. PHP_FALIAS(imap_listmailbox, imap_list, arginfo_imap_list)
  464. PHP_FALIAS(imap_getmailboxes, imap_list_full, arginfo_imap_getmailboxes)
  465. PHP_FALIAS(imap_scanmailbox, imap_listscan, arginfo_imap_listscan)
  466. PHP_FALIAS(imap_listsubscribed, imap_lsub, arginfo_imap_lsub)
  467. PHP_FALIAS(imap_getsubscribed, imap_lsub_full, arginfo_imap_getsubscribed)
  468. PHP_FALIAS(imap_fetchtext, imap_body, arginfo_imap_body)
  469. PHP_FALIAS(imap_scan, imap_listscan, arginfo_imap_listscan)
  470. PHP_FALIAS(imap_create, imap_createmailbox, arginfo_imap_createmailbox)
  471. PHP_FALIAS(imap_rename, imap_renamemailbox, arginfo_imap_renamemailbox)
  472. {NULL, NULL, NULL}
  473. };
  474. /* }}} */
  475. /* {{{ imap dependencies */
  476. static const zend_module_dep imap_deps[] = {
  477. ZEND_MOD_REQUIRED("standard")
  478. {NULL, NULL, NULL}
  479. };
  480. /* }}} */
  481. /* {{{ imap_module_entry
  482. */
  483. zend_module_entry imap_module_entry = {
  484. STANDARD_MODULE_HEADER_EX, NULL,
  485. imap_deps,
  486. "imap",
  487. imap_functions,
  488. PHP_MINIT(imap),
  489. NULL,
  490. PHP_RINIT(imap),
  491. PHP_RSHUTDOWN(imap),
  492. PHP_MINFO(imap),
  493. NO_VERSION_YET,
  494. PHP_MODULE_GLOBALS(imap),
  495. PHP_GINIT(imap),
  496. NULL,
  497. NULL,
  498. STANDARD_MODULE_PROPERTIES_EX
  499. };
  500. /* }}} */
  501. #ifdef COMPILE_DL_IMAP
  502. ZEND_GET_MODULE(imap)
  503. #endif
  504. /* True globals, no need for thread safety */
  505. static int le_imap;
  506. #define PHP_IMAP_CHECK_MSGNO(msgindex) \
  507. if ((msgindex < 1) || ((unsigned) msgindex > imap_le_struct->imap_stream->nmsgs)) { \
  508. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad message number"); \
  509. RETURN_FALSE; \
  510. } \
  511. /* {{{ mail_close_it
  512. */
  513. static void mail_close_it(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  514. {
  515. pils *imap_le_struct = (pils *)rsrc->ptr;
  516. /* Do not try to close prototype streams */
  517. if (!(imap_le_struct->flags & OP_PROTOTYPE)) {
  518. mail_close_full(imap_le_struct->imap_stream, imap_le_struct->flags);
  519. }
  520. if (IMAPG(imap_user)) {
  521. efree(IMAPG(imap_user));
  522. IMAPG(imap_user) = 0;
  523. }
  524. if (IMAPG(imap_password)) {
  525. efree(IMAPG(imap_password));
  526. IMAPG(imap_password) = 0;
  527. }
  528. efree(imap_le_struct);
  529. }
  530. /* }}} */
  531. /* {{{ add_assoc_object
  532. */
  533. static int add_assoc_object(zval *arg, char *key, zval *tmp TSRMLS_DC)
  534. {
  535. HashTable *symtable;
  536. if (Z_TYPE_P(arg) == IS_OBJECT) {
  537. symtable = Z_OBJPROP_P(arg);
  538. } else {
  539. symtable = Z_ARRVAL_P(arg);
  540. }
  541. return zend_hash_update(symtable, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL);
  542. }
  543. /* }}} */
  544. /* {{{ add_next_index_object
  545. */
  546. static inline int add_next_index_object(zval *arg, zval *tmp TSRMLS_DC)
  547. {
  548. HashTable *symtable;
  549. if (Z_TYPE_P(arg) == IS_OBJECT) {
  550. symtable = Z_OBJPROP_P(arg);
  551. } else {
  552. symtable = Z_ARRVAL_P(arg);
  553. }
  554. return zend_hash_next_index_insert(symtable, (void *) &tmp, sizeof(zval *), NULL);
  555. }
  556. /* }}} */
  557. /* {{{ mail_newfolderobjectlist
  558. *
  559. * Mail instantiate FOBJECTLIST
  560. * Returns: new FOBJECTLIST list
  561. * Author: CJH
  562. */
  563. FOBJECTLIST *mail_newfolderobjectlist(void)
  564. {
  565. return (FOBJECTLIST *) memset(fs_get(sizeof(FOBJECTLIST)), 0, sizeof(FOBJECTLIST));
  566. }
  567. /* }}} */
  568. /* {{{ mail_free_foblist
  569. *
  570. * Mail garbage collect FOBJECTLIST
  571. * Accepts: pointer to FOBJECTLIST pointer
  572. * Author: CJH
  573. */
  574. void mail_free_foblist(FOBJECTLIST **foblist, FOBJECTLIST **tail)
  575. {
  576. FOBJECTLIST *cur, *next;
  577. for (cur=*foblist, next=cur->next; cur; cur=next) {
  578. next = cur->next;
  579. if(cur->text.data)
  580. fs_give((void **)&(cur->text.data));
  581. fs_give((void **)&cur);
  582. }
  583. *tail = NIL;
  584. *foblist = NIL;
  585. }
  586. /* }}} */
  587. /* {{{ mail_newerrorlist
  588. *
  589. * Mail instantiate ERRORLIST
  590. * Returns: new ERRORLIST list
  591. * Author: CJH
  592. */
  593. ERRORLIST *mail_newerrorlist(void)
  594. {
  595. return (ERRORLIST *) memset(fs_get(sizeof(ERRORLIST)), 0, sizeof(ERRORLIST));
  596. }
  597. /* }}} */
  598. /* {{{ mail_free_errorlist
  599. *
  600. * Mail garbage collect FOBJECTLIST
  601. * Accepts: pointer to FOBJECTLIST pointer
  602. * Author: CJH
  603. */
  604. void mail_free_errorlist(ERRORLIST **errlist)
  605. {
  606. if (*errlist) { /* only free if exists */
  607. if ((*errlist)->text.data) {
  608. fs_give((void **) &(*errlist)->text.data);
  609. }
  610. mail_free_errorlist (&(*errlist)->next);
  611. fs_give((void **) errlist); /* return string to free storage */
  612. }
  613. }
  614. /* }}} */
  615. /* {{{ mail_newmessagelist
  616. *
  617. * Mail instantiate MESSAGELIST
  618. * Returns: new MESSAGELIST list
  619. * Author: CJH
  620. */
  621. MESSAGELIST *mail_newmessagelist(void)
  622. {
  623. return (MESSAGELIST *) memset(fs_get(sizeof(MESSAGELIST)), 0, sizeof(MESSAGELIST));
  624. }
  625. /* }}} */
  626. /* {{{ mail_free_messagelist
  627. *
  628. * Mail garbage collect MESSAGELIST
  629. * Accepts: pointer to MESSAGELIST pointer
  630. * Author: CJH
  631. */
  632. void mail_free_messagelist(MESSAGELIST **msglist, MESSAGELIST **tail)
  633. {
  634. MESSAGELIST *cur, *next;
  635. for (cur = *msglist, next = cur->next; cur; cur = next) {
  636. next = cur->next;
  637. fs_give((void **)&cur);
  638. }
  639. *tail = NIL;
  640. *msglist = NIL;
  641. }
  642. /* }}} */
  643. #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
  644. /* {{{ mail_getquota
  645. *
  646. * Mail GET_QUOTA callback
  647. * Called via the mail_parameter function in c-client:src/c-client/mail.c
  648. * Author DRK
  649. */
  650. void mail_getquota(MAILSTREAM *stream, char *qroot, QUOTALIST *qlist)
  651. {
  652. zval *t_map, *return_value;
  653. TSRMLS_FETCH();
  654. return_value = *IMAPG(quota_return);
  655. /* put parsing code here */
  656. for(; qlist; qlist = qlist->next) {
  657. MAKE_STD_ZVAL(t_map);
  658. array_init(t_map);
  659. if (strncmp(qlist->name, "STORAGE", 7) == 0)
  660. {
  661. /* this is to add backwards compatibility */
  662. add_assoc_long_ex(return_value, "usage", sizeof("usage"), qlist->usage);
  663. add_assoc_long_ex(return_value, "limit", sizeof("limit"), qlist->limit);
  664. }
  665. add_assoc_long_ex(t_map, "usage", sizeof("usage"), qlist->usage);
  666. add_assoc_long_ex(t_map, "limit", sizeof("limit"), qlist->limit);
  667. add_assoc_zval_ex(return_value, qlist->name, strlen(qlist->name)+1, t_map);
  668. }
  669. }
  670. /* }}} */
  671. /* {{{ mail_getquota
  672. *
  673. * Mail GET_ACL callback
  674. * Called via the mail_parameter function in c-client:src/c-client/mail.c
  675. */
  676. void mail_getacl(MAILSTREAM *stream, char *mailbox, ACLLIST *alist)
  677. {
  678. TSRMLS_FETCH();
  679. /* walk through the ACLLIST */
  680. for(; alist; alist = alist->next) {
  681. add_assoc_stringl(IMAPG(imap_acl_list), alist->identifier, alist->rights, strlen(alist->rights), 1);
  682. }
  683. }
  684. /* }}} */
  685. #endif
  686. /* {{{ PHP_GINIT_FUNCTION
  687. */
  688. static PHP_GINIT_FUNCTION(imap)
  689. {
  690. imap_globals->imap_user = NIL;
  691. imap_globals->imap_password = NIL;
  692. imap_globals->imap_alertstack = NIL;
  693. imap_globals->imap_errorstack = NIL;
  694. imap_globals->imap_folders = NIL;
  695. imap_globals->imap_folders_tail = NIL;
  696. imap_globals->imap_sfolders = NIL;
  697. imap_globals->imap_sfolders_tail = NIL;
  698. imap_globals->imap_messages = NIL;
  699. imap_globals->imap_messages_tail = NIL;
  700. imap_globals->imap_folder_objects = NIL;
  701. imap_globals->imap_folder_objects_tail = NIL;
  702. imap_globals->imap_sfolder_objects = NIL;
  703. imap_globals->imap_sfolder_objects_tail = NIL;
  704. imap_globals->folderlist_style = FLIST_ARRAY;
  705. #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
  706. imap_globals->quota_return = NIL;
  707. imap_globals->imap_acl_list = NIL;
  708. #endif
  709. imap_globals->gets_stream = NIL;
  710. }
  711. /* }}} */
  712. /* {{{ PHP_MINIT_FUNCTION
  713. */
  714. PHP_MINIT_FUNCTION(imap)
  715. {
  716. unsigned long sa_all = SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY;
  717. #ifndef PHP_WIN32
  718. mail_link(&unixdriver); /* link in the unix driver */
  719. mail_link(&mhdriver); /* link in the mh driver */
  720. /* mail_link(&mxdriver); */ /* According to c-client docs (internal.txt) this shouldn't be used. */
  721. mail_link(&mmdfdriver); /* link in the mmdf driver */
  722. mail_link(&newsdriver); /* link in the news driver */
  723. mail_link(&philedriver); /* link in the phile driver */
  724. #endif
  725. mail_link(&imapdriver); /* link in the imap driver */
  726. mail_link(&nntpdriver); /* link in the nntp driver */
  727. mail_link(&pop3driver); /* link in the pop3 driver */
  728. mail_link(&mbxdriver); /* link in the mbx driver */
  729. mail_link(&tenexdriver); /* link in the tenex driver */
  730. mail_link(&mtxdriver); /* link in the mtx driver */
  731. mail_link(&dummydriver); /* link in the dummy driver */
  732. #ifndef PHP_WIN32
  733. auth_link(&auth_log); /* link in the log authenticator */
  734. auth_link(&auth_md5); /* link in the cram-md5 authenticator */
  735. #if HAVE_IMAP_KRB && defined(HAVE_IMAP_AUTH_GSS)
  736. auth_link(&auth_gss); /* link in the gss authenticator */
  737. #endif
  738. auth_link(&auth_pla); /* link in the plain authenticator */
  739. #endif
  740. #ifdef HAVE_IMAP_SSL
  741. ssl_onceonlyinit ();
  742. #endif
  743. /* lets allow NIL */
  744. REGISTER_LONG_CONSTANT("NIL", NIL, CONST_PERSISTENT | CONST_CS);
  745. /* plug in our gets */
  746. mail_parameters(NIL, SET_GETS, (void *) NIL);
  747. /* set default timeout values */
  748. mail_parameters(NIL, SET_OPENTIMEOUT, (void *) FG(default_socket_timeout));
  749. mail_parameters(NIL, SET_READTIMEOUT, (void *) FG(default_socket_timeout));
  750. mail_parameters(NIL, SET_WRITETIMEOUT, (void *) FG(default_socket_timeout));
  751. mail_parameters(NIL, SET_CLOSETIMEOUT, (void *) FG(default_socket_timeout));
  752. /* timeout constants */
  753. REGISTER_LONG_CONSTANT("IMAP_OPENTIMEOUT", 1, CONST_PERSISTENT | CONST_CS);
  754. REGISTER_LONG_CONSTANT("IMAP_READTIMEOUT", 2, CONST_PERSISTENT | CONST_CS);
  755. REGISTER_LONG_CONSTANT("IMAP_WRITETIMEOUT", 3, CONST_PERSISTENT | CONST_CS);
  756. REGISTER_LONG_CONSTANT("IMAP_CLOSETIMEOUT", 4, CONST_PERSISTENT | CONST_CS);
  757. /* Open Options */
  758. REGISTER_LONG_CONSTANT("OP_DEBUG", OP_DEBUG, CONST_PERSISTENT | CONST_CS);
  759. /* debug protocol negotiations */
  760. REGISTER_LONG_CONSTANT("OP_READONLY", OP_READONLY, CONST_PERSISTENT | CONST_CS);
  761. /* read-only open */
  762. REGISTER_LONG_CONSTANT("OP_ANONYMOUS", OP_ANONYMOUS, CONST_PERSISTENT | CONST_CS);
  763. /* anonymous open of newsgroup */
  764. REGISTER_LONG_CONSTANT("OP_SHORTCACHE", OP_SHORTCACHE, CONST_PERSISTENT | CONST_CS);
  765. /* short (elt-only) caching */
  766. REGISTER_LONG_CONSTANT("OP_SILENT", OP_SILENT, CONST_PERSISTENT | CONST_CS);
  767. /* don't pass up events (internal use) */
  768. REGISTER_LONG_CONSTANT("OP_PROTOTYPE", OP_PROTOTYPE, CONST_PERSISTENT | CONST_CS);
  769. /* return driver prototype */
  770. REGISTER_LONG_CONSTANT("OP_HALFOPEN", OP_HALFOPEN, CONST_PERSISTENT | CONST_CS);
  771. /* half-open (IMAP connect but no select) */
  772. REGISTER_LONG_CONSTANT("OP_EXPUNGE", OP_EXPUNGE, CONST_PERSISTENT | CONST_CS);
  773. /* silently expunge recycle stream */
  774. REGISTER_LONG_CONSTANT("OP_SECURE", OP_SECURE, CONST_PERSISTENT | CONST_CS);
  775. /* don't do non-secure authentication */
  776. /*
  777. PHP re-assigns CL_EXPUNGE a custom value that can be used as part of the imap_open() bitfield
  778. because it seems like a good idea to be able to indicate that the mailbox should be
  779. automatically expunged during imap_open in case the script get interrupted and it doesn't get
  780. to the imap_close() where this option is normally placed. If the c-client library adds other
  781. options and the value for this one conflicts, simply make PHP_EXPUNGE higher at the top of
  782. this file
  783. */
  784. REGISTER_LONG_CONSTANT("CL_EXPUNGE", PHP_EXPUNGE, CONST_PERSISTENT | CONST_CS);
  785. /* expunge silently */
  786. /* Fetch options */
  787. REGISTER_LONG_CONSTANT("FT_UID", FT_UID, CONST_PERSISTENT | CONST_CS);
  788. /* argument is a UID */
  789. REGISTER_LONG_CONSTANT("FT_PEEK", FT_PEEK, CONST_PERSISTENT | CONST_CS);
  790. /* peek at data */
  791. REGISTER_LONG_CONSTANT("FT_NOT", FT_NOT, CONST_PERSISTENT | CONST_CS);
  792. /* NOT flag for header lines fetch */
  793. REGISTER_LONG_CONSTANT("FT_INTERNAL", FT_INTERNAL, CONST_PERSISTENT | CONST_CS);
  794. /* text can be internal strings */
  795. REGISTER_LONG_CONSTANT("FT_PREFETCHTEXT", FT_PREFETCHTEXT, CONST_PERSISTENT | CONST_CS);
  796. /* IMAP prefetch text when fetching header */
  797. /* Flagging options */
  798. REGISTER_LONG_CONSTANT("ST_UID", ST_UID, CONST_PERSISTENT | CONST_CS);
  799. /* argument is a UID sequence */
  800. REGISTER_LONG_CONSTANT("ST_SILENT", ST_SILENT, CONST_PERSISTENT | CONST_CS);
  801. /* don't return results */
  802. REGISTER_LONG_CONSTANT("ST_SET", ST_SET, CONST_PERSISTENT | CONST_CS);
  803. /* set vs. clear */
  804. /* Copy options */
  805. REGISTER_LONG_CONSTANT("CP_UID", CP_UID, CONST_PERSISTENT | CONST_CS);
  806. /* argument is a UID sequence */
  807. REGISTER_LONG_CONSTANT("CP_MOVE", CP_MOVE, CONST_PERSISTENT | CONST_CS);
  808. /* delete from source after copying */
  809. /* Search/sort options */
  810. REGISTER_LONG_CONSTANT("SE_UID", SE_UID, CONST_PERSISTENT | CONST_CS);
  811. /* return UID */
  812. REGISTER_LONG_CONSTANT("SE_FREE", SE_FREE, CONST_PERSISTENT | CONST_CS);
  813. /* free search program after finished */
  814. REGISTER_LONG_CONSTANT("SE_NOPREFETCH", SE_NOPREFETCH, CONST_PERSISTENT | CONST_CS);
  815. /* no search prefetching */
  816. REGISTER_LONG_CONSTANT("SO_FREE", SO_FREE, CONST_PERSISTENT | CONST_CS);
  817. /* free sort program after finished */
  818. REGISTER_LONG_CONSTANT("SO_NOSERVER", SO_NOSERVER, CONST_PERSISTENT | CONST_CS);
  819. /* don't do server-based sort */
  820. /* Status options */
  821. REGISTER_LONG_CONSTANT("SA_MESSAGES", SA_MESSAGES , CONST_PERSISTENT | CONST_CS);
  822. /* number of messages */
  823. REGISTER_LONG_CONSTANT("SA_RECENT", SA_RECENT, CONST_PERSISTENT | CONST_CS);
  824. /* number of recent messages */
  825. REGISTER_LONG_CONSTANT("SA_UNSEEN", SA_UNSEEN , CONST_PERSISTENT | CONST_CS);
  826. /* number of unseen messages */
  827. REGISTER_LONG_CONSTANT("SA_UIDNEXT", SA_UIDNEXT, CONST_PERSISTENT | CONST_CS);
  828. /* next UID to be assigned */
  829. REGISTER_LONG_CONSTANT("SA_UIDVALIDITY", SA_UIDVALIDITY , CONST_PERSISTENT | CONST_CS);
  830. /* UID validity value */
  831. REGISTER_LONG_CONSTANT("SA_ALL", sa_all, CONST_PERSISTENT | CONST_CS);
  832. /* get all status information */
  833. /* Bits for mm_list() and mm_lsub() */
  834. REGISTER_LONG_CONSTANT("LATT_NOINFERIORS", LATT_NOINFERIORS , CONST_PERSISTENT | CONST_CS);
  835. REGISTER_LONG_CONSTANT("LATT_NOSELECT", LATT_NOSELECT, CONST_PERSISTENT | CONST_CS);
  836. REGISTER_LONG_CONSTANT("LATT_MARKED", LATT_MARKED, CONST_PERSISTENT | CONST_CS);
  837. REGISTER_LONG_CONSTANT("LATT_UNMARKED", LATT_UNMARKED , CONST_PERSISTENT | CONST_CS);
  838. #ifdef LATT_REFERRAL
  839. REGISTER_LONG_CONSTANT("LATT_REFERRAL", LATT_REFERRAL, CONST_PERSISTENT | CONST_CS);
  840. #endif
  841. #ifdef LATT_HASCHILDREN
  842. REGISTER_LONG_CONSTANT("LATT_HASCHILDREN", LATT_HASCHILDREN, CONST_PERSISTENT | CONST_CS);
  843. #endif
  844. #ifdef LATT_HASNOCHILDREN
  845. REGISTER_LONG_CONSTANT("LATT_HASNOCHILDREN", LATT_HASNOCHILDREN, CONST_PERSISTENT | CONST_CS);
  846. #endif
  847. /* Sort functions */
  848. REGISTER_LONG_CONSTANT("SORTDATE", SORTDATE , CONST_PERSISTENT | CONST_CS);
  849. /* date */
  850. REGISTER_LONG_CONSTANT("SORTARRIVAL", SORTARRIVAL , CONST_PERSISTENT | CONST_CS);
  851. /* arrival date */
  852. REGISTER_LONG_CONSTANT("SORTFROM", SORTFROM , CONST_PERSISTENT | CONST_CS);
  853. /* from */
  854. REGISTER_LONG_CONSTANT("SORTSUBJECT", SORTSUBJECT , CONST_PERSISTENT | CONST_CS);
  855. /* subject */
  856. REGISTER_LONG_CONSTANT("SORTTO", SORTTO , CONST_PERSISTENT | CONST_CS);
  857. /* to */
  858. REGISTER_LONG_CONSTANT("SORTCC", SORTCC , CONST_PERSISTENT | CONST_CS);
  859. /* cc */
  860. REGISTER_LONG_CONSTANT("SORTSIZE", SORTSIZE , CONST_PERSISTENT | CONST_CS);
  861. /* size */
  862. REGISTER_LONG_CONSTANT("TYPETEXT", TYPETEXT , CONST_PERSISTENT | CONST_CS);
  863. REGISTER_LONG_CONSTANT("TYPEMULTIPART", TYPEMULTIPART , CONST_PERSISTENT | CONST_CS);
  864. REGISTER_LONG_CONSTANT("TYPEMESSAGE", TYPEMESSAGE , CONST_PERSISTENT | CONST_CS);
  865. REGISTER_LONG_CONSTANT("TYPEAPPLICATION", TYPEAPPLICATION , CONST_PERSISTENT | CONST_CS);
  866. REGISTER_LONG_CONSTANT("TYPEAUDIO", TYPEAUDIO , CONST_PERSISTENT | CONST_CS);
  867. REGISTER_LONG_CONSTANT("TYPEIMAGE", TYPEIMAGE , CONST_PERSISTENT | CONST_CS);
  868. REGISTER_LONG_CONSTANT("TYPEVIDEO", TYPEVIDEO , CONST_PERSISTENT | CONST_CS);
  869. REGISTER_LONG_CONSTANT("TYPEMODEL", TYPEMODEL , CONST_PERSISTENT | CONST_CS);
  870. REGISTER_LONG_CONSTANT("TYPEOTHER", TYPEOTHER , CONST_PERSISTENT | CONST_CS);
  871. /*
  872. TYPETEXT unformatted text
  873. TYPEMULTIPART multiple part
  874. TYPEMESSAGE encapsulated message
  875. TYPEAPPLICATION application data
  876. TYPEAUDIO audio
  877. TYPEIMAGE static image (GIF, JPEG, etc.)
  878. TYPEVIDEO video
  879. TYPEMODEL model
  880. TYPEOTHER unknown
  881. */
  882. REGISTER_LONG_CONSTANT("ENC7BIT", ENC7BIT , CONST_PERSISTENT | CONST_CS);
  883. REGISTER_LONG_CONSTANT("ENC8BIT", ENC8BIT , CONST_PERSISTENT | CONST_CS);
  884. REGISTER_LONG_CONSTANT("ENCBINARY", ENCBINARY , CONST_PERSISTENT | CONST_CS);
  885. REGISTER_LONG_CONSTANT("ENCBASE64", ENCBASE64, CONST_PERSISTENT | CONST_CS);
  886. REGISTER_LONG_CONSTANT("ENCQUOTEDPRINTABLE", ENCQUOTEDPRINTABLE , CONST_PERSISTENT | CONST_CS);
  887. REGISTER_LONG_CONSTANT("ENCOTHER", ENCOTHER , CONST_PERSISTENT | CONST_CS);
  888. /*
  889. ENC7BIT 7 bit SMTP semantic data
  890. ENC8BIT 8 bit SMTP semantic data
  891. ENCBINARY 8 bit binary data
  892. ENCBASE64 base-64 encoded data
  893. ENCQUOTEDPRINTABLE human-readable 8-as-7 bit data
  894. ENCOTHER unknown
  895. */
  896. REGISTER_LONG_CONSTANT("IMAP_GC_ELT", GC_ELT , CONST_PERSISTENT | CONST_CS);
  897. REGISTER_LONG_CONSTANT("IMAP_GC_ENV", GC_ENV , CONST_PERSISTENT | CONST_CS);
  898. REGISTER_LONG_CONSTANT("IMAP_GC_TEXTS", GC_TEXTS , CONST_PERSISTENT | CONST_CS);
  899. /*
  900. GC_ELT message cache elements
  901. GC_ENV ENVELOPEs and BODYs
  902. GC_TEXTS texts
  903. */
  904. le_imap = zend_register_list_destructors_ex(mail_close_it, NULL, "imap", module_number);
  905. return SUCCESS;
  906. }
  907. /* }}} */
  908. /* {{{ PHP_RINIT_FUNCTION
  909. */
  910. PHP_RINIT_FUNCTION(imap)
  911. {
  912. IMAPG(imap_errorstack) = NIL;
  913. IMAPG(imap_alertstack) = NIL;
  914. IMAPG(gets_stream) = NIL;
  915. return SUCCESS;
  916. }
  917. /* }}} */
  918. /* {{{ PHP_RSHUTDOWN_FUNCTION
  919. */
  920. PHP_RSHUTDOWN_FUNCTION(imap)
  921. {
  922. ERRORLIST *ecur = NIL;
  923. STRINGLIST *acur = NIL;
  924. if (IMAPG(imap_errorstack) != NIL) {
  925. /* output any remaining errors at their original error level */
  926. if (EG(error_reporting) & E_NOTICE) {
  927. ecur = IMAPG(imap_errorstack);
  928. while (ecur != NIL) {
  929. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s (errflg=%ld)", ecur->LTEXT, ecur->errflg);
  930. ecur = ecur->next;
  931. }
  932. }
  933. mail_free_errorlist(&IMAPG(imap_errorstack));
  934. }
  935. if (IMAPG(imap_alertstack) != NIL) {
  936. /* output any remaining alerts at E_NOTICE level */
  937. if (EG(error_reporting) & E_NOTICE) {
  938. acur = IMAPG(imap_alertstack);
  939. while (acur != NIL) {
  940. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", acur->LTEXT);
  941. acur = acur->next;
  942. }
  943. }
  944. mail_free_stringlist(&IMAPG(imap_alertstack));
  945. IMAPG(imap_alertstack) = NIL;
  946. }
  947. return SUCCESS;
  948. }
  949. /* }}} */
  950. #if !defined(CCLIENTVERSION)
  951. #if HAVE_IMAP2007e
  952. #define CCLIENTVERSION "2007e"
  953. #elif HAVE_IMAP2007d
  954. #define CCLIENTVERSION "2007d"
  955. #elif HAVE_IMAP2007b
  956. #define CCLIENTVERSION "2007b"
  957. #elif HAVE_IMAP2007a
  958. #define CCLIENTVERSION "2007a"
  959. #elif HAVE_IMAP2004
  960. #define CCLIENTVERSION "2004"
  961. #elif HAVE_IMAP2001
  962. #define CCLIENTVERSION "2001"
  963. #elif HAVE_IMAP2000
  964. #define CCLIENTVERSION "2000"
  965. #elif defined(IMAP41)
  966. #define CCLIENTVERSION "4.1"
  967. #else
  968. #define CCLIENTVERSION "4.0"
  969. #endif
  970. #endif
  971. /* {{{ PHP_MINFO_FUNCTION
  972. */
  973. PHP_MINFO_FUNCTION(imap)
  974. {
  975. php_info_print_table_start();
  976. php_info_print_table_row(2, "IMAP c-Client Version", CCLIENTVERSION);
  977. #if HAVE_IMAP_SSL
  978. php_info_print_table_row(2, "SSL Support", "enabled");
  979. #endif
  980. #if HAVE_IMAP_KRB && HAVE_IMAP_AUTH_GSS
  981. php_info_print_table_row(2, "Kerberos Support", "enabled");
  982. #endif
  983. php_info_print_table_end();
  984. }
  985. /* }}} */
  986. /* {{{ imap_do_open
  987. */
  988. static void php_imap_do_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
  989. {
  990. char *mailbox, *user, *passwd;
  991. int mailbox_len, user_len, passwd_len;
  992. long retries = 0, flags = NIL, cl_flags = NIL;
  993. MAILSTREAM *imap_stream;
  994. pils *imap_le_struct;
  995. zval *params = NULL;
  996. int argc = ZEND_NUM_ARGS();
  997. if (zend_parse_parameters(argc TSRMLS_CC, "sss|lla", &mailbox, &mailbox_len, &user, &user_len,
  998. &passwd, &passwd_len, &flags, &retries, &params) == FAILURE) {
  999. return;
  1000. }
  1001. if (argc >= 4) {
  1002. if (flags & PHP_EXPUNGE) {
  1003. cl_flags = CL_EXPUNGE;
  1004. flags ^= PHP_EXPUNGE;
  1005. }
  1006. if (flags & OP_PROTOTYPE) {
  1007. cl_flags |= OP_PROTOTYPE;
  1008. }
  1009. }
  1010. if (params) {
  1011. zval **disabled_auth_method;
  1012. if (zend_hash_find(HASH_OF(params), "DISABLE_AUTHENTICATOR", sizeof("DISABLE_AUTHENTICATOR"), (void **)&disabled_auth_method) == SUCCESS) {
  1013. switch (Z_TYPE_PP(disabled_auth_method)) {
  1014. case IS_STRING:
  1015. if (Z_STRLEN_PP(disabled_auth_method) > 1) {
  1016. mail_parameters (NIL, DISABLE_AUTHENTICATOR, (void *)Z_STRVAL_PP(disabled_auth_method));
  1017. }
  1018. break;
  1019. case IS_ARRAY:
  1020. {
  1021. zval **z_auth_method;
  1022. int i;
  1023. int nelems = zend_hash_num_elements(Z_ARRVAL_PP(disabled_auth_method));
  1024. if (nelems == 0 ) {
  1025. break;
  1026. }
  1027. for (i = 0; i < nelems; i++) {
  1028. if (zend_hash_index_find(Z_ARRVAL_PP(disabled_auth_method), i, (void **) &z_auth_method) == SUCCESS) {
  1029. if (Z_TYPE_PP(z_auth_method) == IS_STRING) {
  1030. if (Z_STRLEN_PP(z_auth_method) > 1) {
  1031. mail_parameters (NIL, DISABLE_AUTHENTICATOR, (void *)Z_STRVAL_PP(disabled_auth_method));
  1032. }
  1033. } else {
  1034. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid argument, expect string or array of strings");
  1035. }
  1036. }
  1037. }
  1038. }
  1039. break;
  1040. case IS_LONG:
  1041. default:
  1042. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid argument, expect string or array of strings");
  1043. break;
  1044. }
  1045. }
  1046. }
  1047. if (IMAPG(imap_user)) {
  1048. efree(IMAPG(imap_user));
  1049. IMAPG(imap_user) = 0;
  1050. }
  1051. if (IMAPG(imap_password)) {
  1052. efree(IMAPG(imap_password));
  1053. IMAPG(imap_password) = 0;
  1054. }
  1055. /* local filename, need to perform open_basedir and safe_mode checks */
  1056. if (mailbox[0] != '{') {
  1057. if (strlen(mailbox) != mailbox_len) {
  1058. RETURN_FALSE;
  1059. }
  1060. if (php_check_open_basedir(mailbox TSRMLS_CC)) {
  1061. RETURN_FALSE;
  1062. }
  1063. }
  1064. IMAPG(imap_user) = estrndup(user, user_len);
  1065. IMAPG(imap_password) = estrndup(passwd, passwd_len);
  1066. #ifdef SET_MAXLOGINTRIALS
  1067. if (argc == 5) {
  1068. if (retries < 0) {
  1069. php_error_docref(NULL TSRMLS_CC, E_WARNING ,"Retries must be greater or equal to 0");
  1070. } else {
  1071. mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) retries);
  1072. }
  1073. }
  1074. #endif
  1075. imap_stream = mail_open(NIL, mailbox, flags);
  1076. if (imap_stream == NIL) {
  1077. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't open stream %s", mailbox);
  1078. efree(IMAPG(imap_user)); IMAPG(imap_user) = 0;
  1079. efree(IMAPG(imap_password)); IMAPG(imap_password) = 0;
  1080. RETURN_FALSE;
  1081. }
  1082. imap_le_struct = emalloc(sizeof(pils));
  1083. imap_le_struct->imap_stream = imap_stream;
  1084. imap_le_struct->flags = cl_flags;
  1085. ZEND_REGISTER_RESOURCE(return_value, imap_le_struct, le_imap);
  1086. }
  1087. /* }}} */
  1088. /* {{{ proto resource imap_open(string mailbox, string user, string password [, int options [, int n_retries]])
  1089. Open an IMAP stream to a mailbox */
  1090. PHP_FUNCTION(imap_open)
  1091. {
  1092. php_imap_do_open(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  1093. }
  1094. /* }}} */
  1095. /* {{{ proto bool imap_reopen(resource stream_id, string mailbox [, int options [, int n_retries]])
  1096. Reopen an IMAP stream to a new mailbox */
  1097. PHP_FUNCTION(imap_reopen)
  1098. {
  1099. zval *streamind;
  1100. char *mailbox;
  1101. int mailbox_len;
  1102. long options = 0, retries = 0;
  1103. pils *imap_le_struct;
  1104. MAILSTREAM *imap_stream;
  1105. long flags=NIL;
  1106. long cl_flags=NIL;
  1107. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ll", &streamind, &mailbox, &mailbox_len, &options, &retries) == FAILURE) {
  1108. return;
  1109. }
  1110. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1111. if (options) {
  1112. flags = options;
  1113. if (flags & PHP_EXPUNGE) {
  1114. cl_flags = CL_EXPUNGE;
  1115. flags ^= PHP_EXPUNGE;
  1116. }
  1117. imap_le_struct->flags = cl_flags;
  1118. }
  1119. #ifdef SET_MAXLOGINTRIALS
  1120. if (retries) {
  1121. mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) retries);
  1122. }
  1123. #endif
  1124. /* local filename, need to perform open_basedir and safe_mode checks */
  1125. if (mailbox[0] != '{' && php_check_open_basedir(mailbox TSRMLS_CC)) {
  1126. RETURN_FALSE;
  1127. }
  1128. imap_stream = mail_open(imap_le_struct->imap_stream, mailbox, flags);
  1129. if (imap_stream == NIL) {
  1130. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't re-open stream");
  1131. RETURN_FALSE;
  1132. }
  1133. imap_le_struct->imap_stream = imap_stream;
  1134. RETURN_TRUE;
  1135. }
  1136. /* }}} */
  1137. /* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options [, string internal_date]])
  1138. Append a new message to a specified mailbox */
  1139. PHP_FUNCTION(imap_append)
  1140. {
  1141. zval *streamind;
  1142. char *folder, *message, *internal_date = NULL, *flags = NULL;
  1143. int folder_len, message_len, internal_date_len = 0, flags_len = 0;
  1144. pils *imap_le_struct;
  1145. STRING st;
  1146. char* regex = "/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/";
  1147. const int regex_len = strlen(regex);
  1148. pcre_cache_entry *pce; /* Compiled regex */
  1149. zval *subpats = NULL; /* Parts (not used) */
  1150. long regex_flags = 0; /* Flags (not used) */
  1151. long start_offset = 0; /* Start offset (not used) */
  1152. int global = 0;
  1153. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|ss", &streamind, &folder, &folder_len, &message, &message_len, &flags, &flags_len, &internal_date, &internal_date_len) == FAILURE) {
  1154. return;
  1155. }
  1156. if (internal_date) {
  1157. /* Make sure the given internal_date string matches the RFC specifiedformat */
  1158. if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC))== NULL) {
  1159. RETURN_FALSE;
  1160. }
  1161. php_pcre_match_impl(pce, internal_date, internal_date_len, return_value, subpats, global,
  1162. 0, regex_flags, start_offset TSRMLS_CC);
  1163. if (!Z_LVAL_P(return_value)) {
  1164. php_error_docref(NULL TSRMLS_CC, E_WARNING, "internal date not correctly formatted");
  1165. internal_date = NULL;
  1166. }
  1167. }
  1168. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1169. INIT (&st, mail_string, (void *) message, message_len);
  1170. if (mail_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), (internal_date ? internal_date : NIL), &st)) {
  1171. RETURN_TRUE;
  1172. } else {
  1173. RETURN_FALSE;
  1174. }
  1175. }
  1176. /* }}} */
  1177. /* {{{ proto int imap_num_msg(resource stream_id)
  1178. Gives the number of messages in the current mailbox */
  1179. PHP_FUNCTION(imap_num_msg)
  1180. {
  1181. zval *streamind;
  1182. pils *imap_le_struct;
  1183. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &streamind) == FAILURE) {
  1184. return;
  1185. }
  1186. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1187. RETURN_LONG(imap_le_struct->imap_stream->nmsgs);
  1188. }
  1189. /* }}} */
  1190. /* {{{ proto bool imap_ping(resource stream_id)
  1191. Check if the IMAP stream is still active */
  1192. PHP_FUNCTION(imap_ping)
  1193. {
  1194. zval *streamind;
  1195. pils *imap_le_struct;
  1196. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &streamind) == FAILURE) {
  1197. return;
  1198. }
  1199. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1200. RETURN_BOOL(mail_ping(imap_le_struct->imap_stream));
  1201. }
  1202. /* }}} */
  1203. /* {{{ proto int imap_num_recent(resource stream_id)
  1204. Gives the number of recent messages in current mailbox */
  1205. PHP_FUNCTION(imap_num_recent)
  1206. {
  1207. zval *streamind;
  1208. pils *imap_le_struct;
  1209. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &streamind) == FAILURE) {
  1210. return;
  1211. }
  1212. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1213. RETURN_LONG(imap_le_struct->imap_stream->recent);
  1214. }
  1215. /* }}} */
  1216. #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
  1217. /* {{{ proto array imap_get_quota(resource stream_id, string qroot)
  1218. Returns the quota set to the mailbox account qroot */
  1219. PHP_FUNCTION(imap_get_quota)
  1220. {
  1221. zval *streamind;
  1222. char *qroot;
  1223. int qroot_len;
  1224. pils *imap_le_struct;
  1225. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &streamind, &qroot, &qroot_len) == FAILURE) {
  1226. return;
  1227. }
  1228. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1229. array_init(return_value);
  1230. IMAPG(quota_return) = &return_value;
  1231. /* set the callback for the GET_QUOTA function */
  1232. mail_parameters(NIL, SET_QUOTA, (void *) mail_getquota);
  1233. if (!imap_getquota(imap_le_struct->imap_stream, qroot)) {
  1234. php_error_docref(NULL TSRMLS_CC, E_WARNING, "c-client imap_getquota failed");
  1235. zval_dtor(return_value);
  1236. RETURN_FALSE;
  1237. }
  1238. }
  1239. /* }}} */
  1240. /* {{{ proto array imap_get_quotaroot(resource stream_id, string mbox)
  1241. Returns the quota set to the mailbox account mbox */
  1242. PHP_FUNCTION(imap_get_quotaroot)
  1243. {
  1244. zval *streamind;
  1245. char *mbox;
  1246. int mbox_len;
  1247. pils *imap_le_struct;
  1248. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &streamind, &mbox, &mbox_len) == FAILURE) {
  1249. return;
  1250. }
  1251. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1252. array_init(return_value);
  1253. IMAPG(quota_return) = &return_value;
  1254. /* set the callback for the GET_QUOTAROOT function */
  1255. mail_parameters(NIL, SET_QUOTA, (void *) mail_getquota);
  1256. if (!imap_getquotaroot(imap_le_struct->imap_stream, mbox)) {
  1257. php_error_docref(NULL TSRMLS_CC, E_WARNING, "c-client imap_getquotaroot failed");
  1258. zval_dtor(return_value);
  1259. RETURN_FALSE;
  1260. }
  1261. }
  1262. /* }}} */
  1263. /* {{{ proto bool imap_set_quota(resource stream_id, string qroot, int mailbox_size)
  1264. Will set the quota for qroot mailbox */
  1265. PHP_FUNCTION(imap_set_quota)
  1266. {
  1267. zval *streamind;
  1268. char *qroot;
  1269. int qroot_len;
  1270. long mailbox_size;
  1271. pils *imap_le_struct;
  1272. STRINGLIST limits;
  1273. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &streamind, &qroot, &qroot_len, &mailbox_size) == FAILURE) {
  1274. return;
  1275. }
  1276. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1277. limits.text.data = "STORAGE";
  1278. limits.text.size = mailbox_size;
  1279. limits.next = NIL;
  1280. RETURN_BOOL(imap_setquota(imap_le_struct->imap_stream, qroot, &limits));
  1281. }
  1282. /* }}} */
  1283. /* {{{ proto bool imap_setacl(resource stream_id, string mailbox, string id, string rights)
  1284. Sets the ACL for a given mailbox */
  1285. PHP_FUNCTION(imap_setacl)
  1286. {
  1287. zval *streamind;
  1288. char *mailbox, *id, *rights;
  1289. int mailbox_len, id_len, rights_len;
  1290. pils *imap_le_struct;
  1291. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &streamind, &mailbox, &mailbox_len, &id, &id_len, &rights, &rights_len) == FAILURE) {
  1292. return;
  1293. }
  1294. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1295. RETURN_BOOL(imap_setacl(imap_le_struct->imap_stream, mailbox, id, rights));
  1296. }
  1297. /* }}} */
  1298. /* {{{ proto array imap_getacl(resource stream_id, string mailbox)
  1299. Gets the ACL for a given mailbox */
  1300. PHP_FUNCTION(imap_getacl)
  1301. {
  1302. zval *streamind;
  1303. char *mailbox;
  1304. int mailbox_len;
  1305. pils *imap_le_struct;
  1306. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &streamind, &mailbox, &mailbox_len) == FAILURE) {
  1307. return;
  1308. }
  1309. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1310. /* initializing the special array for the return values */
  1311. array_init(return_value);
  1312. IMAPG(imap_acl_list) = return_value;
  1313. /* set the callback for the GET_ACL function */
  1314. mail_parameters(NIL, SET_ACL, (void *) mail_getacl);
  1315. if (!imap_getacl(imap_le_struct->imap_stream, mailbox)) {
  1316. php_error(E_WARNING, "c-client imap_getacl failed");
  1317. zval_dtor(return_value);
  1318. RETURN_FALSE;
  1319. }
  1320. IMAPG(imap_acl_list) = NIL;
  1321. }
  1322. /* }}} */
  1323. #endif /* HAVE_IMAP2000 || HAVE_IMAP2001 */
  1324. /* {{{ proto bool imap_expunge(resource stream_id)
  1325. Permanently delete all messages marked for deletion */
  1326. PHP_FUNCTION(imap_expunge)
  1327. {
  1328. zval *streamind;
  1329. pils *imap_le_struct;
  1330. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &streamind) == FAILURE) {
  1331. return;
  1332. }
  1333. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1334. mail_expunge (imap_le_struct->imap_stream);
  1335. RETURN_TRUE;
  1336. }
  1337. /* }}} */
  1338. /* {{{ proto bool imap_gc(resource stream_id, int flags)
  1339. This function garbage collects (purges) the cache of entries of a specific type. */
  1340. PHP_FUNCTION(imap_gc)
  1341. {
  1342. zval *streamind;
  1343. pils *imap_le_struct;
  1344. long flags;
  1345. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &streamind, &flags) == FAILURE) {
  1346. return;
  1347. }
  1348. if (flags && ((flags & ~(GC_TEXTS | GC_ELT | GC_ENV)) != 0)) {
  1349. php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid value for the flags parameter");
  1350. RETURN_FALSE;
  1351. }
  1352. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1353. mail_gc(imap_le_struct->imap_stream, flags);
  1354. RETURN_TRUE;
  1355. }
  1356. /* }}} */
  1357. /* {{{ proto bool imap_close(resource stream_id [, int options])
  1358. Close an IMAP stream */
  1359. PHP_FUNCTION(imap_close)
  1360. {
  1361. zval *streamind;
  1362. pils *imap_le_struct=NULL;
  1363. long options = 0, flags = NIL;
  1364. int argc = ZEND_NUM_ARGS();
  1365. if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &streamind, &options) == FAILURE) {
  1366. return;
  1367. }
  1368. ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
  1369. if (argc == 2) {
  1370. flags = options;
  1371. /* Check that flags is exactly equal to PHP_EXPUNGE or zero */
  1372. if (flags && ((flags & ~PHP_EXPUNGE) != 0)) {
  1373. php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid value for the flags parameter");
  1374. RETURN_FALSE;
  1375. }
  1376. /* Do the translation from PHP's internal PHP_EXPUNGE define to c-client's CL_EXPUNGE */
  1377. if (flags & PHP_EXPUNGE) {
  1378. flags ^= PHP_EXPUNGE;
  1379. flags |= CL_EXPUNGE;
  1380. }
  1381. imap_le_struct->flags = flags;
  1382. }
  1383. zend_list_delete(Z_RESVAL_P(streamind));
  1384. RETURN_TRUE;
  1385. }
  1386. /* }}} */
  1387. /* {{{ proto array imap_headers(resource stream_id)
  1388. Returns headers for all messages in a mailbox */
  1389. PHP_FUNCTION(imap_headers)
  1390. {
  1391. zval *streamind;
  1392. pils *imap_le_struct;
  1393. unsigned long i;
  1394. char *t;
  1395. unsigned int msgno;
  1396. char tmp[MAILTMPLEN];
  1397. if (ze

Large files files are truncated, but you can click here to view the full file