Fixed PGP inline encrypted message decryption.
authorWerner Koch <wk@gnupg.org>
Thu, 7 Feb 2008 11:46:47 +0000 (11:46 +0000)
committerWerner Koch <wk@gnupg.org>
Thu, 7 Feb 2008 11:46:47 +0000 (11:46 +0000)
src/ChangeLog
src/mapihelp.cpp
src/message.cpp

index 5e6f671..76092c2 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-07  Werner Koch  <wk@g10code.com>
+
+       * message.cpp (message_wipe_body_cruft): Delete only encrypted
+       messages.
+
 2008-02-06  Werner Koch  <wk@g10code.com>
 
        * mimeparser.c (mime_decrypt): New arg IS_RFC822.
index fde1751..f3f2073 100644 (file)
@@ -1777,7 +1777,7 @@ mapi_has_last_decrypted (LPMESSAGE message)
 
 
 /* Returns True if MESSAGE has a GpgOL Last Decrypted property and
-   that matches the curren sessiobn. */
+   that matches the current session. */
 int
 mapi_test_last_decrypted (LPMESSAGE message)
 {
@@ -1787,10 +1787,10 @@ mapi_test_last_decrypted (LPMESSAGE message)
   int yes = 0;
 
   if (get_gpgollastdecrypted_tag (message, &tag) )
-    return 0; /* No.  */
+    goto leave; /* No.  */
   hr = HrGetOneProp ((LPMAPIPROP)message, tag, &propval);
   if (FAILED (hr))
-    return 0; /* No.  */  
+    goto leave; /* No.  */  
 
   if (PROP_TYPE (propval->ulPropTag) == PT_BINARY
       && propval->Value.bin.cb == 8
@@ -1798,6 +1798,9 @@ mapi_test_last_decrypted (LPMESSAGE message)
     yes = 1;
 
   MAPIFreeBuffer (propval);
+ leave:
+  log_debug ("%s:%s: message decrypted during this session: %s\n",
+             SRCNAME, __func__, yes?"yes":"no");
   return yes;
 }
 
index 5bcb293..67cf695 100644 (file)
@@ -190,44 +190,63 @@ message_wipe_body_cruft (LPEXCHEXTCALLBACK eecb)
   hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
   if (SUCCEEDED (hr))
     {
-      if (mapi_has_last_decrypted (message))
+      switch (mapi_get_message_type (message))
         {
-          SPropTagArray proparray;
-          int anyokay = 0;
-          
-          proparray.cValues = 1;
-          proparray.aulPropTag[0] = PR_BODY;
-          hr = message->DeleteProps (&proparray, NULL);
-          if (hr)
-            log_debug_w32 (hr, "%s:%s: deleting PR_BODY failed",
-                           SRCNAME, __func__);
-          else
-            anyokay++;
-          
-          proparray.cValues = 1;
-          proparray.aulPropTag[0] = PR_BODY_HTML;
-          message->DeleteProps (&proparray, NULL);
-          if (hr)
-            log_debug_w32 (hr, "%s:%s: deleting PR_BODY_HTML failed", 
-                           SRCNAME, __func__);
-          else
-            anyokay++;
+        case MSGTYPE_GPGOL_MULTIPART_ENCRYPTED:
+        case MSGTYPE_GPGOL_OPAQUE_ENCRYPTED:
+          {
+            if (mapi_has_last_decrypted (message))
+              {
+                SPropTagArray proparray;
+                int anyokay = 0;
+            
+                proparray.cValues = 1;
+                proparray.aulPropTag[0] = PR_BODY;
+                hr = message->DeleteProps (&proparray, NULL);
+                if (hr)
+                  log_debug_w32 (hr, "%s:%s: deleting PR_BODY failed",
+                                 SRCNAME, __func__);
+                else
+                  anyokay++;
+            
+                proparray.cValues = 1;
+                proparray.aulPropTag[0] = PR_BODY_HTML;
+                message->DeleteProps (&proparray, NULL);
+                if (hr)
+                  log_debug_w32 (hr, "%s:%s: deleting PR_BODY_HTML failed", 
+                                 SRCNAME, __func__);
+                else
+                  anyokay++;
+
+                if (anyokay)
+                  {
+                    hr = message->SaveChanges (KEEP_OPEN_READWRITE);
+                    if (hr)
+                      log_error_w32 (hr, "%s:%s: SaveChanges failed",
+                                     SRCNAME, __func__); 
+                    else
+                      log_debug ("%s:%s: SaveChanges succeded; "
+                                 "body cruft removed",
+                                 SRCNAME, __func__); 
+                  }
+              }  
+            else
+              log_debug_w32 (hr, "%s:%s: "
+                             "error getting message decryption status", 
+                             SRCNAME, __func__);
+          }
+          break;
 
-          if (anyokay)
-            {
-              hr = message->SaveChanges (KEEP_OPEN_READWRITE);
-              if (hr)
-                log_error_w32 (hr, "%s:%s: SaveChanges failed",
-                               SRCNAME, __func__); 
-              else
-                log_debug ("%s:%s: SaveChanges succeded; body cruft removed",
-                           SRCNAME, __func__); 
-            }
-        }  
-      else
-        log_debug_w32 (hr, "%s:%s: error getting message", 
-                       SRCNAME, __func__);
-     
+        case MSGTYPE_GPGOL_PGP_MESSAGE:
+          /* We can't delete the body of a message if it is an inline
+             PGP encrypted message because the body holds the
+             ciphertext.  */
+          break;
+
+        default: 
+          break;
+        }
+      
       ul_release (message, __func__);
       ul_release (mdb, __func__);
     }