Explorar o código

Fixed major problems with IMAP session handling in the MIME code. This
fixed a bunch of bugs including "reply", "forward", and the weird attachment
problem I was having.

Luke Ehresman %!s(int64=25) %!d(string=hai) anos
pai
achega
3a9c042add
Modificáronse 5 ficheiros con 26 adicións e 23 borrados
  1. 2 0
      ChangeLog
  2. 3 3
      functions/imap_messages.php
  3. 4 11
      functions/mime.php
  4. 16 8
      src/compose.php
  5. 1 1
      src/read_body.php

+ 2 - 0
ChangeLog

@@ -1,5 +1,7 @@
 Version 0.5pre1 -- DEVELOPMENT
 ------------------------------
+- Removed a bunch of annoying "success" screens
+- Better IMAP session handling
 - Redid the options section and split it into different parts
 - Added "view all headers" option when reading a message
 - In-Reply-To and References headers are inserted when replying to a message.

+ 3 - 3
functions/imap_messages.php

@@ -117,7 +117,7 @@
     ******************************************************************************/
    function sqimap_get_message ($imap_stream, $id, $mailbox) {
       $header = sqimap_get_message_header($imap_stream, $id, $mailbox);
-      $msg = sqimap_get_message_body(&$header);
+      $msg = sqimap_get_message_body($imap_stream, &$header);
       return $msg;
    }
 
@@ -326,7 +326,7 @@
    /******************************************************************************
     **  Returns the body of a message.
     ******************************************************************************/
-   function sqimap_get_message_body (&$header) {
+   function sqimap_get_message_body ($imap_stream, &$header) {
       $id = $header->id;
       //fputs ($imap_stream, "a001 FETCH $id:$id BODY[TEXT]\r\n");
       //$read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
@@ -342,7 +342,7 @@
          $i++;
       }
       */
-      return decodeMime($body, &$header);
+      return decodeMime($imap_stream, $body, &$header);
    }
 
 

+ 4 - 11
functions/mime.php

@@ -59,6 +59,7 @@
       $id = $header->id;
       fputs ($imap_stream, "a001 FETCH $id BODYSTRUCTURE\r\n");
       $read = fgets ($imap_stream, 10000);
+      $endline = fgets($imap_stream, 1024);
       $read = strtolower($read);
 
       if ($debug_mime) echo "<tt>$read</tt><br><br>";
@@ -360,13 +361,9 @@
    /** This is the first function called.  It decides if this is a multipart
        message or if it should be handled as a single entity
     **/
-   function decodeMime ($body, $header) {
+   function decodeMime ($imap_stream, $body, $header) {
       global $username, $key, $imapServerAddress, $imapPort;
-      $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-      sqimap_mailbox_select($imap_stream, $header->mailbox);
-      $struct = mime_structure ($imap_stream, $header);
-      sqimap_logout($imap_stream);
-      return $struct;
+      return mime_structure ($imap_stream, $header);
    }
 
    // This is here for debugging purposese.  It will print out a list
@@ -420,7 +417,7 @@
        everything needed, including HTML Tags, Attachments at the
        bottom, etc.
     **/
-   function formatBody($message, $color, $wrap_at) {
+   function formatBody($imap_stream, $message, $color, $wrap_at) {
       // this if statement checks for the entity to show as the
       // primary message. To add more of them, just put them in the
       // order that is their priority.
@@ -429,12 +426,8 @@
       $id = $message->header->id;
       $urlmailbox = urlencode($message->header->mailbox);
 
-      $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-      sqimap_mailbox_select($imap_stream, $message->header->mailbox);
-
       $ent_num = findDisplayEntity ($message);
       $body = mime_fetch_body ($imap_stream, $id, $ent_num); 
-      sqimap_logout($imap_stream); 
 
       // If there are other types that shouldn't be formatted, add
       // them here 

+ 16 - 8
src/compose.php

@@ -53,6 +53,7 @@
       if ($id) {
          sqimap_mailbox_select($imapConnection, $mailbox);
          $message = sqimap_get_message($imapConnection, $id, $mailbox);
+         $orig_header = $message->header;
          if ($ent_num)
             $message = getEntity($message, $ent_num);
 
@@ -65,23 +66,30 @@
             $body = "";
          }
          
-         if ($forward_id)
-            $tmp = _("-------- Original Message ---------\n");
          if ($message->header->type1 == "html")
             $body = strip_tags($body);
             
          $body_ary = explode("\n", $body);
          $body = "";
          for ($i=0; $i < count($body_ary); $i++) {
-            if ($i==0 && $forward_id)
-               $tmp = _("-------- Original Message ---------\n") . $body_ary[$i];
-            else
+            if ($i==0 && $forward_id) {
+               $tmp = _("-------- Original Message ---------\n");
+               $tmp .= _("Subject") . ": " . $orig_header->subject . "\n"; 
+               $tmp .= "   " . _("From") . ": " . $orig_header->from . "\n"; 
+               $tmp .= "     " . _("To") . ": " . $orig_header->to[0] . "\n"; 
+               if (count($orig_header->to) > 1) {
+                  for ($x=1; $x < count($orig_header->to); $x++) {
+                     $tmp .= "         " . $orig_header->to[$x] . "\n";
+                  }
+               }
+               $tmp .= "\n" . $body_ary[$i];
+            } else {
                $tmp = $body_ary[$i];
-            
+            }
             if ($forward_id)
-               $body .= "$body$tmp\n";
+               $body = "$body$tmp\n";
             else
-               $body .= "$body> $tmp\n";
+               $body = "$body> $tmp\n";
          }
          return $body;   
       }

+ 1 - 1
src/read_body.php

@@ -273,7 +273,7 @@
    echo "   </TD></TR>";
 
    echo "   <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
-   $body = formatBody($message, $color, $wrap_at);
+   $body = formatBody($imapConnection, $message, $color, $wrap_at);
    echo "<BR>";
 
    echo "$body";