+ /**
+ * function mail - send the message parts to the SMTP stream
+ *
+ * @param Message $message Message object to send
+ * NOTE that this is passed by
+ * reference and will be modified
+ * upon return with updated
+ * fields such as Message ID, References,
+ * In-Reply-To and Date headers.
+ * @param resource $stream Handle to the outgoing stream
+ * (when FALSE, nothing will be
+ * written to the stream; this can
+ * be used to determine the actual
+ * number of bytes that will be
+ * written to the stream)
+ * @param string $reply_id Identifies message being replied to
+ * (OPTIONAL; caller should ONLY specify
+ * a value for this when the message
+ * being sent is a reply)
+ * @param string $reply_ent_id Identifies message being replied to
+ * in the case it was an embedded/attached
+ * 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
+ * if needed.
+ *
+ * @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,
+ $imap_stream=NULL, $extra=NULL) {
+
+ $rfc822_header = &$message->rfc822_header;
+
+ if (count($message->entities)) {
+ $boundary = $this->mimeBoundary();
+ $rfc822_header->content_type->properties['boundary']='"'.$boundary.'"';
+ } else {
+ $boundary='';
+ }
+ $raw_length = 0;
+
+
+ // calculate reply header if needed
+ //
+ if ($reply_id) {
+ global $imapConnection, $username, $imapServerAddress,
+ $imapPort, $mailbox;
+
+ // 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);
+
+ if ($close_imap_stream) {
+ sqimap_logout($my_imap_stream);
+ }
+
+ if ($reply_ent_id) {
+ /* redefine the messsage in case of message/rfc822 */
+ $reply_message = $message->getEntity($reply_ent_id);
+ /* message is an entity which contains the envelope and type0=message
+ * and type1=rfc822. The actual entities are childs from
+ * $reply_message->entities[0]. That's where the encoding and is located
+ */
+
+ $orig_header = $reply_message->rfc822_header; /* here is the envelope located */
+
+ } else {
+ $orig_header = $reply_message->rfc822_header;
+ }
+ $message->reply_rfc822_header = $orig_header;
+ }
+
+
+ $reply_rfc822_header = (isset($message->reply_rfc822_header)
+ ? $message->reply_rfc822_header : '');
+ $header = $this->prepareRFC822_Header($rfc822_header, $reply_rfc822_header, $raw_length);
+
+ $this->send_mail($message, $header, $boundary, $stream, $raw_length, $extra);
+
+ return $raw_length;
+ }
+
+ /**
+ * function send_mail - send the message parts to the IMAP stream
+ *
+ * @param Message $message Message object to send
+ * @param string $header Headers ready to send
+ * @param string $boundary Message parts boundary
+ * @param resource $stream Handle to the SMTP stream
+ * (when FALSE, nothing will be
+ * written to the stream; this can
+ * be used to determine the actual
+ * number of bytes that will be
+ * written to the stream)
+ * @param int &$raw_length The number of bytes written (or that
+ * would have been written) to the
+ * output stream - NOTE that this is
+ * passed by reference
+ * @param mixed $extra Any implementation-specific variables
+ * can be passed in here and used in
+ * an overloaded version of this method
+ * if needed.
+ *
+ * @return void
+ *
+ */
+ function send_mail($message, $header, $boundary, $stream=false,
+ &$raw_length, $extra=NULL) {
+
+
+ if ($stream) {