sqgetGlobalVar('key', $key, SQ_COOKIE); sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); sqgetGlobalVar('passed_id', $passed_id, SQ_GET); sqgetGlobalVar('mailbox', $mailbox, SQ_GET); sqgetGlobalVar('ent_id', $ent_id, SQ_GET); sqgetGlobalVar('startMessage', $startMessage, SQ_GET); /* end globals */ $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); displayPageHeader($color, 'None'); echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' . 'align="center">' . "\n" . '<tr><td bgcolor="' . $color[0] . '">' . '<b><center>' . _("Viewing a Business Card") . " - "; $msg_url = 'read_body.php?mailbox=' . urlencode($mailbox) . '&startMessage=' . urlencode($startMessage) . '&passed_id=' . urlencode($passed_id); $msg_url = set_url_var($msg_url, 'ent_id', 0); echo '<a href="' . $msg_url . '">' . _("View message") . '</a>'; echo '</center></b></td></tr>'; $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $entity_vcard = getEntity($message, $ent_id); $vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id); $vcard = decodeBody($vcard, $entity_vcard->header->encoding); $vcard = explode("\n", $vcard); foreach ($vcard as $l) { $k = substr($l, 0, strpos($l, ':')); $v = substr($l, strpos($l, ':') + 1); $attributes = explode(';', $k); $k = strtolower(array_shift($attributes)); foreach ($attributes as $attr) { if ($attr == 'quoted-printable') { $v = quoted_printable_decode($v); } else { $k .= ';' . strtolower($attr); }
$composesession = $session; sqsession_register($composesession, 'composesession'); if (!isset($compose_messages)) { $compose_messages = array(); } if (!isset($compose_messages[$session]) || $compose_messages[$session] == NULL) { $composeMessage = new Message(); $rfc822_header = new Rfc822Header(); $composeMessage->rfc822_header = $rfc822_header; $composeMessage->reply_rfc822_header = ''; $compose_messages[$session] = $composeMessage; sqsession_register($compose_messages, 'compose_messages'); } else { $composeMessage = $compose_messages[$session]; } $message = sqimap_get_message($imap_stream, $passed_id, $mailbox); $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imap_stream); $compose_messages[$session] = $composeMessage; sqsession_register($compose_messages, 'compose_messages'); $fn = getPref($data_dir, $username, 'full_name'); $em = getPref($data_dir, $username, 'email_address'); $HowItLooks = $fn . ' '; if ($em != '') { $HowItLooks .= '<' . $em . '>'; } } echo "<p>"; echo _("Sending this spam report will give you back a reply with URLs that you can click on to properly report this spam message to the proper authorities. This is a free service. By pressing the \"Send Spam Report\" button, you agree to follow SpamCop's rules/terms of service/etc."); echo "</p>"; ?>
function attachSelectedMessages($msg, $imapConnection) { global $username, $attachment_dir, $startMessage, $data_dir, $composesession, $uid_support, $mailbox, $msgs, $thread_sort_messages, $allow_server_sort, $show_num, $compose_messages; if (!isset($compose_messages)) { $compose_messages = array(); sqsession_register($compose_messages, 'compose_messages'); } if (!$composesession) { $composesession = 1; sqsession_register($composesession, 'composesession'); } else { $composesession++; sqsession_register($composesession, 'composesession'); } $hashed_attachment_dir = getHashedDir($username, $attachment_dir, $composesession); if ($thread_sort_messages || $allow_server_sort) { $start_index = 0; } else { $start_index = ($startMessage - 1) * $show_num; } $i = 0; $j = 0; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); $composeMessage = new Message(); $rfc822_header = new Rfc822Header(); $composeMessage->rfc822_header = $rfc822_header; $composeMessage->reply_rfc822_header = ''; while ($j < count($msg)) { if (isset($msg[$i])) { $id = $msg[$i]; $body_a = sqimap_run_command($imapConnection, "FETCH {$id} RFC822", true, $response, $readmessage, $uid_support); if ($response == 'OK') { $message = sqimap_get_message($imapConnection, $id, $mailbox); // fetch the subject for the message from the object $filename = $message->rfc822_header->subject; if (empty($filename)) { $filename = "untitled-" . $message->entity_id; } $filename .= '.msg'; $filename = decodeHeader($filename, false, false); array_shift($body_a); array_pop($body_a); $body = implode('', $body_a); $body .= "\r\n"; $localfilename = GenerateRandomString(32, 'FILE', 7); $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}"; while (file_exists($full_localfilename)) { $localfilename = GenerateRandomString(32, 'FILE', 7); $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}"; } $fp = fopen($full_localfilename, 'wb'); fwrite($fp, $body); fclose($fp); $composeMessage->initAttachment('message/rfc822', $filename, $localfilename); } $j++; } $i++; } $compose_messages[$composesession] = $composeMessage; sqsession_register($compose_messages, 'compose_messages'); session_write_close(); return $composesession; }
function newMail($mailbox = '', $passed_id = '', $passed_ent_id = '', $action = '', $session = '') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $composesession, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $compose_messages, $composeMessage, $body_quote; global $languages, $squirrelmail_language, $default_charset; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; } $encoding = $message->header->encoding; $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $msg = $message->getEntity($ent); $type0 = $msg->type0; $type1 = $msg->type1; $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/<\\/?p>/i', '/<div><\\/div>/i', '/<br\\s*(\\/)*>/i', '/<\\/?div>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ', '>', '<'), array(' ', '>', '<'), $bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart); } } if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ($actual && is_conversion_safe($actual) && $actual != $default_charset) { $bodypart = charset_convert($actual, $bodypart, $default_charset, false); } $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority, 0, 1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } //ClearAttachments($session); $identity = ''; $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach ($idents as $nr => $data) { $enc_from_name = '"' . $data['full_name'] . '" <' . $data['email_address'] . '>'; if ($enc_from_name == $orig_from) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } switch ($action) { case 'draft': $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $send_from = $orig_header->getAddr_s('from'); $send_from_parts = new AddressStructure(); $send_from_parts = $orig_header->parseAddress($send_from); $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host; $identities = get_identities(); if (count($identities) > 0) { foreach ($identities as $iddata) { if ($send_from_add == $iddata['email_address']) { $identity = $iddata['index']; break; } } } $subject = decodeHeader($orig_header->subject, false, false, true); /* remember the references and in-reply-to headers in case of an reply */ $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case 'edit_as_new': $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); break; case 'forward': $send_to = ''; $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true)); $body = getforwardHeader($orig_header) . $body; // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines // forwarded message text should be as undisturbed as possible, so commenting out this call // sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); //add a blank line after the forward headers $body = "\n" . $body; break; case 'forward_as_attachment': $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true)); $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $body = ''; break; case 'reply_all': if (isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc, false, false, true); } case 'reply': // skip this if send_to was already set right above here if (!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to'); } else { if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to'); } else { $send_to = $orig_header->getAddr_s('from'); } } } $send_to = decodeHeader($send_to, false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = is_array($orig_header->from) ? $orig_header->from[0] : $orig_header->from; $body = ''; $strip_sigs = getPref($data_dir, $username, 'strip_sigs'); foreach ($rewrap_body as $line) { if ($strip_sigs && substr($line, 0, 3) == '-- ') { break; } if (preg_match("/^(>+)/", $line, $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n{$body_quote}{$gt} ", rtrim($line)) . "\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n{$body_quote}" . (!empty($body_quote) ? ' ' : ''), rtrim($line)) . "\n"; } } //rewrap the body to clean up quotations and line lengths $body = sqBodyWrap($body, $editor_size); $body = getReplyCitation($from, $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } $compose_messages[$session] = $composeMessage; sqsession_register($compose_messages, 'compose_messages'); session_write_close(); sqimap_logout($imapConnection); } $ret = array('send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity); return $ret; }
function newMail($mailbox = '', $passed_id = '', $passed_ent_id = '', $action = '', $session = '') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $data_dir, $username, $key, $imapServerAddress, $imapPort, $imap_stream_options, $composeMessage, $body_quote, $request_mdn, $request_dr, $mdn_user_support, $languages, $squirrelmail_language, $default_charset, $do_not_reply_to_self; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain', 'text/html')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain', 'text/html')); } $orig_header = $message->rfc822_header; } $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $msg = $message->getEntity($ent); $type0 = $msg->type0; $type1 = $msg->type1; $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/<\\/?p>/i', '/<div><\\/div>/i', '/<br\\s*(\\/)*>/i', '/<\\/?div>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ', '>', '<'), array(' ', '>', '<'), $bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart); } } // charset encoding in compose form stuff if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ($actual && is_conversion_safe($actual) && $actual != $default_charset) { $bodypart = charset_convert($actual, $bodypart, $default_charset, false); } // end of charset encoding in compose $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority, 0, 1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach ($idents as $nr => $data) { $enc_from_name = '"' . $data['full_name'] . '" <' . $data['email_address'] . '>'; $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match !== FALSE) { $identity = $identity_match; } } switch ($action) { case 'draft': $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $send_from = $orig_header->getAddr_s('from'); $send_from_parts = new AddressStructure(); $send_from_parts = $orig_header->parseAddress($send_from); $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host; $identity = find_identity(array($send_from_add)); $subject = decodeHeader($orig_header->subject, false, false, true); // Remember the receipt settings $request_mdn = $mdn_user_support && !empty($orig_header->dnt) ? '1' : '0'; $request_dr = $mdn_user_support && !empty($orig_header->drnt) ? '1' : '0'; /* remember the references and in-reply-to headers in case of an reply */ //FIXME: it would be better to fiddle with headers inside of the message object or possibly when delivering the message to its destination (drafts folder?); is this possible? $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case 'edit_as_new': $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); break; case 'forward': $send_to = ''; $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true)); $body = getforwardHeader($orig_header) . $body; // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines // forwarded message text should be as undisturbed as possible, so commenting out this call // sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); //add a blank line after the forward headers $body = "\n" . $body; break; case 'forward_as_attachment': $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true)); $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $subject = decodeHeader($orig_header->subject, false, false, true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 4) != 'fwd:') { $subject = 'Fwd: ' . $subject; } $body = ''; break; case 'reply_all': if (isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc, false, false, true); $send_to_cc = str_replace('""', '"', $send_to_cc); } case 'reply': // skip this if send_to was already set right above here if (!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to', ',', FALSE, TRUE); } else { if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to', ',', FALSE, TRUE); } else { $send_to = $orig_header->getAddr_s('from', ',', FALSE, TRUE); } } } $send_to = decodeHeader($send_to, false, false, true); $send_to = str_replace('""', '"', $send_to); // If user doesn't want replies to her own messages // going back to herself (instead send again to the // original recipient of the message being replied to), // then iterate through identities, checking if the TO // field is one of them (if the reply is to ourselves) // // Note we don't bother if the original message doesn't // have anything in the TO field itself (because that's // what we use if we change the recipient to be that of // the previous message) // if ($do_not_reply_to_self && !empty($orig_header->to)) { $orig_to = ''; foreach ($idents as $id) { if (!empty($id['email_address']) && strpos($send_to, $id['email_address']) !== FALSE) { // if this is a reply-all, the original recipient // is already in the CC field, so we can just blank // the recipient (TO field) (as long as the CC field // isn't empty that is)... but then move the CC into // the TO, so TO isn't empty // if ($action == 'reply_all' && !empty($send_to_cc)) { $orig_to = $send_to_cc; $send_to_cc = ''; break; } $orig_to = $orig_header->to; if (is_array($orig_to) && count($orig_to)) { $orig_to = $orig_header->getAddr_s('to', ',', FALSE, TRUE); } else { if (is_object($orig_to)) { /* unneccesarry, just for failsafe purpose */ $orig_to = $orig_header->getAddr_s('to', ',', FALSE, TRUE); } else { $orig_to = ''; } } $orig_to = decodeHeader($orig_to, false, false, true); $orig_to = str_replace('""', '"', $orig_to); break; } } // if the reply was addressed back to ourselves, // we will send it to the TO of the previous message // if (!empty($orig_to)) { $send_to = $orig_to; // in this case, we also want to reset the FROM // identity as well (it should match the original // *FROM* header instead of TO or CC) // if (count($idents) > 1) { $identity = ''; foreach ($idents as $i => $id) { if (!empty($id['email_address']) && strpos($orig_from, $id['email_address']) !== FALSE) { $identity = $i; break; } } } } } $subject = decodeHeader($orig_header->subject, false, false, true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = is_array($orig_header->from) && !empty($orig_header->from) ? $orig_header->from[0] : $orig_header->from; $body = ''; $strip_sigs = getPref($data_dir, $username, 'strip_sigs'); foreach ($rewrap_body as $line) { if ($strip_sigs && rtrim($line, "\r\n") == '-- ') { break; } if (preg_match("/^(>+)/", $line, $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n{$body_quote}{$gt} ", rtrim($line)) . "\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n{$body_quote}" . (!empty($body_quote) ? ' ' : ''), rtrim($line)) . "\n"; } } //rewrap the body to clean up quotations and line lengths $body = sqBodyWrap($body, $editor_size); $body = getReplyCitation($from, $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } //FIXME: we used to register $compose_messages in the session here, but not any more - so do we still need the session_write_close() and sqimap_logout() here? We probably need the IMAP logout, but what about the session closure? session_write_close(); sqimap_logout($imapConnection); } $ret = array('send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity); return $ret; }
function newMail($mailbox = '', $passed_id = '', $passed_ent_id = '', $action = '', $session = '') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $composesession, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $compose_messages, $composeMessage, $body_quote; global $languages, $squirrelmail_language, $default_charset; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; } $encoding = $message->header->encoding; $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/<p>/i', '/<br\\s*(\\/)*>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ', '>', '<'), array(' ', '>', '<'), $bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart); } } // charset encoding in compose form stuff if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ($actual && is_conversion_safe($actual) && $actual != $default_charset) { $bodypart = charset_convert($actual, $bodypart, $default_charset, false); } // end of charset encoding in compose $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority, 0, 1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } $identity = ''; $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach ($idents as $nr => $data) { $enc_from_name = '"' . $data['full_name'] . '" <' . $data['email_address'] . '>'; if ($enc_from_name == $orig_from) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } switch ($action) { case 'draft': $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); // FIXME: ident support? $subject = decodeHeader($orig_header->subject, false, false, true); /* remember the references and in-reply-to headers in case of an reply */ $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; $body_ary = explode("\n", $body); $cnt = count($body_ary); $body = ''; for ($i = 0; $i < $cnt; $i++) { if (!ereg("^[>\\s]*\$", $body_ary[$i]) || !$body_ary[$i]) { sqWordWrap($body_ary[$i], $editor_size, $default_charset); $body .= $body_ary[$i] . "\n"; } unset($body_ary[$i]); } sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case 'edit_as_new': $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); sqUnWordWrap($body); break; case 'forward': $send_to = ''; $subject = decodeHeader($orig_header->subject, false, false, true); if (substr(strtolower($subject), 0, 4) != 'fwd:' && substr(strtolower($subject), 0, 5) != '[fwd:' && substr(strtolower($subject), 0, 6) != '[ fwd:') { $subject = '[Fwd: ' . $subject . ']'; } $body = getforwardHeader($orig_header) . $body; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); $body = "\n" . $body; break; case 'forward_as_attachment': $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $body = ''; break; case 'reply_all': if (isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc, false, false, true); } case 'reply': if (!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to'); } else { if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to'); } else { $send_to = $orig_header->getAddr_s('from'); } } } $send_to = decodeHeader($send_to, false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = is_array($orig_header->from) && !empty($orig_header->from) ? $orig_header->from[0] : $orig_header->from; sqUnWordWrap($body); $body = ''; $cnt = count($rewrap_body); for ($i = 0; $i < $cnt; $i++) { sqWordWrap($rewrap_body[$i], $editor_size, $default_charset); if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n" . $body_quote . "{$gt} ", rtrim($rewrap_body[$i])) . "\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n" . $body_quote . (!empty($body_quote) ? ' ' : ''), rtrim($rewrap_body[$i])) . "\n"; } unset($rewrap_body[$i]); } $body = getReplyCitation($from, $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } $compose_messages[$session] = $composeMessage; sqsession_register($compose_messages, 'compose_messages'); session_write_close(); sqimap_logout($imapConnection); } $ret = array('send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity); return $ret; }
/** * 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, $key, $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, $key, $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; }
} // && $mail->open($account['host'], $account['type'], $account['port'],$account['username'], $GO_CRYPTO->decrypt($account['password']),$mailbox, 0, $account['use_ssl'], $account['novalidate_cert'])) $imapConnection = sqimap_login($account['username'], $GO_CRYPTO->decrypt($account['password']), $account['host'], $account['port'], true); if (!$imapConnection) { email_error(); } $aMailboxPref = array(MBX_PREF_SORT => 0, MBX_PREF_LIMIT => (int) $show_num, MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge, MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')); $aConfig = array('allow_thread_sort' => $allow_thread_sort, 'allow_server_sort' => $allow_server_sort, 'user' => $username, 'offset' => $startMessage); $aMailbox = sqm_api_mailbox_select($imapConnection, $mailbox, $aConfig, $aMailboxPref); if (!$aMailbox) { email_error(); } if (isset($aMailbox['MSG_HEADERS'][$uid]['MESSAGE_OBJECT']) && is_object($aMailbox['MSG_HEADERS'][$uid]['MESSAGE_OBJECT'])) { $message = $aMailbox['MSG_HEADERS'][$uid]['MESSAGE_OBJECT']; } else { $message = sqimap_get_message($imapConnection, $uid, $mailbox); $aMailbox['MSG_HEADERS'][$uid]['MESSAGE_OBJECT'] = $message; } $subject = $message->rfc822_header->subject; if ($ent_id) { $message =& $message->getEntity($ent_id); $header = $message->header; if ($message->rfc822_header) { $subject = $message->rfc822_header->subject; } else { $header = $message->header; } $type0 = $header->type0; $type1 = $header->type1; $encoding = strtolower($header->encoding); } else {