59177427 |
1 | <?php |
ef870322 |
2 | /** |
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 |
14 | **/ |
15 | |
2a32fc83 |
16 | session_start(); |
17 | |
d068c0ec |
18 | if (!isset($config_php)) |
19 | include("../config/config.php"); |
20 | if (!isset($strings_php)) |
21 | include("../functions/strings.php"); |
22 | if (!isset($page_header_php)) |
23 | include("../functions/page_header.php"); |
24 | if (!isset($imap_php)) |
25 | include("../functions/imap.php"); |
26 | if (!isset($date_php)) |
27 | include("../functions/date.php"); |
28 | if (!isset($mime_php)) |
29 | include("../functions/mime.php"); |
30 | if (!isset($smtp_php)) |
31 | include("../functions/smtp.php"); |
32 | if (!isset($display_messages_php)) |
33 | include("../functions/display_messages.php"); |
3c13b9fb |
34 | if (!isset($auth_php)) |
35 | include ("../functions/auth.php"); |
f7fb20fe |
36 | |
d3cdb279 |
37 | include("../src/load_prefs.php"); |
8467bf00 |
38 | |
4ba45d11 |
39 | // This function is used when not sending or adding attachments |
df15de21 |
40 | function newMail () { |
41 | global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, |
3806fa52 |
42 | $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc; |
e39d73e5 |
43 | |
2e434774 |
44 | $send_to = decodeHeader($send_to); |
45 | $send_to_cc = decodeHeader($send_to_cc); |
a53e5469 |
46 | |
429f8906 |
47 | if ($forward_id) |
48 | $id = $forward_id; |
49 | else if ($reply_id) |
50 | $id = $reply_id; |
51 | |
1195c340 |
52 | |
429f8906 |
53 | if ($id) { |
813eba2f |
54 | sqimap_mailbox_select($imapConnection, $mailbox); |
429f8906 |
55 | $message = sqimap_get_message($imapConnection, $id, $mailbox); |
1195c340 |
56 | if ($ent_num) |
57 | $message = getEntity($message, $ent_num); |
429f8906 |
58 | |
59 | if ($message->header->type0 == "text" || $message->header->type1 == "message") { |
1195c340 |
60 | if ($ent_num) |
61 | $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header->encoding); |
62 | else |
63 | $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header->encoding); |
429f8906 |
64 | } else { |
65 | $body = ""; |
df15de21 |
66 | } |
67 | |
429f8906 |
68 | if ($forward_id) |
69 | $tmp = _("-------- Original Message ---------\n"); |
70 | if ($message->header->type1 == "html") |
71 | $body = strip_tags($body); |
72 | |
df15de21 |
73 | $body_ary = explode("\n", $body); |
74 | $body = ""; |
429f8906 |
75 | for ($i=0; $i < count($body_ary); $i++) { |
1195c340 |
76 | if ($i==0 && $forward_id) |
77 | $tmp = _("-------- Original Message ---------\n") . $body_ary[$i]; |
78 | else |
79 | $tmp = $body_ary[$i]; |
429f8906 |
80 | |
81 | if ($forward_id) |
1195c340 |
82 | $body .= "$body$tmp\n"; |
df15de21 |
83 | else |
1195c340 |
84 | $body .= "$body> $tmp\n"; |
78509c54 |
85 | } |
1195c340 |
86 | return $body; |
78509c54 |
87 | } |
429f8906 |
88 | |
29d08a52 |
89 | if (!$send_to) { |
90 | $send_to = sqimap_find_email($send_to); |
91 | } |
92 | |
cf8758c7 |
93 | // $send_to = ereg_replace("\"", "", $send_to); |
df15de21 |
94 | $send_to = stripslashes($send_to); |
95 | |
96 | /** This formats a CC string if they hit "reply all" **/ |
97 | if ($send_to_cc != "") { |
98 | $send_to_cc = ereg_replace(";", ",", $send_to_cc); |
99 | $sendcc = explode(",", $send_to_cc); |
100 | $send_to_cc = ""; |
101 | |
102 | for ($i = 0; $i < count($sendcc); $i++) { |
103 | $sendcc[$i] = trim($sendcc[$i]); |
104 | if ($sendcc[$i] == "") |
105 | continue; |
106 | |
a53e5469 |
107 | $sendcc[$i] = sqimap_find_email($sendcc[$i]); |
813eba2f |
108 | $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]); |
109 | $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]); |
df15de21 |
110 | |
111 | if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) && |
112 | (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) && |
113 | (trim($sendcc[$i]) != "")) { |
114 | $send_to_cc .= trim($sendcc[$i]) . ", "; |
115 | } |
116 | } |
117 | $send_to_cc = trim($send_to_cc); |
118 | if (substr($send_to_cc, -1) == ",") { |
119 | $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1); |
120 | } |
121 | } |
122 | } // function newMail() |
78509c54 |
123 | |
df15de21 |
124 | function showInputForm () { |
125 | global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body, |
4ba45d11 |
126 | $passed_body, $color, $use_signature, $signature, $editor_size, |
3806fa52 |
127 | $attachments, $subject, $newmail, $use_javascript_addr_book, |
966286ae |
128 | $send_to_bcc, $reply_id, $mailbox; |
78509c54 |
129 | |
2e434774 |
130 | $subject = decodeHeader($subject); |
131 | $reply_subj = decodeHeader($reply_subj); |
132 | $forward_subj = decodeHeader($forward_subj); |
a53e5469 |
133 | |
3806fa52 |
134 | if ($use_javascript_addr_book) { |
135 | echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n"; |
136 | echo "function open_abook() { \n"; |
137 | echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\","; |
138 | echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n"; |
139 | echo " if((!nwin.opener) && (document.windows != null))\n"; |
140 | echo " nwin.opener = document.windows;\n"; |
141 | echo "}\n"; |
142 | echo "// --></SCRIPT>\n\n"; |
143 | } |
5100704d |
144 | |
3806fa52 |
145 | echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST ENCTYPE=\"multipart/form-data\">\n"; |
966286ae |
146 | if ($reply_id) { |
147 | echo "<input type=hidden name=reply_id value=$reply_id>\n"; |
148 | } |
cf8758c7 |
149 | printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox)); |
761d149e |
150 | echo "<TABLE WIDTH=50 ALIGN=center CELLSPACING=0 BORDER=0>\n"; |
df15de21 |
151 | echo " <TR>\n"; |
152 | echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
df15de21 |
153 | echo _("To:"); |
761d149e |
154 | echo " </TD><TD colspan=2 WIDTH=\"100%\" BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
cf8758c7 |
155 | printf(" <INPUT TYPE=text NAME=\"send_to\" VALUE=\"%s\" SIZE=60><BR>\n", |
156 | htmlspecialchars($send_to)); |
df15de21 |
157 | echo " </TD>\n"; |
158 | echo " </TR>\n"; |
159 | echo " <TR>\n"; |
160 | echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
aae41ae9 |
161 | echo _("CC:"); |
761d149e |
162 | echo " </TD><TD colspan=2 BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
cf8758c7 |
163 | printf(" <INPUT TYPE=text NAME=\"send_to_cc\" SIZE=60 VALUE=\"%s\"><BR>\n", |
164 | htmlspecialchars($send_to_cc)); |
df15de21 |
165 | echo " </TD>\n"; |
166 | echo " </TR>\n"; |
167 | echo " <TR>\n"; |
168 | echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
aae41ae9 |
169 | echo _("BCC:"); |
761d149e |
170 | echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
cf8758c7 |
171 | printf(" <INPUT TYPE=text NAME=\"send_to_bcc\" VALUE=\"%s\" SIZE=60><BR>\n", |
172 | htmlspecialchars($send_to_bcc)); |
3806fa52 |
173 | echo "</TD></TR>\n"; |
5100704d |
174 | |
df15de21 |
175 | echo " <TR>\n"; |
176 | echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
df15de21 |
177 | echo _("Subject:"); |
761d149e |
178 | echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
df15de21 |
179 | if ($reply_subj) { |
180 | $reply_subj = str_replace("\"", "'", $reply_subj); |
181 | $reply_subj = stripslashes($reply_subj); |
182 | $reply_subj = trim($reply_subj); |
183 | if (substr(strtolower($reply_subj), 0, 3) != "re:") |
184 | $reply_subj = "Re: $reply_subj"; |
cf8758c7 |
185 | printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">", |
186 | htmlspecialchars($reply_subj)); |
df15de21 |
187 | } else if ($forward_subj) { |
188 | $forward_subj = str_replace("\"", "'", $forward_subj); |
189 | $forward_subj = stripslashes($forward_subj); |
190 | $forward_subj = trim($forward_subj); |
191 | if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") && |
192 | (substr(strtolower($forward_subj), 0, 5) != "[fwd:") && |
193 | (substr(strtolower($forward_subj), 0, 6) != "[ fwd:")) |
194 | $forward_subj = "[Fwd: $forward_subj]"; |
cf8758c7 |
195 | printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">", |
196 | htmlspecialchars($forward_subj)); |
df15de21 |
197 | } else { |
cf8758c7 |
198 | printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">", |
199 | htmlspecialchars($subject)); |
31f3d7c0 |
200 | } |
480feea7 |
201 | echo "</td></tr>\n\n"; |
202 | |
203 | echo " <TR><td>\n </td><td>\n"; |
204 | if ($use_javascript_addr_book) { |
205 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\""; |
206 | echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");"; |
207 | echo " // --></SCRIPT><NOSCRIPT>\n"; |
208 | echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">"; |
209 | echo " </NOSCRIPT>\n"; |
210 | } else { |
211 | echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">"; |
212 | } |
213 | echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n"; |
214 | echo " </TD>\n"; |
215 | echo " </TR>\n\n"; |
216 | |
4ba45d11 |
217 | |
e5b23ff2 |
218 | echo " <TR>\n"; |
3806fa52 |
219 | echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=3>\n"; |
cf8758c7 |
220 | echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>"; |
221 | if ($use_signature == true && $newmail == true) { |
222 | echo htmlspecialchars($body) . "\n\n-- \n" . htmlspecialchars($signature); |
223 | } else { |
224 | echo htmlspecialchars($body); |
225 | } |
226 | echo "</TEXTAREA><BR>\n"; |
e5b23ff2 |
227 | echo " </TD>\n"; |
228 | echo " </TR>\n"; |
6c7fd6ca |
229 | echo " <TR><TD COLSPAN=3 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\""; |
e5b23ff2 |
230 | echo _("Send"); |
231 | echo "\"></TD></TR>\n"; |
232 | |
4ba45d11 |
233 | // This code is for attachments |
234 | echo " <tr>\n"; |
e5b23ff2 |
235 | echo " <TD WIDTH=50 BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n"; |
aae41ae9 |
236 | echo " <SMALL><BR></SMALL>"._("Attach:"); |
761d149e |
237 | echo " </td><td colspan=2 ALIGN=left BGCOLOR=\"$color[0]\">\n"; |
4ba45d11 |
238 | // echo " <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n"; |
239 | // echo " value=\"10000\">\n"; |
240 | echo " <INPUT NAME=\"attachfile\" TYPE=\"file\">\n"; |
469eb37b |
241 | echo " <input type=\"submit\" name=\"attach\"\n"; |
4ba45d11 |
242 | echo " value=\"" . _("Add") ."\">\n"; |
469eb37b |
243 | echo " </td>\n"; |
469eb37b |
244 | echo " </tr>\n"; |
4ba45d11 |
245 | if (isset($attachments) && count($attachments)>0) { |
e5b23ff2 |
246 | echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n"; |
247 | echo " "; |
761d149e |
248 | echo "</td><td align=left colspan=2 bgcolor=\"$color[0]\">"; |
4ba45d11 |
249 | while (list($localname, $remotename) = each($attachments)) { |
250 | echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n"; |
251 | echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n"; |
252 | } |
253 | |
254 | echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n"; |
469eb37b |
255 | echo "</td></tr>"; |
4ba45d11 |
256 | } |
4ba45d11 |
257 | // End of attachment code |
258 | |
ffc2ccbc |
259 | echo "</TABLE>\n"; |
df15de21 |
260 | echo "</FORM>"; |
31f3d7c0 |
261 | } |
8467bf00 |
262 | |
df15de21 |
263 | function showSentForm () { |
df15de21 |
264 | echo "<BR><BR><BR><CENTER><B>Message Sent!</B><BR><BR>"; |
9f2215a1 |
265 | echo "You will be automatically forwarded.<BR>If not, <A HREF=\"right_main.php\">click here</A>"; |
aae41ae9 |
266 | echo "</CENTER>"; |
df15de21 |
267 | } |
b278172f |
268 | |
0ad7dbda |
269 | function checkInput ($show) { |
270 | /** I implemented the $show variable because the error messages |
271 | were getting sent before the page header. So, I check once |
272 | using $show=false, and then when i'm ready to display the |
273 | error message, show=true **/ |
274 | global $body, $send_to, $subject, $color; |
b278172f |
275 | |
1e62a204 |
276 | if ($body == "" && $subject == "") { |
0ad7dbda |
277 | if ($show) |
1e62a204 |
278 | plain_error_message(_("You have not entered a message body or a subject."), $color); |
df15de21 |
279 | return false; |
280 | } else if ($send_to == "") { |
0ad7dbda |
281 | if ($show) |
282 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
df15de21 |
283 | return false; |
b278172f |
284 | } |
df15de21 |
285 | return true; |
286 | } // function checkInput() |
287 | |
3806fa52 |
288 | |
ecf51658 |
289 | if (($mailbox == "") || ($mailbox == "None")) |
dcb7f454 |
290 | $mailbox = "INBOX"; |
3806fa52 |
291 | |
4ba45d11 |
292 | if(isset($send)) { |
0ad7dbda |
293 | if (checkInput(false)) { |
966286ae |
294 | $urlMailbox = urlencode ($mailbox); |
295 | sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id); |
296 | header ("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1"); |
df15de21 |
297 | } else { |
e1469126 |
298 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
dcb7f454 |
299 | displayPageHeader($color, $mailbox); |
0ad7dbda |
300 | checkInput(true); |
301 | |
df15de21 |
302 | showInputForm(); |
1195c340 |
303 | sqimap_logout($imapConnection); |
7c6cb7ca |
304 | } |
3806fa52 |
305 | } else if ($html_addr_search_done) { |
3c13b9fb |
306 | is_logged_in(); |
dcb7f454 |
307 | displayPageHeader($color, $mailbox); |
3806fa52 |
308 | |
309 | $body = stripslashes($body); |
310 | $send_to = stripslashes($send_to); |
311 | $send_to_cc = stripslashes($send_to_cc); |
312 | $send_to_bcc = stripslashes($send_to_bcc); |
313 | $subject = stripslashes($subject); |
314 | |
6c7fd6ca |
315 | for ($i=0; $i < count($send_to_search); $i++) { |
316 | if ($send_to) |
317 | $send_to .= ", "; |
318 | $send_to .= $send_to_search[$i]; |
319 | } |
320 | |
321 | for ($i=0; $i < count($send_to_cc_search); $i++) { |
322 | if ($send_to_cc) |
323 | $send_to_cc .= ", "; |
324 | $send_to_cc .= $send_to_cc_search[$i]; |
325 | } |
326 | |
3806fa52 |
327 | showInputForm(); |
6c7fd6ca |
328 | } else if ($html_addr_search) { |
591d2a88 |
329 | // I am using an include so as to elminiate an extra unnecessary click. If you |
330 | // can think of a better way, please implement it. |
6c7fd6ca |
331 | include ("addrbook_search_html.php"); |
4ba45d11 |
332 | } else if (isset($attach)) { |
3c13b9fb |
333 | is_logged_in(); |
dcb7f454 |
334 | displayPageHeader($color, $mailbox); |
fc3348ac |
335 | |
4ba45d11 |
336 | $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy"); |
c3c37167 |
337 | $localfilename = $localfilename; |
4ba45d11 |
338 | |
339 | // Put the file in a better place |
340 | error_reporting(0); // Rename will produce error output if it fails |
c3c37167 |
341 | if (!rename($attachfile, $attachment_dir.$localfilename)) { |
342 | if (!copy($attachfile, $attachment_dir.$localfilename)) { |
4ba45d11 |
343 | plain_error_message(_("Could not move/copy file. File not attached")); |
c3c37167 |
344 | $failed = true; |
4ba45d11 |
345 | } |
346 | } |
347 | // If it still exists, PHP will remove the original file |
348 | |
c3c37167 |
349 | if (!$failed) { |
350 | // Write information about the file |
351 | $fp = fopen ($attachment_dir.$localfilename.".info", "w"); |
352 | fputs ($fp, "$attachfile_type\n$attachfile_name\n"); |
353 | fclose ($fp); |
4ba45d11 |
354 | |
c3c37167 |
355 | $attachments[$localfilename] = $attachfile_name; |
356 | } |
4ba45d11 |
357 | |
358 | showInputForm(); |
359 | } else if (isset($do_delete)) { |
3c13b9fb |
360 | is_logged_in(); |
dcb7f454 |
361 | displayPageHeader($color, $mailbox); |
fc3348ac |
362 | |
4ba45d11 |
363 | while (list($key, $localname) = each($delete)) { |
a53e5469 |
364 | array_splice ($attachments, $key, 1); |
c3c37167 |
365 | unlink ($attachment_dir.$localname); |
366 | unlink ($attachment_dir.$localname.".info"); |
4ba45d11 |
367 | } |
4bfed9f3 |
368 | |
4ba45d11 |
369 | showInputForm(); |
370 | } else { |
a60b9989 |
371 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
dcb7f454 |
372 | displayPageHeader($color, $mailbox); |
fc3348ac |
373 | |
b57c4e63 |
374 | $newmail = true; |
1220e677 |
375 | newMail(); |
4ba45d11 |
376 | showInputForm(); |
1195c340 |
377 | sqimap_logout($imapConnection); |
4ba45d11 |
378 | } |
da79853a |
379 | ?> |