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