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