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