* message inside another (OPTIONAL; caller
* should ONLY specify a value for this
* when the message being sent is a reply)
+ * @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.
* @param mixed $extra Any implementation-specific variables
* can be passed in here and used in
* an overloaded version of this method
*
*/
function mail(&$message, $stream=false, $reply_id=0, $reply_ent_id=0,
- $extra=NULL) {
+ $imap_stream=NULL, $extra=NULL) {
$rfc822_header = &$message->rfc822_header;
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 */
} else {
if ($mime_header->type0 == 'text' || $mime_header->type0 == 'message') {
$header[] = 'Content-Transfer-Encoding: 8bit' . $rn;
+ } else if ($mime_header->type0 == 'multipart' || $mime_header->type0 == 'alternative') {
+ /* no-op; no encoding needed */
} else {
$header[] = 'Content-Transfer-Encoding: base64' . $rn;
}
} else {
// use default received headers
$header[] = "Received: from $received_from" . $rn;
- if ($edit_identity || ! isset($hide_auth_header) || ! $hide_auth_header)
+ if (!isset($hide_auth_header) || !$hide_auth_header)
$header[] = " (SquirrelMail authenticated user $username)" . $rn;
$header[] = " by $SERVER_NAME with HTTP;" . $rn;
$header[] = " $date" . $rn;