From: pdontthink Date: Fri, 25 Apr 2008 21:59:00 +0000 (+0000) Subject: Don't open multiple IMAP connections when building reply headers during send X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=69bb88aa7887eb7259926da61d80b123db2a0524;p=squirrelmail.git Don't open multiple IMAP connections when building reply headers during send git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@13064 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/class/deliver/Deliver.class.php b/class/deliver/Deliver.class.php index ad4e1fd7..504b61f9 100644 --- a/class/deliver/Deliver.class.php +++ b/class/deliver/Deliver.class.php @@ -56,13 +56,24 @@ class Deliver { * can be passed in here and used in * an overloaded version of this method * if needed. + * @param resource $imap_stream If there is an open IMAP stream in + * the caller's context, it should be + * passed in here. This is OPTIONAL, + * as one will be created if not given, + * but as some IMAP servers may baulk + * at opening more than one connection + * at a time, the caller should always + * abide if possible. Currently, this + * stream is only used when $reply_id + * is also non-zero, but that is subject + * to change. * * @return integer The number of bytes written (or that would have been * written) to the output stream. * */ function mail(&$message, $stream=false, $reply_id=0, $reply_ent_id=0, - $extra=NULL) { + $extra=NULL, $imap_stream=NULL) { $rfc822_header = &$message->rfc822_header; @@ -81,12 +92,27 @@ class Deliver { global $imapConnection, $username, $imapServerAddress, $imapPort, $mailbox; - if (!is_resource($imapConnection)) - $imapConnection = sqimap_login($username, FALSE, + // try our best to use an existing IMAP handle + // + $close_imap_stream = FALSE; + if (is_resource($imap_stream)) { + $my_imap_stream = $imap_stream; + + } else if (is_resource($imapConnection)) { + $my_imap_stream = $imapConnection; + + } else { + $close_imap_stream = TRUE; + $my_imap_stream = sqimap_login($username, FALSE, $imapServerAddress, $imapPort, 0); + } + + sqimap_mailbox_select($my_imap_stream, $mailbox); + $reply_message = sqimap_get_message($my_imap_stream, $reply_id, $mailbox); - sqimap_mailbox_select($imapConnection, $mailbox); - $reply_message = sqimap_get_message($imapConnection, $reply_id, $mailbox); + if ($close_imap_stream) { + sqimap_logout($my_imap_stream); + } if ($reply_ent_id) { /* redefine the messsage in case of message/rfc822 */ diff --git a/src/compose.php b/src/compose.php index 917a6d2f..ec6eb201 100644 --- a/src/compose.php +++ b/src/compose.php @@ -1721,7 +1721,7 @@ function deliverMessage(&$composeMessage, $draft=false) { } require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); - $imap_deliver->mail($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $sent_folder); + $imap_deliver->mail($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $sent_folder, $imap_stream); unset ($imap_deliver); }