[svn] GpgOL - r222 - in trunk: . doc po src

svn author wk cvs at cvs.gnupg.org
Mon Feb 18 12:16:45 CET 2008


Author: wk
Date: 2008-02-18 12:16:44 +0100 (Mon, 18 Feb 2008)
New Revision: 222

Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/configure.ac
   trunk/doc/gpgol.texi
   trunk/po/de.po
   trunk/src/ChangeLog
   trunk/src/dialogs.rc
   trunk/src/mapihelp.h
   trunk/src/message.cpp
   trunk/src/olflange-dlgs.cpp
Log:
Fixed decryption of PGP inline encrypted messages.


[The diff below has been truncated]

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/ChangeLog	2008-02-18 11:16:44 UTC (rev 222)
@@ -1,3 +1,11 @@
+2008-02-18  Werner Koch  <wk at g10code.com>
+
+	Release 0.10.5 development version.
+
+2008-02-15  Werner Koch  <wk at g10code.com>
+
+	* po/de.po: Describe more explicit on how to start the UI-server.
+
 2008-02-06  Werner Koch  <wk at g10code.com>
 
 	Released 0.10.4 development version.

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/src/ChangeLog	2008-02-18 11:16:44 UTC (rev 222)
@@ -1,3 +1,18 @@
+2008-02-18  Werner Koch  <wk at g10code.com>
+
+	* message.cpp (pgp_body_to_attachment): New.
+	(message_decrypt): Use it.
+	(message_wipe_body_cruft): Also wipe already processed PGP
+	encrypted messages.  Factor common code out to ...
+	(do_wipe_body): .. new.
+	* mapihelp.h (ATTACHTYPE_PGPBODY): New.
+
+2008-02-15  Werner Koch  <wk at g10code.com>
+
+	* olflange-dlgs.cpp: Remove code for IDC_ENCRYPT_WITH_STANDARD_KEY
+	and IDC_ENCRYPT_TO.
+	* dialogs.rc: Ditto.
+
 2008-02-13  Werner Koch  <wk at g10code.com>
 
 	* mapihelp.cpp (get_gpgolcharset_tag, mapi_get_gpgol_charset) 

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/NEWS	2008-02-18 11:16:44 UTC (rev 222)
@@ -1,9 +1,16 @@
-Noteworthy changes for version 0.10.4 (2008-02-06)
+Noteworthy changes for version 0.10.5 (2008-02-18)
 ==================================================
 
  UNDER HEAVY DEVELOPMENT - DO NOT USE FOR PRODUCTION!
     - Under OL2007 some menu entries are missing.
 
+ * PGP inline encrypted mails are not anymore deleted after the first
+   decryption.
+
+
+Noteworthy changes for version 0.10.4 (2008-02-06)
+==================================================
+
  * Sign and encrypt works now.
 
  * Texts with embedded attachments are now concatenated.

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/configure.ac	2008-02-18 11:16:44 UTC (rev 222)
@@ -17,7 +17,7 @@
 # Set my_issvn to "yes" for non-released code.  Remember to run an
 # "svn up" and "autogen.sh" right before creating a distribution.
 m4_define([my_version], [0.10.5])
-m4_define([my_issvn], [yes])
+m4_define([my_issvn], [no])
 
 m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \
             || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')]))

Modified: trunk/doc/gpgol.texi
===================================================================
--- trunk/doc/gpgol.texi	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/doc/gpgol.texi	2008-02-18 11:16:44 UTC (rev 222)
@@ -557,6 +557,12 @@
 
   @item ATTACHTYPE_MOSSTEMPL = 3
   The attachment has been created in the course of sending a message.
+
+  @item ATTACHTYPE_PGPBODY = 4
+  The attachment contains the original PGP message body of PGP inline
+  encrypted messages.  We need to save this away because it may happen
+  that in the course of displaying the plaintext Outlook overwrites the
+  actual body due to internal syncronization.
   @end table
 
 @item GpgOL Sig Status

Modified: trunk/po/de.po  [not shown]
Modified: trunk/src/dialogs.rc
===================================================================
--- trunk/src/dialogs.rc	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/src/dialogs.rc	2008-02-18 11:16:44 UTC (rev 222)
@@ -59,12 +59,14 @@
                     "Button", BS_AUTOCHECKBOX | WS_TABSTOP,
                     24, 66, 215, 10
 
-    CONTROL         "encrypt-to", IDC_ENCRYPT_WITH_STANDARD_KEY,
-                    "Button", BS_AUTOCHECKBOX | WS_TABSTOP,
-                    24, 79, 215, 10
+  /* Note: We epp the spae for now in case we need to add other config
+     options. */
+/*     CONTROL         "encrypt-to", IDC_ENCRYPT_WITH_STANDARD_KEY, */
+/*                     "Button", BS_AUTOCHECKBOX | WS_TABSTOP, */
+/*                     24, 79, 215, 10 */
 
-    EDITTEXT        IDC_ENCRYPT_TO, 
-                    36, 91, 133, 12, ES_AUTOHSCROLL
+/*     EDITTEXT        IDC_ENCRYPT_TO,  */
+/*                     36, 91, 133, 12, ES_AUTOHSCROLL */
 
     CONTROL         "preview-decrypt", IDC_PREVIEW_DECRYPT,
                     "Button", BS_AUTOCHECKBOX | WS_TABSTOP,

Modified: trunk/src/mapihelp.h
===================================================================
--- trunk/src/mapihelp.h	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/src/mapihelp.h	2008-02-18 11:16:44 UTC (rev 222)
@@ -48,8 +48,11 @@
     ATTACHTYPE_MOSS = 1,         /* The original MOSS message (ie. a
                                     S/MIME or PGP/MIME message. */
     ATTACHTYPE_FROMMOSS = 2,     /* Attachment created from MOSS.  */
-    ATTACHTYPE_MOSSTEMPL = 3     /* Attachment has been created in the
+    ATTACHTYPE_MOSSTEMPL = 3,    /* Attachment has been created in the
                                     course of sending a message */ 
+    ATTACHTYPE_PGPBODY = 4       /* Attachment contains the original
+                                    PGP message body of PGP inline
+                                    encrypted messages.  */
   }
 attachtype_t;
 
@@ -81,11 +84,14 @@
 typedef struct mapi_attach_item_s mapi_attach_item_t;
 
 /* The filename of the attachment we create as the result of sign or
-   encrypt operation.  Don't change this name as some tests rely on
+   encrypt operations.  Don't change this name as some tests rely on
    it.  */
 #define MIMEATTACHFILENAME "gpgolXXX.dat"
+/* The name of the file we use to store the original body of PGP
+   encrypted messages.  Note that PGP/MIME message don't need that
+   because Outlook carries them as 2 attachments.  */
+#define PGPBODYFILENAME    "gpgolPGP.dat"
 
-
 void log_mapi_property (LPMESSAGE message, ULONG prop, const char *propname);
 int get_gpgolattachtype_tag (LPMESSAGE message, ULONG *r_tag);
 int get_gpgolsigstatus_tag (LPMESSAGE message, ULONG *r_tag);

Modified: trunk/src/message.cpp
===================================================================
--- trunk/src/message.cpp	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/src/message.cpp	2008-02-18 11:16:44 UTC (rev 222)
@@ -176,6 +176,43 @@
 }
 
 
+/* Helper for message_wipe_body_cruft.  */
+static void
+do_wipe_body (LPMESSAGE message)
+{
+  HRESULT hr;
+  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__); 
+    }
+}
+
+
 /* If the current message is an encrypted one remove the body
    properties which might have come up due to OL internal
    syncronization and a failing olDiscard feature.  */
@@ -197,40 +234,7 @@
         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__); 
-                  }
-              }  
+              do_wipe_body (message);
             else
               log_debug_w32 (hr, "%s:%s: "
                              "error getting message decryption status", 
@@ -239,9 +243,32 @@
           break;
 
         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.  */
+          {
+            /* In general we can't delete the body of a message if it
+               is an inline PGP encrypted message because the body
+               holds the ciphertext.  However, while decrypting, we
+               take a copy of the body and work on that in future; if
+               this has been done we can delete the body.  */
+            mapi_attach_item_t *table;
+            int found = 0;
+            int tblidx;
+
+            table = mapi_create_attach_table (message, 0);
+            if (table)
+              {
+                for (tblidx=0; !table[tblidx].end_of_table; tblidx++)
+                  if (table[tblidx].attach_type == ATTACHTYPE_PGPBODY
+                      && table[tblidx].filename 
+                      && !strcmp (table[tblidx].filename, PGPBODYFILENAME))
+                    {
+                      found = 1;
+                      break;
+                    }
+              }
+            mapi_release_attach_table (table);
+            if (found)
+              do_wipe_body (message);
+          }
           break;
 
         default: 
@@ -268,12 +295,12 @@
   buflen = strlen (msgcls) + strlen (sigstat) + strlen (mimeinfo) + 200;
   buffer = (char*)xmalloc (buflen+1);
   snprintf (buffer, buflen, 
-            _("Message class: %s\n"
-              "Sig Status   : %s\n"
-              "Structure of the message:\n"
+            _("Signature status: %s\n"
+              "Message class ..: %s\n"
+              "MIME structure .:\n"
               "%s"), 
+            sigstat,
             msgcls,
-            sigstat,
             mimeinfo);
   
   MessageBox (hwnd, buffer, _("GpgOL - Message Information"),
@@ -465,7 +492,6 @@
 }
 
 
-
 /* Verify MESSAGE and update the attachments as required.  MSGTYPE
    should be the type of the message so that the fucntion can decide
    what to do.  With FORCE set the verification is done regardlessless
@@ -639,6 +665,138 @@
 }
 
 
+/* Copy the MAPI body to a PGPBODY type attachment. */
+static int
+pgp_body_to_attachment (LPMESSAGE message)
+{
+  HRESULT hr;
+  LPSTREAM instream;
+  ULONG newpos;
+  LPATTACH newatt = NULL;
+  SPropValue prop;
+  LPSTREAM outstream = NULL;
+  LPUNKNOWN punk;
+
+  instream = mapi_get_body_as_stream (message);
+  if (!instream)
+    return -1;
+  
+  hr = message->CreateAttach (NULL, 0, &newpos, &newatt);
+  if (hr)
+    {
+      log_error ("%s:%s: can't create attachment: hr=%#lx\n",
+                 SRCNAME, __func__, hr); 
+      goto leave;
+    }
+
+  prop.ulPropTag = PR_ATTACH_METHOD;
+  prop.Value.ul = ATTACH_BY_VALUE;
+  hr = HrSetOneProp ((LPMAPIPROP)newatt, &prop);
+  if (hr)
+    {
+      log_error ("%s:%s: can't set attach method: hr=%#lx\n",
+                 SRCNAME, __func__, hr); 
+      goto leave;
+    }
+
+  /* Mark that attachment so that we know why it has been created.  */
+  if (get_gpgolattachtype_tag (message, &prop.ulPropTag) )
+    goto leave;
+  prop.Value.l = ATTACHTYPE_PGPBODY;
+  hr = HrSetOneProp ((LPMAPIPROP)newatt, &prop);	
+  if (hr)
+    {
+      log_error ("%s:%s: can't set %s property: hr=%#lx\n",
+                 SRCNAME, __func__, "GpgOL Attach Type", hr); 
+      goto leave;
+    }
+
+  prop.ulPropTag = PR_ATTACHMENT_HIDDEN;
+  prop.Value.b = TRUE;
+  hr = HrSetOneProp ((LPMAPIPROP)newatt, &prop);
+  if (hr)
+    {
+      log_error ("%s:%s: can't set hidden attach flag: hr=%#lx\n",
+                 SRCNAME, __func__, hr); 
+      goto leave;
+    }
+
+  prop.ulPropTag = PR_ATTACH_FILENAME_A;
+  prop.Value.lpszA = PGPBODYFILENAME;
+  hr = HrSetOneProp ((LPMAPIPROP)newatt, &prop);
+  if (hr)
+    {
+      log_error ("%s:%s: can't set attach filename: hr=%#lx\n",
+                 SRCNAME, __func__, hr); 
+      goto leave;
+    }
+
+  punk = (LPUNKNOWN)outstream;
+  hr = newatt->OpenProperty (PR_ATTACH_DATA_BIN, &IID_IStream, 0,
+                             MAPI_CREATE|MAPI_MODIFY, &punk);
+  if (FAILED (hr)) 
+    {
+      log_error ("%s:%s: can't create output stream: hr=%#lx\n",
+                 SRCNAME, __func__, hr); 
+      goto leave;
+    }
+  outstream = (LPSTREAM)punk;
+
+  /* Insert a blank line so that our mime parser skips over the mail
+     headers.  */
+  hr = outstream->Write ("\r\n", 2, NULL);
+  if (hr)
+    {
+      log_error ("%s:%s: Write failed: hr=%#lx", SRCNAME, __func__, hr);
+      goto leave;
+    }
+
+  {
+    ULARGE_INTEGER cb;
+    cb.QuadPart = 0xffffffffffffffffll;
+    hr = instream->CopyTo (outstream, cb, NULL, NULL);
+  }
+  if (hr)
+    {
+      log_error ("%s:%s: can't copy streams: hr=%#lx\n",
+                 SRCNAME, __func__, hr); 
+      goto leave;
+    }
+  hr = outstream->Commit (0);
+  if (hr)
+    {
+      log_error ("%s:%s: Commiting output stream failed: hr=%#lx",
+                 SRCNAME, __func__, hr);
+      goto leave;
+    }
+  outstream->Release ();
+  outstream = NULL;
+  hr = newatt->SaveChanges (0);
+  if (hr)
+    {
+      log_error ("%s:%s: SaveChanges of the attachment failed: hr=%#lx\n",
+                 SRCNAME, __func__, hr); 
+      goto leave;
+    }
+  newatt->Release ();
+  newatt = NULL;
+  hr = message->SaveChanges (KEEP_OPEN_READWRITE);
+  if (hr)
+    log_error ("%s:%s: SaveChanges failed: hr=%#lx\n", SRCNAME, __func__, hr); 
+
+ leave:
+  if (outstream)
+    {
+      outstream->Revert ();
+      outstream->Release ();
+    }
+  if (newatt)
+    newatt->Release ();
+  instream->Release ();
+  return hr? -1:0;
+}
+
+
 /* Decrypt MESSAGE, check signature and update the attachments as
    required.  MSGTYPE should be the type of the message so that the
    function can decide what to do.  With FORCE set the decryption is
@@ -647,7 +805,7 @@
 message_decrypt (LPMESSAGE message, msgtype_t msgtype, int force, HWND hwnd)
 {
   mapi_attach_item_t *table = NULL;
-  int part2_idx;
+  int part1_idx, part2_idx;
   int tblidx;
   int retval = -1;
   LPSTREAM cipherstream;
@@ -682,12 +840,58 @@
 
   if (msgtype == MSGTYPE_GPGOL_PGP_MESSAGE)
     {
-      /* PGP messages are special:  All is contained in the body and thus
-         there is no requirement for an attachment.  */
-      cipherstream = mapi_get_body_as_stream (message);
+      /* PGP messages are special: All is contained in the body and
+         thus there would be no requirement for an attachment.
+         However, due to problems with Outlook overwriting the body of
+         the message after decryption, we need to save the body away
+         before decrypting it.  We then always look for that original
+         body atatchment and create one if it does not exist.  */
+      part1_idx = -1;
+      table = mapi_create_attach_table (message, 0);
+      if (!table)
+        ;
+      else
+        {
+          for (tblidx=0; !table[tblidx].end_of_table; tblidx++)
+            if (table[tblidx].attach_type == ATTACHTYPE_PGPBODY
+                && table[tblidx].filename 
+                && !strcmp (table[tblidx].filename, PGPBODYFILENAME))
+              {
+                part1_idx = tblidx;
+                break;
+              }
+        }
+      if (part1_idx == -1)
+        {
+          mapi_release_attach_table (table);
+          if (pgp_body_to_attachment (message))
+            table = NULL;
+          else
+            table = mapi_create_attach_table (message, 0);
+          if (table)
+            {
+              for (tblidx=0; !table[tblidx].end_of_table; tblidx++)
+                if (table[tblidx].attach_type == ATTACHTYPE_PGPBODY
+                    && table[tblidx].filename 
+                    && !strcmp (table[tblidx].filename, PGPBODYFILENAME))
+                  {
+                    part1_idx = tblidx;
+                    break;
+                  }
+            }
+        }
+      if (!table || part1_idx == -1)
+        {
+          log_debug ("%s:%s: problem copying the PGP inline encrypted message",
+                     SRCNAME, __func__);
+          goto leave;
+        }
+      cipherstream = mapi_get_attach_as_stream (message, table+part1_idx,
+                                                NULL);
       if (!cipherstream)
-        goto leave;
+        goto leave; /* Problem getting the attachment.  */
       protocol = PROTOCOL_OPENPGP;
+      need_rfc822_parser = 1;
     }
   else
     {
@@ -756,8 +960,6 @@
              attachments by looking at all attachments.  Only if this
              fails we identify them by their order (i.e. the first 2
              attachments) and mark them as part1 and part2.  */
-          int part1_idx;
-          
           part1_idx = part2_idx = -1;
           for (tblidx=0; !table[tblidx].end_of_table; tblidx++)
             if (table[tblidx].attach_type == ATTACHTYPE_MOSS)

Modified: trunk/src/olflange-dlgs.cpp
===================================================================
--- trunk/src/olflange-dlgs.cpp	2008-02-13 19:18:55 UTC (rev 221)
+++ trunk/src/olflange-dlgs.cpp	2008-02-18 11:16:44 UTC (rev 222)
@@ -47,8 +47,8 @@
     { IDC_OPENPGP_DEFAULT,  N_("Use PGP/MIME by default")},
     { IDC_SMIME_DEFAULT,    N_("Use S/MIME by default")},
     { IDC_ENABLE_SMIME,     N_("Enable the S/MIME support")},
-    { IDC_ENCRYPT_WITH_STANDARD_KEY, 
-                     N_("Also encrypt message with the default certificate")},
+//     { IDC_ENCRYPT_WITH_STANDARD_KEY, 
+//                      N_("Also encrypt message with the default certificate")},




More information about the Gnupg-commits mailing list