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