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