*/
class Deliver {
+ /**
+ * Most recently calculated Message-ID
+ * External code should NEVER access this directly!
+ * @var string
+ */
+ var $message_id;
+
/**
* function mail - send the message parts to the SMTP stream
*
* an overloaded version of this method
* if needed.
*
- * @return integer $raw_length The number of bytes written (or that would
- * have been written) to the output stream
+ * @return array An array containing at least these elements in this order:
+ * - The number of bytes written (or that would have been
+ * written) to the output stream
+ * - The message ID (WARNING: if $stream is FALSE, this
+ * may not be supplied, or may not be accurate)
+ *
*/
function mail($message, $stream=false, $reply_id=0, $reply_ent_id=0,
$extra=NULL) {
} else {
$orig_header = $reply_message->rfc822_header;
}
+ $message->reply_rfc822_header = $orig_header;
}
- $message->reply_rfc822_header = $orig_header;
$reply_rfc822_header = (isset($message->reply_rfc822_header)
$this->send_mail($message, $header, $boundary, $stream, $raw_length, $extra);
- return $raw_length;
+ return array($raw_length, $this->message_id);
}
/**
global $domain, $username, $encode_header_key,
$edit_identity, $hide_auth_header;
- /* if server var SERVER_NAME not available, use $domain */
- if(!sqGetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER)) {
+ /* if server var SERVER_NAME not available, or contains
+ ":" (e.g. IPv6) which is illegal in a Message-ID, use $domain */
+ if(!sqGetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER) ||
+ strpos($SERVER_NAME,':') !== FALSE) {
$SERVER_NAME = $domain;
}
/* This creates an RFC 822 date */
$date = date('D, j M Y H:i:s ', time()) . $this->timezone();
+
/* Create a message-id */
- $message_id = '<' . $REMOTE_PORT . '.';
- if (isset($encode_header_key) && trim($encode_header_key)!='') {
- // use encrypted form of remote address
- $message_id.= OneTimePadEncrypt($this->ip2hex($REMOTE_ADDR),base64_encode($encode_header_key));
- } else {
- $message_id.= $REMOTE_ADDR;
- }
- $message_id .= '.' . time() . '.squirrel@' . $SERVER_NAME .'>';
+ $message_id = '<';
+ /* user-specifc data to decrease collision chance */
+ $seed_data = $username . '.';
+ $seed_data .= (!empty($REMOTE_PORT) ? $REMOTE_PORT . '.' : '');
+ $seed_data .= (!empty($REMOTE_ADDR) ? $REMOTE_ADDR . '.' : '');
+ /* add the current time in milliseconds and randomness */
+ $seed_data .= uniqid(mt_rand(),true);
+ /* put it through one-way hash and add it to the ID */
+ $message_id .= md5($seed_data) . '.squirrel@' . $SERVER_NAME .'>';
+ $this->message_id = $message_id;
+
/* Make an RFC822 Received: line */
if (isset($REMOTE_HOST)) {
$received_from = "$REMOTE_HOST ([$REMOTE_ADDR])";