added step for copying config_default.php to config.php
[squirrelmail.git] / src / compose.php
CommitLineData
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");
14 include("../functions/mailbox.php");
15 include("../functions/date.php");
f7fb20fe 16 include("../functions/mime.php");
df15de21 17 include("../functions/smtp.php");
18 include("../functions/display_messages.php");
f7fb20fe 19
d3cdb279 20 include("../src/load_prefs.php");
8467bf00 21
f8f9bed9 22 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
b235d629 23 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 0);
f8f9bed9 24 displayPageHeader($color, "None");
31f3d7c0 25
df15de21 26 // This function is used
27 function newMail () {
28 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
29 $reply_id, $send_to, $send_to_cc, $mailbox;
e39d73e5 30
df15de21 31 if ($forward_id) {
32 selectMailbox($imapConnection, $mailbox, $numMessages);
33 $msg = fetchMessage($imapConnection, $forward_id, $mailbox);
34
35 if (containsType($msg, "text", "html", $ent_num)) {
78509c54 36 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
df15de21 37 } else if (containsType($msg, "text", "plain", $ent_num)) {
78509c54 38 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
df15de21 39 }
40 // add other primary displaying msg types here
41 else {
42 // find any type that's displayable
43 if (containsType($msg, "text", "any_type", $ent_num)) {
44 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
45 } else if (containsType($msg, "msg", "any_type", $ent_num)) {
46 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
47 } else {
48 $body = _("No Message");
49 }
50 }
51
52 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
53
54 $tmp = _("-------- Original Message ---------\n");
55 $body_ary = explode("\n", $body);
56 $body = "";
57 for ($i=0;$i < count($body_ary);$i++) {
58 if ($type1 == "html")
59 $tmp .= strip_tags($body_ary[$i]);
60 else
61 $tmp .= $body_ary[$i];
62 $body = "$body$tmp\n";
63 $tmp = "";
78509c54 64 }
65 }
df15de21 66
67 if ($reply_id) {
68 selectMailbox($imapConnection, $mailbox, $numMessages);
69 $msg = fetchMessage($imapConnection, $reply_id, $mailbox);
70
71 if (containsType($msg, "text", "html", $ent_num)) {
78509c54 72 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
df15de21 73 } else if (containsType($msg, "text", "plain", $ent_num)) {
78509c54 74 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
df15de21 75 }
76 // add other primary displaying msg types here
77 else {
78 // find any type that's displayable
79 if (containsType($msg, "text", "any_type", $ent_num)) {
80 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
81 } else if (containsType($msg, "msg", "any_type", $ent_num)) {
82 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
83 } else {
84 $body = _("No Message");
85 }
86 }
87
88 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
89
90 $body_ary = explode("\n", $body);
91 $body = "";
92 for ($i=0;$i < count($body_ary);$i++) {
93 if ($type1 == "html")
94 $tmp = strip_tags($body_ary[$i]);
95 else
96 $tmp = $body_ary[$i];
97 $body = "$body> $tmp\n";
78509c54 98 }
99 }
df15de21 100
101 // Add some decoding information
102 $send_to = encodeEmailAddr($send_to);
103 // parses the field and returns only the email address
104 $send_to = decodeEmailAddr($send_to);
105
106 $send_to = strtolower($send_to);
107 $send_to = ereg_replace("\"", "", $send_to);
108 $send_to = stripslashes($send_to);
109
110 /** This formats a CC string if they hit "reply all" **/
111 if ($send_to_cc != "") {
112 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
113 $sendcc = explode(",", $send_to_cc);
114 $send_to_cc = "";
115
116 for ($i = 0; $i < count($sendcc); $i++) {
117 $sendcc[$i] = trim($sendcc[$i]);
118 if ($sendcc[$i] == "")
119 continue;
120
121 $sendcc[$i] = encodeEmailAddr($sendcc[$i]);
122 $sendcc[$i] = decodeEmailAddr($sendcc[$i]);
123
124 $whofrom = encodeEmailAddr($msg["HEADER"]["FROM"]);
125 $whofrom = decodeEmailAddr($whofrom);
126
127 $whoreplyto = encodeEmailAddr($msg["HEADER"]["REPLYTO"]);
128 $whoreplyto = decodeEmailAddr($whoreplyto);
129
130 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
131 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
132 (trim($sendcc[$i]) != "")) {
133 $send_to_cc .= trim($sendcc[$i]) . ", ";
134 }
135 }
136 $send_to_cc = trim($send_to_cc);
137 if (substr($send_to_cc, -1) == ",") {
138 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
139 }
140 }
141 } // function newMail()
78509c54 142
df15de21 143 function showInputForm () {
144 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
145 $passed_body, $color, $use_signature, $signature, $editor_size;
78509c54 146
df15de21 147 echo "\n<FORM action=\"compose.php\" METHOD=GET>\n";
148 echo "<TABLE COLS=2 WIDTH=50 ALIGN=CENTER CELLSPACING=0 BORDER=0>\n";
149 echo " <TR>\n";
150 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
151 echo " <FONT FACE=\"Arial,Helvetica\">";
152 echo _("To:");
153 echo " </FONT>\n";
154 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
155 if ($send_to)
156 echo " <INPUT TYPE=TEXT NAME=send_to VALUE=\"$send_to\" SIZE=60><BR>";
157 else
158 echo " <INPUT TYPE=TEXT NAME=send_to SIZE=60><BR>";
159 echo " </TD>\n";
160 echo " </TR>\n";
161 echo " <TR>\n";
162 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
163 echo " <FONT FACE=\"Arial,Helvetica\">CC:</FONT>\n";
164 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
165 if ($send_to_cc)
166 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60 VALUE=\"$send_to_cc\"><BR>";
167 else
168 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60><BR>";
169 echo " </TD>\n";
170 echo " </TR>\n";
171 echo " <TR>\n";
172 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
173 echo " <FONT FACE=\"Arial,Helvetica\">BCC:</FONT>\n";
174 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
175 if ($send_to_bcc)
176 echo " <INPUT TYPE=TEXT NAME=send_to_bcc VALUE=\"$send_to_bcc\" SIZE=60><BR>";
177 else
178 echo " <INPUT TYPE=TEXT NAME=send_to_bcc 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";
183 echo " <FONT FACE=\"Arial,Helvetica\">";
184 echo _("Subject:");
185 echo " </FONT>\n";
186 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
187 if ($reply_subj) {
188 $reply_subj = str_replace("\"", "'", $reply_subj);
189 $reply_subj = stripslashes($reply_subj);
190 $reply_subj = trim($reply_subj);
191 if (substr(strtolower($reply_subj), 0, 3) != "re:")
192 $reply_subj = "Re: $reply_subj";
193 echo " <INPUT TYPE=TEXT NAME=subject SIZE=60 VALUE=\"$reply_subj\">";
194 } else if ($forward_subj) {
195 $forward_subj = str_replace("\"", "'", $forward_subj);
196 $forward_subj = stripslashes($forward_subj);
197 $forward_subj = trim($forward_subj);
198 if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
199 (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
200 (substr(strtolower($forward_subj), 0, 6) != "[ fwd:"))
201 $forward_subj = "[Fwd: $forward_subj]";
202 echo " <INPUT TYPE=TEXT NAME=subject SIZE=60 VALUE=\"$forward_subj\">";
203 } else {
204 echo " <INPUT TYPE=TEXT NAME=subject VALUE=\"$subject\" SIZE=60>";
31f3d7c0 205 }
df15de21 206 echo " &nbsp;&nbsp;<INPUT TYPE=SUBMIT NAME=send VALUE=\"";
207 echo _("Send");
208 echo "\"><BR>\n";
209 echo " </TD>\n";
210 echo " </TR>\n";
211 echo " <TR>\n";
212 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
213 if ($use_signature == true)
214 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>$body\n\n$signature</TEXTAREA><BR>";
215 else
216 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>$body</TEXTAREA><BR>\n";
217 echo " </TD>\n";
218 echo " </TR>\n";
219 echo "</TABLE>\n";
220 echo "<CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\"";
221 echo _("Send");
222 echo "\"></CENTER>";
223 echo "</FORM>";
31f3d7c0 224 }
8467bf00 225
df15de21 226 function showSentForm () {
227 echo "<FONT FACE=\"Arial,Helvetica\">";
228 echo "<BR><BR><BR><CENTER><B>Message Sent!</B><BR><BR>";
229 echo "You will be automatically forwarded.<BR>If not, <A HREF=\"right_main.php\">click here</A>";
230 echo "</CENTER></FONT>";
231 }
b278172f 232
df15de21 233 function checkInput () {
234 global $body, $send_to, $subject;
b278172f 235
df15de21 236 if ($body == "") {
237 plain_error_message("You have not entered a message body.", $color);
238 return false;
239 } else if ($send_to == "") {
240 displayPageHeader($color, "None");
241 plain_error_message("You have not filled in the \"To:\" field.", $color);
242 return false;
243 } else if ($subject == "") {
244 plain_error_message("You have not entered a subject.", $color);
245 return false;
b278172f 246 }
df15de21 247 return true;
248 } // function checkInput()
249
250 if (!isset($send)) {
251 newMail();
252 showInputForm();
253 } else if(isset($send)) {
254 if (checkInput()) {
255 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body);
256 showSentForm();
257 } else {
258 showInputForm();
7c6cb7ca 259 }
4bfed9f3 260 }
261
da79853a 262?>