From 4ba45d11cf8f031150a21de5e345b613f02aac7f Mon Sep 17 00:00:00 2001 From: gustavf Date: Tue, 1 Feb 2000 13:58:51 +0000 Subject: [PATCH] Added attachments support when sending mail (alfa quality). git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@190 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- config/config.php | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++ functions/smtp.php | 36 ++++++++++++-- src/compose.php | 81 ++++++++++++++++++++++++++----- 3 files changed, 237 insertions(+), 16 deletions(-) create mode 100644 config/config.php diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..bf37760 --- /dev/null +++ b/config/config.php @@ -0,0 +1,136 @@ +mailing list"; + +// Themes +// You can define your own theme and put it in this directory. You must +// call it as the example below. You can name the theme whatever you +// want. For an example of a theme, see the ones included in the config +// directory. +// +// You can download themes from http://squirrelmail.sourceforge.net/index.php3?page=10 +// +// To add a new theme to the options that users can choose from, just add +// a new number to the array at the bottom, and follow the pattern. + + // The first one HAS to be here, and is your system's default theme. + // It can be any theme you want + $theme[0]["PATH"] = "../config/default_theme.php"; + $theme[0]["NAME"] = "Default"; + + $theme[1]["PATH"] = "../config/sandstorm_theme.php"; + $theme[1]["NAME"] = "Sand Storm"; + + $theme[2]["PATH"] = "../config/deepocean_theme.php"; + $theme[2]["NAME"] = "Deep Ocean"; + + $theme[3]["PATH"] = "../config/slashdot_theme.php"; + $theme[3]["NAME"] = "Slashdot"; + + $theme[4]["PATH"] = "../config/purple_theme.php"; + $theme[4]["NAME"] = "Purple"; + + $theme[5]["PATH"] = "../config/forest_theme.php"; + $theme[5]["NAME"] = "Forest"; + + $theme[6]["PATH"] = "../config/ice_theme.php"; + $theme[6]["NAME"] = "Ice"; + +// Whether or not to use a special color for special folders. If not, special +// folders will be the same color as the other folders + $use_special_folder_color = true; + +/* The following are related to deleting messages. + * $move_to_trash + * - if this is set to "true", when "delete" is pressed, it will attempt + * to move the selected messages to the folder named $trash_folder. If + * it's set to "false", we won't even attempt to move the messages, just + * delete them. + * $trash_folder + * - This is the path to the default trash folder. For Cyrus IMAP, it + * would be "INBOX.Trash", but for UW it would be "Trash". We need the + * full path name here. + * $auto_expunge + * - If this is true, when a message is moved or copied, the source mailbox + * will get expunged, removing all messages marked "Deleted". + */ + + $default_move_to_trash = true; + $trash_folder = "INBOX.Trash"; + $auto_expunge = true; + +// Special Folders are folders that can't be manipulated like normal user created +// folders can. A couple of examples would be "INBOX.Trash", "INBOX.Drafts". We have +// them set to Netscape's default mailboxes, but this obviously can be changed. +// To add one, just add a new number to the array. + + $special_folders[0] = "INBOX"; // The first one has to be the inbox (whatever the name is) + $special_folders[1] = $trash_folder; + $special_folders[2] = "INBOX.Sent"; + $special_folders[3] = "INBOX.Drafts"; + $special_folders[4] = "INBOX.Templates"; + +// Whether or not to list the special folders first (true/false) + $list_special_folders_first = true; + +// Are all your folders subfolders of INBOX (i.e. cyrus IMAP server) +// If you are not sure, set it to false. + $default_sub_of_inbox = true; + +// Some IMAP daemons (UW) handle folders weird. They only allow a folder to contain +// either messages or other folders, not both at the same time. This option controls +// whether or not to display an option during folder creation. The option toggles +// which type of folder it should be. +// +// If this option confuses you, make it "true". You can't hurt anything if it's true, +// but some servers will respond weird if it's false. (Cyrus works fine whether it's +// true OR false). + $show_contain_subfolders_option = false; + +// Whether or not to use META tags and automatically forward after an action has +// been completed. + $auto_forward = true; + +// Path to the data/ directory +// It is a possible security hole to have a writable directory under the web server's +// root directory (ex: /home/httpd/html). For this reason, it is possible to put +// the data directory anywhere you would like. The path name can be absolute or +// relative (to the config directory). It doesn't matter. Here are two examples: +// +// Absolute: +// $data_dir = "/usr/local/squirrelmail/data/"; +// +// Relative (to the config directory): +// $data_dir = "../data/"; + + $data_dir = "../data/"; +?> diff --git a/functions/smtp.php b/functions/smtp.php index 259b698..5a71dc5 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -11,12 +11,39 @@ // Returns true only if this message is multipart function isMultipart () { - return true; + global $attachments; + + if (count($attachments)>0) + return true; + else + return false; } // Attach the files that are due to be attached - function attachFile ($fp) { - return false; + function attachFiles ($fp) { + global $attachments; + + while (list($localname, $remotename) = each($attachments)) { + $fileinfo = fopen ($localname.".info", "r"); + $filetype = fgets ($fileinfo, 8192); + fclose ($fileinfo); + $filetype = trim ($filetype); + if ($filetype=="") + $filetype = "application/octet-stream"; + + fputs ($fp, "--".mimeBoundary()."\n"); + fputs ($fp, "Content-Type: $filetype\n"); + fputs ($fp, "Content-Disposition: attachment; filename=\"$remotename\"\n"); + fputs ($fp, "Content-Transfer-Encoding: base64\n\n"); + + $file = fopen ($localname, "r"); + while ($tmp = fread($file, 57)) + fputs ($fp, chunk_split(base64_encode($tmp))); + fclose ($file); + + unlink ($localname); + unlink ($localname.".info"); + } } // Return a nice MIME-boundary @@ -27,7 +54,7 @@ if ($mimeBoundaryString == "") { $temp = "SquirrelMail".$version.$REMOTE_ADDR.$SERVER_NAME. $REMOTE_PORT; - $mimeBoundaryString = "=-=_=-SqMB.".substr(md5($temp),1,15); + $mimeBoundaryString = "=-_+".substr(md5($temp),1,20); } return $mimeBoundaryString; @@ -103,6 +130,7 @@ fputs ($fp, "Content-Type: text/plain; charset=ISO-8859-1\n"); fputs ($fp, "Content-Transfer-Encoding: 8bit\n\n"); fputs ($fp, "$body\n"); + attachFiles($fp); fputs ($fp, "\n--".mimeBoundary()."--\n"); } else { fputs ($fp, "$body\n"); diff --git a/src/compose.php b/src/compose.php index 1ba81ee..ed4e4e2 100644 --- a/src/compose.php +++ b/src/compose.php @@ -23,7 +23,7 @@ $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 0); displayPageHeader($color, "None"); - // This function is used + // This function is used when not sending or adding attachments function newMail () { global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, $reply_id, $send_to, $send_to_cc, $mailbox; @@ -142,9 +142,11 @@ function showInputForm () { global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body, - $passed_body, $color, $use_signature, $signature, $editor_size; + $passed_body, $color, $use_signature, $signature, $editor_size, + $attachments, $subject; - echo "\n
\n"; + echo "\n\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; + + // This code is for attachments + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + // End of attachment code + echo " \n"; echo "
\n"; @@ -160,7 +162,7 @@ echo "
\n"; - echo " CC:\n"; + echo " "._("CC").":\n"; echo " \n"; if ($send_to_cc) echo "
"; @@ -208,6 +210,33 @@ echo "\">
\n"; echo "
\n"; + echo " "; + echo " "._("Attach:")."\n"; + echo " \n"; + // echo " \n"; + echo " \n"; + echo "   \n"; + echo "
"; + if (isset($attachments) && count($attachments)>0) { + while (list($localname, $remotename) = each($attachments)) { + echo "\n"; + echo "$remotename
\n"; + } + + echo "\n"; + + } + echo "
\n"; if ($use_signature == true) @@ -234,29 +263,57 @@ global $body, $send_to, $subject; if ($body == "") { - plain_error_message("You have not entered a message body.", $color); + plain_error_message(_("You have not entered a message body."), $color); return false; } else if ($send_to == "") { displayPageHeader($color, "None"); - plain_error_message("You have not filled in the \"To:\" field.", $color); + plain_error_message(_("You have not filled in the \"To:\" field."), $color); return false; } else if ($subject == "") { - plain_error_message("You have not entered a subject.", $color); + plain_error_message(_("You have not entered a subject."), $color); return false; } return true; } // function checkInput() - if (!isset($send)) { - newMail(); - showInputForm(); - } else if(isset($send)) { + if(isset($send)) { if (checkInput()) { sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body); showSentForm(); } else { showInputForm(); } - } + } else if (isset($attach)) { + $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy"); + $localfilename = $data_dir.$localfilename; + + // Put the file in a better place + error_reporting(0); // Rename will produce error output if it fails + if (!rename($attachfile, $localfilename)) { + if (!copy($attachfile, $localfilename)) { + plain_error_message(_("Could not move/copy file. File not attached")); + } + } + // If it still exists, PHP will remove the original file + + // Write information about the file + $fp = fopen ($localfilename.".info", "w"); + fputs ($fp, "$attachfile_type\n$attachfile_name\n"); + fclose ($fp); + + $attachments[$localfilename] = $attachfile_name; + + showInputForm(); + } else if (isset($do_delete)) { + while (list($key, $localname) = each($delete)) { + array_splice ($attachments, $localname, 1); + unlink ($localname); + unlink ($localname.".info"); + } + showInputForm(); + } else { + Newmail(); + showInputForm(); + } ?> -- 1.9.1