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