PageRenderTime 278ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/tine20/Tinebase/Mail.php

https://github.com/corneliusweiss/Tine-2.0-Open-Source-Groupware-and-CRM
PHP | 647 lines | 382 code | 81 blank | 184 comment | 80 complexity | c29d97b9507d26a51a01d0c2be9fb576 MD5 | raw file
  1. <?php
  2. /**
  3. * Tine 2.0
  4. *
  5. * @package Tinebase
  6. * @subpackage Mail
  7. * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
  8. * @copyright Copyright (c) 2008-2014 Metaways Infosystems GmbH (http://www.metaways.de)
  9. * @author Lars Kneschke <l.kneschke@metaways.de>
  10. */
  11. /**
  12. * This class extends the Zend_Mail class
  13. *
  14. * @package Tinebase
  15. * @subpackage Mail
  16. */
  17. class Tinebase_Mail extends Zend_Mail
  18. {
  19. /**
  20. * email address regexp
  21. */
  22. const EMAIL_ADDRESS_REGEXP = '/^([a-z0-9_\+-\.]+@[a-z0-9-\.]+\.[a-z]{2,63})$/i';
  23. /**
  24. * email address regexp (which might be contained in a longer text)
  25. */
  26. const EMAIL_ADDRESS_CONTAINED_REGEXP = '/([a-z0-9_\+-\.]+@[a-z0-9-\.]+\.[a-z]{2,63})/i';
  27. /**
  28. * Sender: address
  29. * @var string
  30. */
  31. protected $_sender = null;
  32. /**
  33. * fallback charset constant
  34. *
  35. * @var string
  36. */
  37. const DEFAULT_FALLBACK_CHARSET = 'iso-8859-15';
  38. /**
  39. * create Tinebase_Mail from Zend_Mail_Message
  40. *
  41. * @param Zend_Mail_Message $_zmm
  42. * @param string $_replyBody
  43. * @return Tinebase_Mail
  44. */
  45. public static function createFromZMM(Zend_Mail_Message $_zmm, $_replyBody = null)
  46. {
  47. $contentStream = fopen("php://temp", 'r+');
  48. fputs($contentStream, $_zmm->getContent());
  49. rewind($contentStream);
  50. $mp = new Zend_Mime_Part($contentStream);
  51. self::_getMetaDataFromZMM($_zmm, $mp);
  52. // append old body when no multipart/mixed
  53. if ($_replyBody !== null && $_zmm->headerExists('content-transfer-encoding')) {
  54. $mp = self::_appendReplyBody($mp, $_replyBody);
  55. } else {
  56. $mp->decodeContent();
  57. if ($_zmm->headerExists('content-transfer-encoding')) {
  58. switch ($_zmm->getHeader('content-transfer-encoding')) {
  59. case Zend_Mime::ENCODING_BASE64:
  60. // BASE64 encode has a bug that swallows the last char(s)
  61. $bodyEncoding = Zend_Mime::ENCODING_7BIT;
  62. break;
  63. default:
  64. $bodyEncoding = $_zmm->getHeader('content-transfer-encoding');
  65. }
  66. } else {
  67. $bodyEncoding = Zend_Mime::ENCODING_7BIT;
  68. }
  69. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
  70. . ' Using encoding: ' . $bodyEncoding);
  71. $mp->encoding = $bodyEncoding;
  72. }
  73. $result = new Tinebase_Mail('utf-8');
  74. $result->setBodyText($mp);
  75. $result->setHeadersFromZMM($_zmm);
  76. return $result;
  77. }
  78. /**
  79. * get meta data (like contentype, charset, ...) from zmm and set it in zmp
  80. *
  81. * @param Zend_Mail_Message $zmm
  82. * @param Zend_Mime_Part $zmp
  83. */
  84. protected static function _getMetaDataFromZMM(Zend_Mail_Message $zmm, Zend_Mime_Part $zmp)
  85. {
  86. if ($zmm->headerExists('content-transfer-encoding')) {
  87. $zmp->encoding = $zmm->getHeader('content-transfer-encoding');
  88. } else {
  89. $zmp->encoding = Zend_Mime::ENCODING_7BIT;
  90. }
  91. if ($zmm->headerExists('content-type')) {
  92. $contentTypeHeader = Zend_Mime_Decode::splitHeaderField($zmm->getHeader('content-type'));
  93. $zmp->type = $contentTypeHeader[0];
  94. if (isset($contentTypeHeader['boundary'])) {
  95. $zmp->boundary = $contentTypeHeader['boundary'];
  96. }
  97. if (isset($contentTypeHeader['charset'])) {
  98. $zmp->charset = $contentTypeHeader['charset'];
  99. }
  100. } else {
  101. $zmp->type = Zend_Mime::TYPE_TEXT;
  102. }
  103. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
  104. . ' Encoding: ' . $zmp->encoding . ' / type: ' . $zmp->type . ' / charset: ' . $zmp->charset);
  105. }
  106. /**
  107. * appends old body to mime part
  108. *
  109. * @param Zend_Mime_Part $mp
  110. * @param string $replyBody plain/text reply body
  111. * @return Zend_Mime_Part
  112. */
  113. protected static function _appendReplyBody(Zend_Mime_Part $mp, $replyBody)
  114. {
  115. $decodedContent = Tinebase_Mail::getDecodedContent($mp, NULL, FALSE);
  116. $type = $mp->type;
  117. if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
  118. Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " mp content: " . $decodedContent);
  119. Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " reply body: " . $replyBody);
  120. }
  121. if ($type === Zend_Mime::TYPE_HTML && /* checks if $replyBody does not contains tags */ $replyBody === strip_tags($replyBody)) {
  122. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
  123. . " Converting plain/text reply body to HTML");
  124. $replyBody = self::convertFromTextToHTML($replyBody);
  125. }
  126. if ($type === Zend_Mime::TYPE_HTML && preg_match('/(<\/body>[\s\r\n]*<\/html>)/i', $decodedContent, $matches)) {
  127. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
  128. . ' Appending reply body to html body.');
  129. $decodedContent = str_replace($matches[1], $replyBody . $matches[1], $decodedContent);
  130. } else {
  131. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
  132. . " Appending reply body to mime text part.");
  133. $decodedContent .= $replyBody;
  134. }
  135. $mp = new Zend_Mime_Part($decodedContent);
  136. $mp->charset = 'utf-8';
  137. $mp->type = $type;
  138. return $mp;
  139. }
  140. /**
  141. * Sets the HTML body for the message
  142. *
  143. * @param string|Zend_Mime_Part $html
  144. * @param string $charset
  145. * @param string $encoding
  146. * @return Zend_Mail Provides fluent interface
  147. */
  148. public function setBodyHtml($html, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE)
  149. {
  150. if ($html instanceof Zend_Mime_Part) {
  151. $mp = $html;
  152. } else {
  153. if ($charset === null) {
  154. $charset = $this->_charset;
  155. }
  156. $mp = new Zend_Mime_Part($html);
  157. $mp->encoding = $encoding;
  158. $mp->type = Zend_Mime::TYPE_HTML;
  159. $mp->disposition = Zend_Mime::DISPOSITION_INLINE;
  160. $mp->charset = $charset;
  161. }
  162. $this->_bodyHtml = $mp;
  163. return $this;
  164. }
  165. /**
  166. * Sets the text body for the message.
  167. *
  168. * @param string|Zend_Mime_Part $txt
  169. * @param string $charset
  170. * @param string $encoding
  171. * @return Zend_Mail Provides fluent interface
  172. */
  173. public function setBodyText($txt, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE)
  174. {
  175. if ($txt instanceof Zend_Mime_Part) {
  176. $mp = $txt;
  177. } else {
  178. if ($charset === null) {
  179. $charset = $this->_charset;
  180. }
  181. $mp = new Zend_Mime_Part($txt);
  182. $mp->encoding = $encoding;
  183. $mp->type = Zend_Mime::TYPE_TEXT;
  184. $mp->disposition = Zend_Mime::DISPOSITION_INLINE;
  185. $mp->charset = $charset;
  186. }
  187. $this->_bodyText = $mp;
  188. return $this;
  189. }
  190. public function setBodyPGPMime($amored)
  191. {
  192. $this->_type = 'multipart/encrypted; protocol="application/pgp-encrypted"';
  193. // PGP/MIME Versions Identification
  194. $pgpIdent = new Zend_Mime_Part('Version: 1');
  195. $pgpIdent->encoding = '7bit';
  196. $pgpIdent->type = 'application/pgp-encrypted';
  197. $pgpIdent->description = 'PGP/MIME Versions Identification';
  198. $this->_bodyText = $pgpIdent;
  199. // OpenPGP encrypted message
  200. $pgpMessage = new Zend_Mime_Part($amored);
  201. $pgpMessage->encoding = '7bit';
  202. $pgpMessage->disposition = 'inline; filename=encrypted.asc';
  203. $pgpMessage->type = 'application/octet-stream; name=encrypted.asc';
  204. $pgpMessage->description = 'OpenPGP encrypted message';
  205. $this->_bodyHtml = $pgpMessage;
  206. }
  207. /**
  208. * set headers
  209. *
  210. * @param Zend_Mail_Message $_zmm
  211. * @return Zend_Mail Provides fluent interface
  212. */
  213. public function setHeadersFromZMM(Zend_Mail_Message $_zmm)
  214. {
  215. foreach ($_zmm->getHeaders() as $header => $values) {
  216. foreach ((array)$values as $value) {
  217. switch ($header) {
  218. case 'content-transfer-encoding':
  219. // these are implicitly set by Zend_Mail_Transport_Abstract::_getHeaders()
  220. case 'content-type':
  221. case 'mime-version':
  222. // do nothing
  223. break;
  224. case 'bcc':
  225. $addresses = self::parseAdresslist($value);
  226. foreach ($addresses as $address) {
  227. $this->addBcc($address['address'], $address['name']);
  228. }
  229. break;
  230. case 'cc':
  231. $addresses = self::parseAdresslist($value);
  232. foreach ($addresses as $address) {
  233. $this->addCc($address['address'], $address['name']);
  234. }
  235. break;
  236. case 'date':
  237. try {
  238. $this->setDate($value);
  239. } catch (Zend_Mail_Exception $zme) {
  240. if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE))
  241. Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Could not set date: " . $value);
  242. if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE))
  243. Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " " . $zme);
  244. $this->setDate();
  245. }
  246. break;
  247. case 'from':
  248. $addresses = self::parseAdresslist($value);
  249. foreach ($addresses as $address) {
  250. $this->setFrom($address['address'], $address['name']);
  251. }
  252. break;
  253. case 'message-id':
  254. $this->setMessageId(trim($value,"<>"));
  255. break;
  256. case 'return-path':
  257. $this->setReturnPath($value);
  258. break;
  259. case 'subject':
  260. $this->setSubject($value);
  261. break;
  262. case 'to':
  263. $addresses = self::parseAdresslist($value);
  264. foreach ($addresses as $address) {
  265. $this->addTo($address['address'], $address['name']);
  266. }
  267. break;
  268. case 'reply-to':
  269. $this->setReplyTo($value);
  270. break;
  271. default:
  272. $this->addHeader($header, $value);
  273. break;
  274. }
  275. }
  276. }
  277. return $this;
  278. }
  279. /**
  280. * Sets Sender-header and sender of the message
  281. *
  282. * @param string $email
  283. * @param string $name
  284. * @return Zend_Mail Provides fluent interface
  285. * @throws Zend_Mail_Exception if called subsequent times
  286. */
  287. public function setSender($email, $name = '')
  288. {
  289. if ($this->_sender === null) {
  290. $email = strtr($email,"\r\n\t",'???');
  291. $this->_from = $email;
  292. $this->_storeHeader('Sender', $this->_encodeHeader('"'.$name.'"').' <'.$email.'>', true);
  293. } else {
  294. throw new Zend_Mail_Exception('Sender Header set twice');
  295. }
  296. return $this;
  297. }
  298. /**
  299. * Formats e-mail address
  300. *
  301. * NOTE: we always add quotes to the name as this caused problems when name is encoded
  302. * @see Zend_Mail::_formatAddress
  303. *
  304. * @param string $email
  305. * @param string $name
  306. * @return string
  307. */
  308. protected function _formatAddress($email, $name)
  309. {
  310. if ($name === '' || $name === null || $name === $email) {
  311. return $email;
  312. } else {
  313. $encodedName = $this->_encodeHeader($name);
  314. $format = '"%s" <%s>';
  315. return sprintf($format, $encodedName, $email);
  316. }
  317. }
  318. /**
  319. * check if Zend_Mail_Message is/contains calendar iMIP message
  320. *
  321. * @param Zend_Mail_Message $zmm
  322. * @return boolean
  323. */
  324. public static function isiMIPMail(Zend_Mail_Message $zmm)
  325. {
  326. foreach ($zmm as $part) {
  327. if (preg_match('/text\/calendar/', $part->contentType)) {
  328. return TRUE;
  329. }
  330. }
  331. return FALSE;
  332. }
  333. /**
  334. * get decoded body content
  335. *
  336. * @param Zend_Mime_Part $zmp
  337. * @param array $partStructure
  338. * @param boolean $appendCharsetFilter
  339. * @return string
  340. */
  341. public static function getDecodedContent(Zend_Mime_Part $zmp, $_partStructure = NULL, $appendCharsetFilter = TRUE)
  342. {
  343. $charset = self::_getCharset($zmp, $_partStructure);
  344. if ($appendCharsetFilter) {
  345. $charset = self::_appendCharsetFilter($zmp, $charset);
  346. }
  347. $encoding = (is_array($_partStructure) && ! empty($_partStructure['encoding']))
  348. ? $_partStructure['encoding']
  349. : $zmp->encoding;
  350. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
  351. . " Trying to decode mime part content. Encoding/charset: " . $encoding . ' / ' . $charset);
  352. // need to set error handler because stream_get_contents just throws a E_WARNING
  353. set_error_handler('Tinebase_Mail::decodingErrorHandler', E_WARNING);
  354. try {
  355. $body = $zmp->getDecodedContent();
  356. restore_error_handler();
  357. } catch (Tinebase_Exception $e) {
  358. if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
  359. . " Decoding of " . $zmp->encoding . '/' . $encoding . ' encoded message failed: ' . $e->getMessage());
  360. // trying to fix decoding problems
  361. restore_error_handler();
  362. $zmp->resetStream();
  363. if (preg_match('/convert\.quoted-printable-decode/', $e->getMessage())) {
  364. if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Trying workaround for http://bugs.php.net/50363.');
  365. $body = quoted_printable_decode(stream_get_contents($zmp->getRawStream()));
  366. $body = iconv($charset, 'utf-8', $body);
  367. } else {
  368. if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Try again with fallback encoding.');
  369. $zmp->appendDecodeFilter(self::_getDecodeFilter());
  370. set_error_handler('Tinebase_Mail::decodingErrorHandler', E_WARNING);
  371. try {
  372. $body = $zmp->getDecodedContent();
  373. restore_error_handler();
  374. } catch (Tinebase_Exception $e) {
  375. restore_error_handler();
  376. if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Fallback encoding failed. Trying base64_decode().');
  377. $zmp->resetStream();
  378. $body = base64_decode(stream_get_contents($zmp->getRawStream()));
  379. $body = iconv($charset, 'utf-8', $body);
  380. }
  381. }
  382. }
  383. return $body;
  384. }
  385. /**
  386. * convert charset (and return charset)
  387. *
  388. * @param Zend_Mime_Part $_part
  389. * @param array $_structure
  390. * @return string
  391. */
  392. protected static function _getCharset(Zend_Mime_Part $_part, $_structure = NULL)
  393. {
  394. return ($_structure && isset($_structure['parameters']['charset']))
  395. ? $_structure['parameters']['charset']
  396. : ($_part->charset ? $_part->charset : self::DEFAULT_FALLBACK_CHARSET);
  397. }
  398. /**
  399. * convert charset (and return charset)
  400. *
  401. * @param Zend_Mime_Part $_part
  402. * @param string $charset
  403. * @return string
  404. */
  405. protected static function _appendCharsetFilter(Zend_Mime_Part $_part, $charset)
  406. {
  407. if ($charset == 'utf8') {
  408. $charset = 'utf-8';
  409. } else if ($charset == 'us-ascii') {
  410. // us-ascii caused problems with iconv encoding to utf-8
  411. $charset = self::DEFAULT_FALLBACK_CHARSET;
  412. } else if (strpos($charset, '.') !== false) {
  413. // the stream filter does not like charsets with a dot in its name
  414. // stream_filter_append(): unable to create or locate filter "convert.iconv.ansi_x3.4-1968/utf-8//IGNORE"
  415. $charset = self::DEFAULT_FALLBACK_CHARSET;
  416. } else if (iconv($charset, 'utf-8', '') === false) {
  417. // check if charset is supported by iconv
  418. $charset = self::DEFAULT_FALLBACK_CHARSET;
  419. }
  420. $_part->appendDecodeFilter(self::_getDecodeFilter($charset));
  421. return $charset;
  422. }
  423. /**
  424. * get decode filter for stream_filter_append
  425. *
  426. * @param string $_charset
  427. * @return string
  428. */
  429. protected static function _getDecodeFilter($_charset = self::DEFAULT_FALLBACK_CHARSET)
  430. {
  431. if (in_array(strtolower($_charset), array('iso-8859-1', 'windows-1252', 'iso-8859-15')) && extension_loaded('mbstring')) {
  432. require_once 'StreamFilter/ConvertMbstring.php';
  433. $filter = 'convert.mbstring';
  434. } else {
  435. $filter = "convert.iconv.$_charset/utf-8//IGNORE";
  436. }
  437. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Appending decode filter: ' . $filter);
  438. return $filter;
  439. }
  440. /**
  441. * error exception handler for iconv decoding errors / only gets E_WARNINGs
  442. *
  443. * NOTE: PHP < 5.3 don't throws exceptions for Catchable fatal errors per default,
  444. * so we convert them into exceptions manually
  445. *
  446. * @param integer $severity
  447. * @param string $errstr
  448. * @param string $errfile
  449. * @param integer $errline
  450. * @throws Tinebase_Exception
  451. *
  452. * @todo maybe we can remove that because php 5.3+ is required now
  453. */
  454. public static function decodingErrorHandler($severity, $errstr, $errfile, $errline)
  455. {
  456. Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " $errstr in {$errfile}::{$errline} ($severity)");
  457. throw new Tinebase_Exception($errstr);
  458. }
  459. /**
  460. * parse address list
  461. *
  462. * @param string $_adressList
  463. * @return array
  464. */
  465. public static function parseAdresslist($_addressList)
  466. {
  467. if (strpos($_addressList, ',') !== FALSE && substr_count($_addressList, '@') == 1) {
  468. // we have a comma in the name -> do not split string!
  469. $addresses = array($_addressList);
  470. } else {
  471. // create stream to be used with fgetcsv
  472. $stream = fopen("php://temp", 'r+');
  473. fputs($stream, $_addressList);
  474. rewind($stream);
  475. // alternative solution to create stream; yet untested
  476. #$stream = fopen('data://text/plain;base64,' . base64_encode($_addressList), 'r');
  477. // split addresses
  478. $addresses = fgetcsv($stream);
  479. }
  480. if (! is_array($addresses)) {
  481. if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ .
  482. ' Could not parse addresses: ' . var_export($addresses, TRUE));
  483. return array();
  484. }
  485. foreach ($addresses as $key => $address) {
  486. if (preg_match('/(.*)<(.+@[^@]+)>/', $address, $matches)) {
  487. $name = trim(trim($matches[1]), '"');
  488. $address = trim($matches[2]);
  489. $addresses[$key] = array('name' => substr($name, 0, 250), 'address' => $address);
  490. } else {
  491. $address = preg_replace('/[,;]*/i', '', $address);
  492. $addresses[$key] = array('name' => null, 'address' => trim($address));
  493. }
  494. }
  495. return $addresses;
  496. }
  497. /**
  498. * convert text to html
  499. * - replace quotes ('> ') with blockquotes
  500. * - does htmlspecialchars()
  501. * - converts linebreaks to <br />
  502. *
  503. * @param string $text
  504. * @param string $blockquoteClass
  505. * @return string
  506. */
  507. public static function convertFromTextToHTML($text, $blockquoteClass = null)
  508. {
  509. if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Input: ' . $text);
  510. $lines = preg_split('/\r\n|\n|\r/', $text);
  511. $result = array();
  512. $indention = 0;
  513. foreach ($lines as $line) {
  514. // get indention level and remove quotes
  515. if (preg_match('/^>[> ]*/', $line, $matches)) {
  516. $indentionLevel = substr_count($matches[0], '>');
  517. $line = str_replace($matches[0], '', $line);
  518. } else {
  519. $indentionLevel = 0;
  520. }
  521. // convert html special chars
  522. $line = htmlspecialchars($line, ENT_COMPAT, 'UTF-8');
  523. // set blockquote tags for current indentionLevel
  524. while ($indention < $indentionLevel) {
  525. $class = $blockquoteClass ? 'class="' . $blockquoteClass . '"' : '';
  526. $line = '<blockquote ' . $class . '>' . $line;
  527. $indention++;
  528. }
  529. while ($indention > $indentionLevel) {
  530. $line = '</blockquote>' . $line;
  531. $indention--;
  532. }
  533. $result[] = $line;
  534. if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Line: ' . $line);
  535. }
  536. $result = implode('<br />', $result);
  537. if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Result: ' . $result);
  538. return $result;
  539. }
  540. /**
  541. * get imap/smtp connection options
  542. *
  543. * do we verify imap/smtp peers?
  544. *
  545. * @param integer $timeout connection timeout
  546. * @return array
  547. *
  548. * TODO use separate configs for imap/smtp/sieve...
  549. */
  550. public static function getConnectionOptions($timeout = 30)
  551. {
  552. $connectionOptions = array(
  553. 'timeout' => $timeout,
  554. );
  555. $tinebaseImapConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::IMAP);
  556. if (isset($tinebaseImapConfig->verifyPeer) && $tinebaseImapConfig->verifyPeer == false) {
  557. $connectionOptions['context'] = array(
  558. 'ssl' => array(
  559. 'verify_peer' => false,
  560. 'verify_peer_name' => false
  561. ),
  562. );
  563. }
  564. return $connectionOptions;
  565. }
  566. }