Added attachments support when sending mail (alfa quality).
authorgustavf <gustavf@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 1 Feb 2000 13:58:51 +0000 (13:58 +0000)
committergustavf <gustavf@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 1 Feb 2000 13:58:51 +0000 (13:58 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@190 7612ce4b-ef26-0410-bec9-ea0150e637f0

config/config.php [new file with mode: 0644]
functions/smtp.php
src/compose.php

diff --git a/config/config.php b/config/config.php
new file mode 100644 (file)
index 0000000..bf37760
--- /dev/null
@@ -0,0 +1,136 @@
+<?
+//  Organization's logo picture (blank if none)
+    $org_logo = "../images/sm_logo.jpg";
+
+//  Organization's name
+    $org_name = "SquirrelMail";
+
+//  Webmail Title
+//  This is the title that goes at the top of the browser window
+    $org_title = "SquirrelMail $version";
+
+//  The server that your imap server is on
+    $imapServerAddress = "localhost";
+    $imapPort = 143;
+
+//  The domain where your email address is.
+//   Example:  in "luke@usa.om.org", usa.om.org is the domain.
+//             this is for all the messages sent out.  Reply address
+//             is generated by $username@$domain
+    $domain = "initio.no";
+
+//  Your SMTP server and port number (usually the same as the IMAP server)
+    $smtpServerAddress = "localhost";
+    $smtpPort = 25;
+
+//  Uncomment this if you want to deliver locally using sendmail instead
+//  of connecting to a SMTP-server
+    $useSendmail = true;
+    $sendmail_path = "/usr/sbin/sendmail";
+
+//  This is displayed right after they log in
+    $motd = "You are using SquirrelMail's web-based email client.  If you run into any bugs or have suggestions, please report them to our <A HREF=\"mailto:squirrelmail-list@sourceforge.net\">mailing list</A>";
+
+//  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/";
+?>
index 259b698e2a9ae3d8adbb698fb456aab91e290266..5a71dc516360120dd72e079ebf1755a6d920b009 100644 (file)
 
    // 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;
         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");
index 1ba81ee270e792deba71df912065c63802ce66d6..ed4e4e2ff1d73b3298692a60b3aa571a76be7787 100644 (file)
@@ -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;
 
    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<FORM action=\"compose.php\" METHOD=GET>\n";
+      echo "\n<FORM action=\"compose.php\" METHOD=POST\n";
+      echo "ENCTYPE=\"multipart/form-data\">\n";
       echo "<TABLE COLS=2 WIDTH=50 ALIGN=CENTER CELLSPACING=0 BORDER=0>\n";
       echo "   <TR>\n";
       echo "      <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
       echo "   </TR>\n";
       echo "   <TR>\n";
       echo "      <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
-      echo "         <FONT FACE=\"Arial,Helvetica\">CC:</FONT>\n";
+      echo "         <FONT FACE=\"Arial,Helvetica\">"._("CC").":</FONT>\n";
       echo "      </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
       if ($send_to_cc)
          echo "         <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60 VALUE=\"$send_to_cc\"><BR>";
       echo "\"><BR>\n";
       echo "      </TD>\n";
       echo "   </TR>\n";
+
+      // This code is for attachments
+      echo "   <tr>\n";
+      echo "     <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
+      echo "      <FONT FACE=\"Arial,Helvetica\">";
+      echo "      "._("Attach:")."</FONT>\n";
+      echo "      </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
+      //      echo "      <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
+      //      echo "      value=\"10000\">\n";
+      echo "      <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
+      echo "      &nbsp&nbsp<input type=\"submit\" name=\"attach\"\n";
+      echo "      value=\"" . _("Add") ."\">\n";
+      echo "      <br>";
+      if (isset($attachments) && count($attachments)>0) {
+         while (list($localname, $remotename) = each($attachments)) {
+            echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
+            echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
+         }
+         
+         echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
+
+      }
+      echo "     </td>\n";
+      echo "     </font>\n";
+      echo "   </tr>\n";
+      // End of attachment code
+
       echo "   <TR>\n";
       echo "      <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
       if ($use_signature == true)
       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();
+   }
 ?>