- }
- }
- } // 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['type0'] = 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, $prefix_sig,
- $editor_size, $attachments, $subject, $newmail,
- $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
- $from_htmladdr_search, $location_of_buttons;
-
- $subject = decodeHeader($subject);
- $reply_subj = decodeHeader($reply_subj);
- $forward_subj = decodeHeader($forward_subj);
-
- if ($use_javascript_addr_book) {
- echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n";
- echo "function open_abook() { \n";
- echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\",";
- echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n";
- echo " if((!nwin.opener) && (document.windows != null))\n";
- echo " nwin.opener = document.windows;\n";
- echo "}\n";
- echo "// --></SCRIPT>\n\n";
- }
-
- echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST ENCTYPE=\"multipart/form-data\"";
- do_hook("compose_form");
- echo ">\n";
- if ($reply_id) {
- echo "<input type=hidden name=reply_id value=$reply_id>\n";
- }
- printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox));
- echo "<TABLE WIDTH=\"100%\" ALIGN=center CELLSPACING=0 BORDER=0>\n";
-
- if ($location_of_buttons == 'top') showComposeButtonRow();
-
- echo " <TR>\n";
- echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
- echo _("To:");
- echo " </TD><TD BGCOLOR=\"$color[4]\">\n";
- printf(" <INPUT TYPE=text NAME=\"send_to\" VALUE=\"%s\" SIZE=60><BR>\n",
- htmlspecialchars($send_to));
- echo " </TD>\n";
- echo " </TR>\n";
- echo " <TR>\n";
- echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
- echo _("CC:");
- echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
- printf(" <INPUT TYPE=text NAME=\"send_to_cc\" SIZE=60 VALUE=\"%s\"><BR>\n",
- htmlspecialchars($send_to_cc));
- echo " </TD>\n";
- echo " </TR>\n";
- echo " <TR>\n";
- echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
- echo _("BCC:");
- echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
- printf(" <INPUT TYPE=text NAME=\"send_to_bcc\" VALUE=\"%s\" SIZE=60><BR>\n",
- htmlspecialchars($send_to_bcc));
- echo "</TD></TR>\n";
-
- echo " <TR>\n";
- echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
- echo _("Subject:");
- echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
- if ($reply_subj) {
- $reply_subj = str_replace("\"", "'", $reply_subj);
- $reply_subj = trim($reply_subj);
- if (substr(strtolower($reply_subj), 0, 3) != "re:")
- $reply_subj = "Re: $reply_subj";
- printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
- htmlspecialchars($reply_subj));
- } else if ($forward_subj) {
- $forward_subj = trim($forward_subj);
- if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
- (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
- (substr(strtolower($forward_subj), 0, 6) != '[ fwd:'))
- $forward_subj = "[Fwd: $forward_subj]";
- printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
- htmlspecialchars($forward_subj));
- } else {
- printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
- htmlspecialchars($subject));
- }
- echo "</td></tr>\n\n";
-
- if ($location_of_buttons == 'between') showComposeButtonRow();
-
- echo " <TR>\n";
- echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
- echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>";
- echo htmlspecialchars($body);
- if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
- if ( $prefix_sig == true )
- echo "\n\n-- \n" . htmlspecialchars($signature);
- else
- echo "\n\n" . htmlspecialchars($signature);
- }
- echo "</TEXTAREA><BR>\n";
- echo " </TD>\n";
- echo " </TR>\n";
-
- if ($location_of_buttons == 'bottom')
- showComposeButtonRow();
- else {
- echo " <TR><TD> </TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT NAME=send VALUE=\""._("Send")."\"></TD></TR>\n";
- }
-
- // This code is for attachments
- echo " <tr>\n";
- echo " <TD BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
- echo " <SMALL><BR></SMALL>"._("Attach:");
- echo " </td><td ALIGN=left BGCOLOR=\"$color[0]\">\n";
- echo " <INPUT NAME=\"attachfile\" SIZE=48 TYPE=\"file\">\n";
- echo " <input type=\"submit\" name=\"attach\"";
- echo " value=\"" . _("Add") ."\">\n";
- echo " </td>\n";
- echo " </tr>\n";
- if (count($attachments))
- {
- echo "<tr><td bgcolor=\"$color[0]\" align=right>\n";
- echo " ";
- echo "</td><td align=left bgcolor=\"$color[0]\">";
- foreach ($attachments as $key => $info) {
- echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$key\">\n";
- echo $info['remotefilename'] . "<br>\n";
- }
-
- echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
- echo "</td></tr>";
- }
- // End of attachment code
-
- echo "</TABLE>\n";
- echo "</FORM>";
- do_hook("compose_bottom");
- }
-
- function showComposeButtonRow() {
- global $use_javascript_addr_book;
-
- echo " <TR><td>\n </td><td>\n";
- if ($use_javascript_addr_book) {
- echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
- echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");";
- echo " // --></SCRIPT><NOSCRIPT>\n";
- echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
- echo " </NOSCRIPT>\n";
- } else {
- echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
- }
- echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
-
- do_hook("compose_button_row");
-
- echo " </TD>\n";
- echo " </TR>\n\n";
- }
-
- function checkInput ($show) {
- /** I implemented the $show variable because the error messages
- were getting sent before the page header. So, I check once
- using $show=false, and then when i'm ready to display the
- error message, show=true **/
- global $body, $send_to, $subject, $color;
-
- if ($send_to == "") {
- if ($show)
+ }
+ }
+} /* function newMail() */
+
+
+function getAttachments($message, $session) {
+ global $mailbox, $attachments, $attachment_dir, $imapConnection,
+ $ent_num, $forward_id, $draft_id, $username;
+
+ if (isset($draft_id)) {
+ $id = $draft_id;
+ } else {
+ $id = $forward_id;
+ }
+
+ if (!$message) {
+ sqimap_mailbox_select($imapConnection, $mailbox);
+ $message = sqimap_get_message($imapConnection, $id, $mailbox);
+ }
+
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+ 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);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+ while (file_exists($full_localfilename)) {
+ $localfilename = GenerateRandomString(32, '', 7);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+ }
+
+ $newAttachment = array();
+ $newAttachment['localfilename'] = $localfilename;
+ $newAttachment['remotefilename'] = $filename;
+ $newAttachment['type'] = strtolower($message->header->type0 .
+ '/' . $message->header->type1);
+ $newAttachment['id'] = strtolower($message->header->id);
+ $newAttachment['session'] = $session;
+
+ /* Write Attachment to file */
+ $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
+ fputs($fp, decodeBody(mime_fetch_body($imapConnection,
+ $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], $session);
+ }
+ }
+ return;
+}
+
+function showInputForm ($session) {
+ global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
+ $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,
+ $username, $data_dir, $identity, $draft_id, $delete_draft,
+ $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
+ $saved_draft, $mail_sent, $sig_first;
+
+ $subject = decodeHeader($subject, false);
+ $reply_subj = decodeHeader($reply_subj, false);
+ $forward_subj = decodeHeader($forward_subj, false);
+
+ if ($use_javascript_addr_book) {
+ echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
+ 'function open_abook() { ' . "\n" .
+ ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
+ '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
+ ' if((!nwin.opener) && (document.windows != null))' . "\n" .
+ ' nwin.opener = document.windows;' . "\n" .
+ "}\n" .
+ '// --></SCRIPT>' . "\n\n";
+ }
+
+ echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
+ 'ENCTYPE="multipart/form-data"';
+ do_hook("compose_form");
+
+
+ echo ">\n";
+
+ if (isset($draft_id)) {
+ echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
+ }
+ if (isset($delete_draft)) {
+ echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
+ }
+ if (isset($session)) {
+ echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
+ }
+
+ if ($saved_draft == 'yes') {
+ echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
+ }
+ if ($mail_sent == 'yes') {
+ echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
+ }
+ echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
+ if ($compose_new_win == '1') {
+ echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
+ }
+ if ($location_of_buttons == 'top') {
+ showComposeButtonRow();
+ }
+
+ $idents = getPref($data_dir, $username, 'identities', 0);
+ if ($idents > 1) {
+ echo ' <TR>' . "\n" .
+ ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
+ "\n" .
+ _("From:") .
+ ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
+ '<select name=identity>' . "\n" .
+ '<option value=default>' .
+ htmlspecialchars(getPref($data_dir, $username, 'full_name'));
+ $em = getPref($data_dir, $username, 'email_address');
+ if ($em != '') {
+ echo htmlspecialchars(' <' . $em . '>') . "\n";
+ }
+ for ($i = 1; $i < $idents; $i ++) {
+ echo '<option value="' . $i . '"';
+ if (isset($identity) && $identity == $i) {
+ echo ' SELECTED';
+ }
+ echo '>' . htmlspecialchars(getPref($data_dir, $username,
+ 'full_name' . $i));
+ $em = getPref($data_dir, $username, 'email_address' . $i);
+ if ($em != '') {
+ echo htmlspecialchars(' <' . $em . '>') . "\n";
+ }
+ echo '</option>';
+ }
+ echo '</select>' . "\n" .
+ ' </TD>' . "\n" .
+ ' </TR>' . "\n";
+ }
+ echo ' <TR>' . "\n" .
+ ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
+ _("To:") .
+ ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
+ ' <INPUT TYPE=text NAME="send_to" VALUE="' .
+ htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
+ ' </TD>' . "\n" .
+ ' </TR>' . "\n" .
+ ' <TR>' . "\n" .
+ ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
+ _("CC:") .
+ ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
+ ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
+ htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
+ ' </TD>' . "\n" .
+ ' </TR>' . "\n" .
+ ' <TR>' . "\n" .
+ ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
+ _("BCC:") .
+ ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
+ ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
+ htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
+ '</TD></TR>' . "\n" .
+ ' <TR>' . "\n" .
+ ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
+ _("Subject:") .
+ ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
+ if ($reply_subj) {
+ $reply_subj = str_replace('"', "'", $reply_subj);
+ $reply_subj = trim($reply_subj);
+ if (substr(strtolower($reply_subj), 0, 3) != 're:') {
+ $reply_subj = 'Re: ' . $reply_subj;
+ }
+ echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
+ htmlspecialchars($reply_subj) . '">';
+ }
+ elseif ($forward_subj) {
+ $forward_subj = trim($forward_subj);
+ if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
+ (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
+ (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) {
+ $forward_subj = '[Fwd: ' . $forward_subj . ']';
+ }
+ echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
+ htmlspecialchars($forward_subj) . '">';
+ } else {
+ echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
+ htmlspecialchars($subject) . '">';
+ }
+ echo '</td></tr>' . "\n\n";
+
+ if ($location_of_buttons == 'between') {
+ showComposeButtonRow();
+ }
+
+ echo ' <TR>' . "\n" .
+ ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
+ ' <TEXTAREA NAME=body ROWS=20 COLS="' .
+ $editor_size . '" WRAP="VIRTUAL">';
+ if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
+ if ($sig_first == '1') {
+ echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
+ echo "\n\n".htmlspecialchars($body);
+ }
+ else {
+ echo "\n\n".htmlspecialchars($body);
+ echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
+ }
+ }
+ else {
+ echo htmlspecialchars($body);
+ }
+ echo '</TEXTAREA><BR>' . "\n" .
+ ' </TD>' . "\n" .
+ ' </TR>' . "\n";
+
+ if ($location_of_buttons == 'bottom') {
+ showComposeButtonRow();
+ } else {
+ echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
+ echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
+ }
+
+ /* This code is for attachments */
+ echo ' <TR>' . "\n" .
+ ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
+ _("Attach:") .
+ ' </TD>' . "\n" .
+ ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
+ ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
+ ' <input type="submit" name="attach"' .
+ ' value="' . _("Add") .'">' . "\n" .
+ ' </TD>' . "\n" .
+ ' </TR>' . "\n";
+
+ if (count($attachments)) {
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+ echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
+ ' ' .
+ '</td><td align=left bgcolor="' . $color[0] . '">';
+ foreach ($attachments as $key => $info) {
+ if ($info['session'] == $session) {
+ $attached_file = "$hashed_attachment_dir/$info[localfilename]";
+ echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
+ $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
+ show_readable_size(filesize($attached_file)) . ")<br>\n";
+ }
+ }
+
+ echo '<input type="submit" name="do_delete" value="' .
+ _("Delete selected attachments") . "\">\n" .
+ '</td></tr>';
+ }
+ /* End of attachment code */
+
+ echo '</TABLE>' . "\n";
+ if ($reply_id) {
+ echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n";
+ }
+ echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
+ "\">\n" .
+ '</FORM>';
+ do_hook('compose_bottom');
+ echo '</BODY></HTML>' . "\n";
+}
+
+
+function showComposeButtonRow() {
+ global $use_javascript_addr_book, $save_as_draft,
+ $default_use_priority, $mailprio, $default_use_mdn,
+ $request_mdn, $request_dr,
+ $data_dir, $username;
+
+ echo " <TR><TD>\n</TD><TD>\n";
+ if ($default_use_priority) {
+ if(!isset($mailprio)) {
+ $mailprio = "3";
+ }
+ echo _("Priority") .': <select name="mailprio">'.
+ '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
+ '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
+ '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
+ "</select>";
+ }
+ $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
+ if ($default_use_mdn) {
+ if ($mdn_user_support) {
+ echo "\n\t". _("Receipt") .': '.
+ '<input type="checkbox" name="request_mdn" value=1'.
+ ($request_mdn=='1'?' checked':'') .'>'. _("On read").
+ ' <input type="checkbox" name="request_dr" value=1'.
+ ($request_dr=='1'?' checked':'') .'>'. _("On Delivery");
+ }
+ }
+
+ echo " <TR><td>\n </td><td>\n";
+ echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
+ if ($use_javascript_addr_book) {
+ echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
+ " <input type=button value=\\\""._("Addresses").
+ "\\\" onclick='javascript:open_abook();'>\");".
+ " // --></SCRIPT><NOSCRIPT>\n".
+ " <input type=submit name=\"html_addr_search\" value=\"".
+ _("Addresses")."\">".
+ " </NOSCRIPT>\n";
+ } else {
+ echo " <input type=submit name=\"html_addr_search\" value=\"".
+ _("Addresses")."\">";
+ }
+ echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
+
+ if ($save_as_draft) {
+ echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
+ }
+
+ do_hook('compose_button_row');
+
+ echo " </TD></TR>\n\n";
+}
+
+function checkInput ($show) {
+ /*
+ * I implemented the $show variable because the error messages
+ * were getting sent before the page header. So, I check once
+ * using $show=false, and then when i'm ready to display the error
+ * message, show=true
+ */
+ global $body, $send_to, $subject, $color;
+
+ if ($send_to == "") {
+ if ($show) {