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