Added sent_subfolders plugin, tweaked config stuff, other stuff.
[squirrelmail.git] / src / compose.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * compose.php
5 *
6 * Copyright (c) 1999-2001 The Squirrelmail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This code sends a mail.
10 *
11 * There are 4 modes of operation:
12 * - Start new mail
13 * - Add an attachment
14 * - Send mail
15 * - Save As Draft
16 *
17 * $Id$
18 */
f7fb20fe 19
35586184 20/*****************************************************************/
21/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
22/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
23/*** + Base level indent should begin at left margin, as ***/
24/*** the require_once below looks. ***/
25/*** + All identation should consist of four space blocks ***/
26/*** + Tab characters are evil. ***/
27/*** + all comments should use "slash-star ... star-slash" ***/
28/*** style -- no pound characters, no slash-slash style ***/
29/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
30/*** ALWAYS USE { AND } CHARACTERS!!! ***/
31/*** + Please use ' instead of ", when possible. Note " ***/
32/*** should always be used in _( ) function calls. ***/
33/*** Thank you for your help making the SM code more readable. ***/
34/*****************************************************************/
35
36require_once('../src/validate.php');
37require_once('../functions/imap.php');
38require_once('../functions/date.php');
39require_once('../functions/mime.php');
40require_once('../functions/smtp.php');
41require_once('../functions/display_messages.php');
42require_once('../functions/plugin.php');
8467bf00 43
a3439b27 44 if (!isset($attachments)) {
79be8a0b 45 $attachments = array();
f972eb46 46 session_register('attachments');
47 }
a98bed68 48
4ba45d11 49 // This function is used when not sending or adding attachments
df15de21 50 function newMail () {
51 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
0a17f9dd 52 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
53 $draft_id, $use_signature;
e39d73e5 54
d51894be 55 $send_to = decodeHeader($send_to);
56 $send_to_cc = decodeHeader($send_to_cc);
57 $send_to_bcc = decodeHeader($send_to_bcc);
a53e5469 58
429f8906 59 if ($forward_id)
60 $id = $forward_id;
3b5b889f 61 elseif ($reply_id)
429f8906 62 $id = $reply_id;
63
0a17f9dd 64 if ($draft_id){
65 $id = $draft_id;
66 $use_signature = FALSE;
67 }
1195c340 68
245a6892 69 if (isset($id)) {
813eba2f 70 sqimap_mailbox_select($imapConnection, $mailbox);
429f8906 71 $message = sqimap_get_message($imapConnection, $id, $mailbox);
8d8ab69a 72 $orig_header = $message->header;
1195c340 73 if ($ent_num)
74 $message = getEntity($message, $ent_num);
429f8906 75
9487c2ff 76 if ($message->header->type0 == 'text' || $message->header->type1 == 'message') {
1195c340 77 if ($ent_num)
78 $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header->encoding);
79 else
80 $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header->encoding);
429f8906 81 } else {
82 $body = "";
df15de21 83 }
9487c2ff 84
429f8906 85 if ($message->header->type1 == "html")
86 $body = strip_tags($body);
f82d9be2 87
9487c2ff 88 sqUnWordWrap($body);
a794e82c 89 $body_ary = explode("\n", $body);
fb6ce88e 90 $i = count($body_ary) - 1;
3bc5ef2d 91 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
fb6ce88e 92 unset($body_ary[$i]);
93 $i --;
441f2d33 94 }
a794e82c 95 $body = "";
3bc5ef2d 96 for ($i=0; isset($body_ary[$i]); $i++) {
0a17f9dd 97 if ($reply_id)
01aab860 98 {
59a29c4b 99 if (ereg('^[ >]+', $body_ary[$i]))
01aab860 100 {
101 $body_ary[$i] = '>' . $body_ary[$i];
102 }
103 else
104 {
105 $body_ary[$i] = '> ' . $body_ary[$i];
106 }
107 }
a951522b 108 if (!$draft_id) {
109 sqWordWrap($body_ary[$i], $editor_size - 1);
110 }
01aab860 111 $body .= $body_ary[$i] . "\n";
f923b93d 112 unset($body_ary[$i]);
a794e82c 113 }
01aab860 114 if ($forward_id)
115 {
116 $bodyTop = "-------- " . _("Original Message") . " --------\n";
9487c2ff 117 $bodyTop .= _("Subject") . ": " . $orig_header->subject . "\n";
118 $bodyTop .= _("From") . ": " . $orig_header->from . "\n";
119 $bodyTop .= _("To") . ": " . $orig_header->to[0] . "\n";
01aab860 120 if (count($orig_header->to) > 1) {
121 for ($x=1; $x < count($orig_header->to); $x++) {
122 $bodyTop .= " " . $orig_header->to[$x] . "\n";
123 }
124 }
125 $bodyTop .= "\n";
126 $body = $bodyTop . $body;
856af1e0 127 } else if ($reply_id) {
9af31e64 128 $orig_from = decodeHeader($orig_header->from);
4c06e15d 129 $orig_from = trim(substr($orig_from,0,strpos($orig_from,'<')));
130 $orig_from = str_replace('"','',$orig_from);
131 $orig_from = str_replace("'",'',$orig_from);
248bfebb 132 $body = getReplyCitation($orig_from) . $body;
78509c54 133 }
9487c2ff 134
01aab860 135 return;
78509c54 136 }
429f8906 137
29d08a52 138 if (!$send_to) {
139 $send_to = sqimap_find_email($send_to);
140 }
141
df15de21 142 /** This formats a CC string if they hit "reply all" **/
143 if ($send_to_cc != "") {
a48fbf9b 144 $send_to_cc = ereg_replace( '"[^"]*"', "", $send_to_cc);
df15de21 145 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
146 $sendcc = explode(",", $send_to_cc);
147 $send_to_cc = "";
9487c2ff 148
df15de21 149 for ($i = 0; $i < count($sendcc); $i++) {
150 $sendcc[$i] = trim($sendcc[$i]);
151 if ($sendcc[$i] == "")
152 continue;
9487c2ff 153
a53e5469 154 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
813eba2f 155 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
156 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
9487c2ff 157
df15de21 158 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
159 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
160 (trim($sendcc[$i]) != "")) {
161 $send_to_cc .= trim($sendcc[$i]) . ", ";
162 }
163 }
164 $send_to_cc = trim($send_to_cc);
165 if (substr($send_to_cc, -1) == ",") {
166 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
167 }
168 }
169 } // function newMail()
78509c54 170
5713b4f9 171 function getAttachments($message) {
172 global $mailbox, $attachments, $attachment_dir, $imapConnection,
3392dc86 173 $ent_num, $forward_id, $draft_id, $username;
0a17f9dd 174
175 if (isset($draft_id))
176 $id = $draft_id;
177 else
178 $id = $forward_id;
f972eb46 179
5713b4f9 180 if (!$message) {
181 sqimap_mailbox_select($imapConnection, $mailbox);
0a17f9dd 182 $message = sqimap_get_message($imapConnection, $id,
f923b93d 183 $mailbox);
991a059e 184 }
9487c2ff 185
3392dc86 186 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
991a059e 187 if (count($message->entities) == 0) {
188 if ($message->header->entity_id != $ent_num) {
189 $filename = decodeHeader($message->header->filename);
9487c2ff 190
991a059e 191 if ($filename == "")
192 $filename = "untitled-".$message->header->entity_id;
9487c2ff 193
991a059e 194 $localfilename = GenerateRandomString(32, '', 7);
3392dc86 195 $full_localfilename = "$hashed_attachment_dir/$localfilename";
196 while (file_exists($full_localfilename)) {
f923b93d 197 $localfilename = GenerateRandomString(32, '', 7);
3392dc86 198 $full_localfilename = "$hashed_attachment_dir/$localfilename";
199 }
f972eb46 200
7a813c24 201 $newAttachment = array();
f972eb46 202 $newAttachment['localfilename'] = $localfilename;
f923b93d 203 $newAttachment['remotefilename'] = $filename;
204 $newAttachment['type'] = strtolower($message->header->type0 .
205 '/' . $message->header->type1);
991a059e 206
207 // Write Attachment to file
3392dc86 208 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
9487c2ff 209 fputs ($fp, decodeBody(mime_fetch_body($imapConnection,
0a17f9dd 210 $id, $message->header->entity_id),
f923b93d 211 $message->header->encoding));
991a059e 212 fclose ($fp);
9487c2ff 213
f972eb46 214 $attachments[] = $newAttachment;
991a059e 215 }
5713b4f9 216 } else {
991a059e 217 for ($i = 0; $i < count($message->entities); $i++) {
5713b4f9 218 getAttachments($message->entities[$i]);
9487c2ff 219 }
5713b4f9 220 }
221 return;
9487c2ff 222 }
5713b4f9 223
df15de21 224 function showInputForm () {
225 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
9487c2ff 226 $passed_body, $color, $use_signature, $signature, $prefix_sig,
227 $editor_size, $attachments, $subject, $newmail,
228 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
aaf9abef 229 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
020abcf3 230 $username, $data_dir, $identity, $draft_id, $delete_draft,
231 $mailprio;
78509c54 232
d51894be 233 $subject = decodeHeader($subject);
2e434774 234 $reply_subj = decodeHeader($reply_subj);
235 $forward_subj = decodeHeader($forward_subj);
9487c2ff 236
3806fa52 237 if ($use_javascript_addr_book) {
238 echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n";
239 echo "function open_abook() { \n";
240 echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\",";
241 echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n";
242 echo " if((!nwin.opener) && (document.windows != null))\n";
243 echo " nwin.opener = document.windows;\n";
244 echo "}\n";
245 echo "// --></SCRIPT>\n\n";
246 }
5100704d 247
b3911477 248 echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST ENCTYPE=\"multipart/form-data\"";
249 do_hook("compose_form");
f923b93d 250 echo ">\n";
9487c2ff 251
f7b1b3b1 252 if (isset($draft_id)) {
0a17f9dd 253 echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$draft_id\">\n";
f7b1b3b1 254 }
0fe622fd 255 if (isset($delete_draft)) {
256 echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$delete_draft\">\n";
257 }
0a17f9dd 258
c5d828b3 259 echo "<TABLE WIDTH=\"100%\" ALIGN=center CELLSPACING=0 BORDER=0>\n";
441f2d33 260
261 if ($location_of_buttons == 'top') showComposeButtonRow();
262
aaf9abef 263 $idents = getPref($data_dir, $username, 'identities');
248bfebb 264 if ($idents != '' && $idents > 1) {
aaf9abef 265 echo " <TR>\n";
e7db48af 266 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=\"10%\" ALIGN=RIGHT>\n";
aaf9abef 267 echo _("From:");
e7db48af 268 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=\"90%\">\n";
248bfebb 269 echo "<select name=identity>\n";
9487c2ff 270 echo "<option value=default>" .
248bfebb 271 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
272 $em = getPref($data_dir, $username, 'email_address');
273 if ($em != '')
274 echo htmlspecialchars(' <' . $em . '>') . "\n";
275 for ($i = 1; $i < $idents; $i ++) {
276 echo '<option value="' . $i . '"';
277 if (isset($identity) && $identity == $i)
278 echo ' SELECTED';
279 echo '>';
9487c2ff 280 echo htmlspecialchars(getPref($data_dir, $username, 'full_name' .
248bfebb 281 $i));
282 $em = getPref($data_dir, $username, 'email_address' . $i);
283 if ($em != '')
284 echo htmlspecialchars(' <' . $em . '>') . "\n";
285 }
286 echo "</select>\n";
aaf9abef 287 echo " </TD>\n";
288 echo " </TR>\n";
289 }
df15de21 290 echo " <TR>\n";
e7db48af 291 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=\"10%\" ALIGN=RIGHT>\n";
df15de21 292 echo _("To:");
e7db48af 293 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=\"90%\">\n";
cf8758c7 294 printf(" <INPUT TYPE=text NAME=\"send_to\" VALUE=\"%s\" SIZE=60><BR>\n",
6e79bfe2 295 htmlspecialchars($send_to));
df15de21 296 echo " </TD>\n";
297 echo " </TR>\n";
298 echo " <TR>\n";
c5d828b3 299 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
aae41ae9 300 echo _("CC:");
c5d828b3 301 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
cf8758c7 302 printf(" <INPUT TYPE=text NAME=\"send_to_cc\" SIZE=60 VALUE=\"%s\"><BR>\n",
6e79bfe2 303 htmlspecialchars($send_to_cc));
df15de21 304 echo " </TD>\n";
305 echo " </TR>\n";
306 echo " <TR>\n";
c5d828b3 307 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
aae41ae9 308 echo _("BCC:");
761d149e 309 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
cf8758c7 310 printf(" <INPUT TYPE=text NAME=\"send_to_bcc\" VALUE=\"%s\" SIZE=60><BR>\n",
6e79bfe2 311 htmlspecialchars($send_to_bcc));
3806fa52 312 echo "</TD></TR>\n";
5100704d 313
df15de21 314 echo " <TR>\n";
c5d828b3 315 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
df15de21 316 echo _("Subject:");
761d149e 317 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
df15de21 318 if ($reply_subj) {
319 $reply_subj = str_replace("\"", "'", $reply_subj);
df15de21 320 $reply_subj = trim($reply_subj);
321 if (substr(strtolower($reply_subj), 0, 3) != "re:")
322 $reply_subj = "Re: $reply_subj";
cf8758c7 323 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
6e79bfe2 324 htmlspecialchars($reply_subj));
df15de21 325 } else if ($forward_subj) {
df15de21 326 $forward_subj = trim($forward_subj);
f972eb46 327 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
328 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
329 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:'))
df15de21 330 $forward_subj = "[Fwd: $forward_subj]";
cf8758c7 331 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
6e79bfe2 332 htmlspecialchars($forward_subj));
df15de21 333 } else {
6e79bfe2 334 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
335 htmlspecialchars($subject));
31f3d7c0 336 }
480feea7 337 echo "</td></tr>\n\n";
338
441f2d33 339 if ($location_of_buttons == 'between') showComposeButtonRow();
4ba45d11 340
e5b23ff2 341 echo " <TR>\n";
c5d828b3 342 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
cf8758c7 343 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>";
441f2d33 344 echo htmlspecialchars($body);
6e79bfe2 345 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
b8163cc4 346 if ( $prefix_sig == true )
347 echo "\n\n-- \n" . htmlspecialchars($signature);
348 else
349 echo "\n\n" . htmlspecialchars($signature);
cf8758c7 350 }
351 echo "</TEXTAREA><BR>\n";
e5b23ff2 352 echo " </TD>\n";
353 echo " </TR>\n";
441f2d33 354
9487c2ff 355 if ($location_of_buttons == 'bottom')
441f2d33 356 showComposeButtonRow();
357 else {
358 echo " <TR><TD>&nbsp;</TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT NAME=send VALUE=\""._("Send")."\"></TD></TR>\n";
359 }
9487c2ff 360
4ba45d11 361 // This code is for attachments
a98bed68 362 echo " <tr>\n";
889df970 363 echo " <TD BGCOLOR=\"$color[0]\" VALIGN=MIDDLE ALIGN=RIGHT>\n";
364 echo _("Attach:");
a98bed68 365 echo " </td><td ALIGN=left BGCOLOR=\"$color[0]\">\n";
944eb785 366 echo " <INPUT NAME=\"attachfile\" SIZE=48 TYPE=\"file\">\n";
95de6c91 367 echo " &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"";
368 echo " value=\"" . _("Add") ."\">\n";
469eb37b 369 echo " </td>\n";
469eb37b 370 echo " </tr>\n";
3392dc86 371 if (count($attachments)) {
372 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
a98bed68 373 echo "<tr><td bgcolor=\"$color[0]\" align=right>\n";
e5b23ff2 374 echo "&nbsp;";
a98bed68 375 echo "</td><td align=left bgcolor=\"$color[0]\">";
f923b93d 376 foreach ($attachments as $key => $info) {
3392dc86 377 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
f972eb46 378 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$key\">\n";
f923b93d 379 echo $info['remotefilename'] . " - " . $info['type'] . " (";
3392dc86 380 echo show_readable_size(filesize($attached_file)) . ")<br>\n";
4ba45d11 381 }
9487c2ff 382
4ba45d11 383 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
469eb37b 384 echo "</td></tr>";
4ba45d11 385 }
4ba45d11 386 // End of attachment code
387
ffc2ccbc 388 echo "</TABLE>\n";
9487c2ff 389 if ($reply_id) {
390 echo "<input type=hidden name=reply_id value=$reply_id>\n";
391 }
392 printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox));
df15de21 393 echo "</FORM>";
d7d3c4d4 394 do_hook("compose_bottom");
4d1d3c86 395 echo "</BODY></HTML>\n";
31f3d7c0 396 }
9487c2ff 397
441f2d33 398 function showComposeButtonRow() {
020abcf3 399 global $use_javascript_addr_book, $save_as_draft,
400 $default_use_priority, $mailprio;
9487c2ff 401
441f2d33 402 echo " <TR><td>\n </td><td>\n";
403 if ($use_javascript_addr_book) {
404 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
405 echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");";
406 echo " // --></SCRIPT><NOSCRIPT>\n";
407 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
408 echo " </NOSCRIPT>\n";
9487c2ff 409 } else {
441f2d33 410 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
9487c2ff 411 }
441f2d33 412 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
9487c2ff 413
f7b1b3b1 414 if ($save_as_draft) {
57155fe3 415 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
f7b1b3b1 416 }
020abcf3 417 if ($default_use_priority) {
418 if(!isset($mailprio)) {
419 $mailprio = "3";
420 }
421 echo "\n\t". _("Priority") .":<select name=\"mailprio\">".
422 "\n\t\t<option value=1".($mailprio=="1"?" selected":"").">". _("High") ."</option>".
423 "\n\t\t<option value=3".($mailprio=="3"?" selected":"").">". _("Normal") ."</option>".
424 "\n\t\t<option value=5".($mailprio=="5"?" selected":"").">". _("Low")."</option>".
425 "\n\t</select>";
426 }
0a17f9dd 427
441f2d33 428 do_hook("compose_button_row");
429
430 echo " </TD>\n";
431 echo " </TR>\n\n";
432 }
8467bf00 433
0ad7dbda 434 function checkInput ($show) {
435 /** I implemented the $show variable because the error messages
436 were getting sent before the page header. So, I check once
437 using $show=false, and then when i'm ready to display the
438 error message, show=true **/
439 global $body, $send_to, $subject, $color;
b278172f 440
99fa2b21 441 if ($send_to == "") {
0ad7dbda 442 if ($show)
443 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
df15de21 444 return false;
b278172f 445 }
df15de21 446 return true;
447 } // function checkInput()
448
3806fa52 449
056ddad7 450 // True if FAILURE
451 function saveAttachedFiles() {
3392dc86 452 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
020abcf3 453
3392dc86 454 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
056ddad7 455 $localfilename = GenerateRandomString(32, '', 7);
3392dc86 456 $full_localfilename = "$hashed_attachment_dir/$localfilename";
457 while (file_exists($full_localfilename)) {
a4fe5de0 458 $localfilename = GenerateRandomString(32, '', 7);
3392dc86 459 $full_localfilename = "$hashed_attachment_dir/$localfilename";
460 }
f972eb46 461
3392dc86 462 if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
463 if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
056ddad7 464 return true;
465 }
466 }
9487c2ff 467
f972eb46 468 $newAttachment['localfilename'] = $localfilename;
469 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
9487c2ff 470 $newAttachment['type'] =
f972eb46 471 strtolower($HTTP_POST_FILES['attachfile']['type']);
8ef72f33 472
473 if ($newAttachment['type'] == "")
474 $newAttachment['type'] = 'application/octet-stream';
475
f972eb46 476 $attachments[] = $newAttachment;
056ddad7 477 }
9487c2ff 478
2d367c68 479 if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None'))
dcb7f454 480 $mailbox = "INBOX";
3806fa52 481
0a17f9dd 482 if (isset($draft)) {
483 require_once ('../src/draft_actions.php');
f7b1b3b1 484 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
0a17f9dd 485 showInputForm();
486 exit();
487 } else {
f7b1b3b1 488 $draft_message = _("Draft Email Saved");
45c4e0f2 489 /* If this is a resumed draft, then delete the original */
490 if(isset($delete_draft)) {
491 Header("Location: delete_message.php?mailbox=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
492 exit();
493 } else {
494 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort&startMessage=1&note=$draft_message");
495 exit();
496 }
0a17f9dd 497 }
498 }
499
f972eb46 500 if (isset($send)) {
245a6892 501 if (isset($HTTP_POST_FILES['attachfile']) &&
502 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
78b4216e 503 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none')
056ddad7 504 $AttachFailure = saveAttachedFiles();
a7ea7540 505 if (checkInput(false) && !isset($AttachFailure)) {
35d520d3 506 $urlMailbox = urlencode (trim($mailbox));
507 if (! isset($reply_id))
508 $reply_id = 0;
ebab5342 509 // Set $default_charset to correspond with the user's selection
f923b93d 510 // of language interface.
511 set_my_charset();
eedcdd97 512
513 // This is to change all newlines to \n
248bfebb 514 // We'll change them to \r\n later (in the sendMessage function)
515 $body = str_replace("\r\n", "\n", $body);
516 $body = str_replace("\r", "\n", $body);
9487c2ff 517
248bfebb 518 // Rewrap $body so that no line is bigger than $editor_size
519 // This should only really kick in the sqWordWrap function
520 // if the browser doesn't support "HARD" as the wrap type
521 // Or, in Opera's case, something goes wrong.
522 $body = explode("\n", $body);
523 $newBody = '';
524 foreach ($body as $line) {
525 if( $line <> '-- ' )
526 $line = rtrim($line);
527 if (strlen($line) <= $editor_size + 1)
528 $newBody .= $line . "\n";
529 else {
530 sqWordWrap($line, $editor_size) . "\n";
531 $newBody .= $line;
532 }
533 }
534 $body = $newBody;
9487c2ff 535
f923b93d 536 do_hook("compose_send");
9487c2ff 537
872c4fac 538 if (! isset($mailprio))
539 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
9bc3dc44 540 $subject, $body, $reply_id);
872c4fac 541 else
9bc3dc44 542 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
543 $subject, $body, $reply_id, $mailprio);
872c4fac 544 if (! $Result) {
9487c2ff 545 showInputForm();
248bfebb 546 exit();
547 }
0a17f9dd 548 if ( isset($delete_draft)) {
cc82b756 549 Header("Location: delete_message.php?mailbox=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
0a17f9dd 550 exit();
551 }
552
248bfebb 553 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
df15de21 554 } else {
01aab860 555 //$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
dcb7f454 556 displayPageHeader($color, $mailbox);
9487c2ff 557
7a813c24 558 if (isset($AttachFailure))
056ddad7 559 plain_error_message(_("Could not move/copy file. File not attached"), $color);
560
0ad7dbda 561 checkInput(true);
9487c2ff 562
df15de21 563 showInputForm();
01aab860 564 //sqimap_logout($imapConnection);
7c6cb7ca 565 }
245a6892 566 } else if (isset($html_addr_search_done)) {
dcb7f454 567 displayPageHeader($color, $mailbox);
3806fa52 568
b8796881 569 if (isset($send_to_search) && is_array($send_to_search)) {
570 foreach ($send_to_search as $k => $v) {
248bfebb 571 if (substr($k, 0, 1) == 'T') {
b8796881 572 if ($send_to)
573 $send_to .= ', ';
574 $send_to .= $v;
248bfebb 575 }
576 elseif (substr($k, 0, 1) == 'C') {
577 if ($send_to_cc)
578 $send_to_cc .= ', ';
579 $send_to_cc .= $v;
580 }
581 elseif (substr($k, 0, 1) == 'B') {
582 if ($send_to_bcc)
583 $send_to_bcc .= ', ';
584 $send_to_bcc .= $v;
585 }
e53f7484 586 }
a98bed68 587 }
9487c2ff 588
3806fa52 589 showInputForm();
245a6892 590 } else if (isset($html_addr_search)) {
f17728d1 591 if (isset($HTTP_POST_FILES['attachfile']) &&
592 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
593 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none')
594 {
595 if (saveAttachedFiles())
596 plain_error_message(_("Could not move/copy file. File not attached"), $color);
597 }
591d2a88 598 // I am using an include so as to elminiate an extra unnecessary click. If you
599 // can think of a better way, please implement it.
ff8a98e7 600 include_once('./addrbook_search_html.php');
4ba45d11 601 } else if (isset($attach)) {
056ddad7 602 if (saveAttachedFiles())
22ef7536 603 plain_error_message(_("Could not move/copy file. File not attached"), $color);
21bc0570 604 displayPageHeader($color, $mailbox);
4ba45d11 605 showInputForm();
606 } else if (isset($do_delete)) {
dcb7f454 607 displayPageHeader($color, $mailbox);
fc3348ac 608
3392dc86 609 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
610 if (isset($delete) && is_array($delete)) {
611 foreach($delete as $index) {
612 $attached_file = $hashed_attachment_dir . '/'
613 . $attachments[$index]['localfilename'];
614 unlink ($attached_file);
f972eb46 615 unset ($attachments[$index]);
f923b93d 616 }
4ba45d11 617 }
4bfed9f3 618
4ba45d11 619 showInputForm();
620 } else {
991a059e 621 // This handles the default case as well as the error case
622 // (they had the same code) --> if (isset($smtpErrors))
9487c2ff 623 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
991a059e 624 $imapPort, 0);
dcb7f454 625 displayPageHeader($color, $mailbox);
fc3348ac 626
b57c4e63 627 $newmail = true;
f972eb46 628
629 ClearAttachments();
630
991a059e 631 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num)
632 getAttachments(0);
9487c2ff 633
0a17f9dd 634 if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num)
635 getAttachments(0);
636
1220e677 637 newMail();
4ba45d11 638 showInputForm();
1195c340 639 sqimap_logout($imapConnection);
4ba45d11 640 }
9487c2ff 641
f923b93d 642 function ClearAttachments() {
3392dc86 643 global $username, $attachments, $attachment_dir;
644 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
9487c2ff 645
f923b93d 646 foreach ($attachments as $info) {
3392dc86 647 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
648 if (file_exists($attached_file)) {
649 unlink($attached_file);
f923b93d 650 }
f972eb46 651 }
9487c2ff 652
f972eb46 653 $attachments = array();
654 }
cd41fc8d 655
656 function getReplyCitation($orig_from) {
657 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
658
659 /* First, return an empty string when no citation style selected. */
660 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
661 return ('');
662 }
663
664 /* Otherwise, try to select the desired citation style. */
665 switch ($reply_citation_style) {
666 case 'author_said':
667 $start = '';
668 $end = ' ' . _("said") . ':';
669 break;
670 case 'quote_who':
671 $start = '<' . _("quote") . ' ' . _("who") . '="';
672 $end = '">';
673 break;
674 case 'user-defined':
675 $start = $reply_citation_start;
676 $end = $reply_citation_end;
677 break;
678 default: return ('');
679 }
680
681 /* Build and return the citation string. */
682 return ($start . $orig_from . $end . "\n");
9487c2ff 683 }
0a17f9dd 684?>