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