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