X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fcompose.php;h=bc688f6e9d335f79a0570860c776b7dedf10ca09;hb=f740c049d91feb836dd9633be9e8ff52c00d066f;hp=1befa6a2bfb587aebb8a6dd2db252a151e1405e0;hpb=1220e6778940c8703bfdf87fa4d3e7760d43b942;p=squirrelmail.git diff --git a/src/compose.php b/src/compose.php index 1befa6a2..bc688f6e 100644 --- a/src/compose.php +++ b/src/compose.php @@ -1,110 +1,122 @@ - - /** This code sends a mail. +
\n"; - $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0); - displayPageHeader($color, "None"); + if (!isset($attachments)) + { + $attachments = array(); + session_register('attachments'); + } + // This function is used when not sending or adding attachments function newMail () { global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, - $reply_id, $send_to, $send_to_cc, $mailbox; + $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size; + + $send_to = decodeHeader($send_to); + $send_to_cc = decodeHeader($send_to_cc); + $send_to_bcc = decodeHeader($send_to_bcc); - if ($forward_id) { + if ($forward_id) + $id = $forward_id; + elseif ($reply_id) + $id = $reply_id; + + + if (isset($id)) { sqimap_mailbox_select($imapConnection, $mailbox); - $msg = sqimap_get_message($imapConnection, $forward_id, $mailbox); - - if (containsType($msg, "text", "html", $ent_num)) { - $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]); - } else if (containsType($msg, "text", "plain", $ent_num)) { - $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]); - } - // add other primary displaying msg types here - else { - // find any type that's displayable - if (containsType($msg, "text", "any_type", $ent_num)) { - $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]); - } else if (containsType($msg, "msg", "any_type", $ent_num)) { - $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]); - } else { - $body = _("No Message"); - } - } - - $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"]; - - $tmp = _("-------- Original Message ---------\n"); - $body_ary = explode("\n", $body); - $body = ""; - for ($i=0;$i < count($body_ary);$i++) { - if ($type1 == "html") - $tmp .= strip_tags($body_ary[$i]); + $message = sqimap_get_message($imapConnection, $id, $mailbox); + $orig_header = $message->header; + if ($ent_num) + $message = getEntity($message, $ent_num); + + if ($message->header->type0 == "text" || $message->header->type1 == "message") { + if ($ent_num) + $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header->encoding); else - $tmp .= $body_ary[$i]; - $body = "$body$tmp\n"; - $tmp = ""; + $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header->encoding); + } else { + $body = ""; } - } - - if ($reply_id) { - sqimap_mailbox_select($imapConnection, $mailbox); - $msg = sqimap_get_message($imapConnection, $reply_id, $mailbox); - - if (containsType($msg, "text", "html", $ent_num)) { - $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false); - } else if (containsType($msg, "text", "plain", $ent_num)) { - $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false); + + if ($message->header->type1 == "html") + $body = strip_tags($body); + + sqUnWordWrap($body); + $body_ary = explode("\n", $body); + $i = count($body_ary) - 1; + while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) { + unset($body_ary[$i]); + $i --; } - // add other primary displaying msg types here - else { - // find any type that's displayable - if (containsType($msg, "text", "any_type", $ent_num)) { - $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false); - } else if (containsType($msg, "msg", "any_type", $ent_num)) { - $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false); - } else { - $body = _("No Message"); + $body = ""; + for ($i=0; isset($body_ary[$i]); $i++) { + if (! $forward_id) + { + if (ereg('^[\\s>]+', $body_ary[$i])) + { + $body_ary[$i] = '>' . $body_ary[$i]; + } + else + { + $body_ary[$i] = '> ' . $body_ary[$i]; + } } + sqWordWrap($body_ary[$i], $editor_size - 1); + $body .= $body_ary[$i] . "\n"; + unset($body_ary[$i]); } - - $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"]; - - $body_ary = explode("\n", $body); - $body = ""; - for ($i=0;$i < count($body_ary);$i++) { - if ($type1 == "html") - $tmp = strip_tags($body_ary[$i]); - else - $tmp = $body_ary[$i]; - $body = "$body> $tmp\n"; + if ($forward_id) + { + $bodyTop = "-------- " . _("Original Message") . " --------\n"; + $bodyTop .= _("Subject") . ": " . $orig_header->subject . "\n"; + $bodyTop .= _("From") . ": " . $orig_header->from . "\n"; + $bodyTop .= _("To") . ": " . $orig_header->to[0] . "\n"; + if (count($orig_header->to) > 1) { + for ($x=1; $x < count($orig_header->to); $x++) { + $bodyTop .= " " . $orig_header->to[$x] . "\n"; + } + } + $bodyTop .= "\n"; + $body = $bodyTop . $body; } + + return; } - - $send_to = sqimap_find_displayable_name($send_to); - - $send_to = strtolower($send_to); - $send_to = ereg_replace("\"", "", $send_to); - $send_to = stripslashes($send_to); - + + if (!$send_to) { + $send_to = sqimap_find_email($send_to); + } + /** This formats a CC string if they hit "reply all" **/ if ($send_to_cc != "") { + $send_to_cc = ereg_replace( '"[^"]*"', "", $send_to_cc); $send_to_cc = ereg_replace(";", ",", $send_to_cc); $sendcc = explode(",", $send_to_cc); $send_to_cc = ""; @@ -114,7 +126,7 @@ if ($sendcc[$i] == "") continue; - $sendcc[$i] = sqimap_find_displayable_name($sendcc[$i]); + $sendcc[$i] = sqimap_find_email($sendcc[$i]); $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]); $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]); @@ -131,108 +143,173 @@ } } // function newMail() + function getAttachments($message) { + global $mailbox, $attachments, $attachment_dir, $imapConnection, + $ent_num, $forward_id; + + if (!$message) { + sqimap_mailbox_select($imapConnection, $mailbox); + $message = sqimap_get_message($imapConnection, $forward_id, + $mailbox); + } + + if (count($message->entities) == 0) { + if ($message->header->entity_id != $ent_num) { + $filename = decodeHeader($message->header->filename); + + if ($filename == "") + $filename = "untitled-".$message->header->entity_id; + + $localfilename = GenerateRandomString(32, '', 7); + while (file_exists($attachment_dir . $localfilename)) + $localfilename = GenerateRandomString(32, '', 7); + + $newAttachment['localfilename'] = $localfilename; + $newAttachment['remotefilename'] = $filename; + $newAttachment['type'] = strtolower($message->header->type0 . + '/' . $message->header->type1); + + // Write Attachment to file + $fp = fopen ($attachment_dir.$localfilename, 'w'); + fputs ($fp, decodeBody(mime_fetch_body($imapConnection, + $forward_id, $message->header->entity_id), + $message->header->encoding)); + fclose ($fp); + + $attachments[] = $newAttachment; + } + } else { + for ($i = 0; $i < count($message->entities); $i++) { + getAttachments($message->entities[$i]); + } + } + return; + } + function showInputForm () { global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body, - $passed_body, $color, $use_signature, $signature, $editor_size, - $attachments, $subject, $newmail; + $passed_body, $color, $use_signature, $signature, $prefix_sig, + $editor_size, $attachments, $subject, $newmail, + $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox, + $from_htmladdr_search, $location_of_buttons, $attachment_dir; + + $subject = decodeHeader($subject); + $reply_subj = decodeHeader($reply_subj); + $forward_subj = decodeHeader($forward_subj); + + if ($use_javascript_addr_book) { + echo "\n\n\n"; + } + + echo "\n