[svn] GPGol - r129 - trunk/src

svn author wk cvs at cvs.gnupg.org
Thu Dec 1 20:24:32 CET 2005


Author: wk
Date: 2005-12-01 20:24:32 +0100 (Thu, 01 Dec 2005)
New Revision: 129

Modified:
   trunk/src/ChangeLog
   trunk/src/display.cpp
   trunk/src/display.h
   trunk/src/engine-gpgme.c
   trunk/src/engine.h
   trunk/src/gpgmsg.cpp
   trunk/src/gpgmsg.hh
   trunk/src/olflange.cpp
   trunk/src/olflange.h
   trunk/src/pgpmime.c
   trunk/src/pgpmime.h
Log:
internal cleanups and reworked the preview decryption

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/ChangeLog	2005-12-01 19:24:32 UTC (rev 129)
@@ -1,3 +1,28 @@
+2005-12-01  Werner Koch  <wk at g10code.com>
+
+	* engine-gpgme.c (op_decrypt_stream_to_gpgme, decrypt_stream) 
+	(op_decrypt): Add arg PREVIEW_MODE.
+	* pgpmime.c (pgpmime_decrypt): New arg PREVIEW_MODE.
+	(struct pgpmime_context): New field PREVIEW.
+	(message_cb, plaintext_handler): Handle preview mode.
+	* gpgmsg.cpp (class GpgMsgImpl): Renamed SILENT to PREVIEW.
+	(setSilent): Renamed to ..
+	(setPreview): .. this.
+	(decrypt): Handle preview mode.  Display a string while decrypting
+	PGP/MIME messages.
+
+	* display.cpp (update_display): New arg TEXT.
+	* gpgmsg.cpp (class GpgMsgImpl): Removed BODY_PLAIN and BODY.
+	(getDisplayText): Removed.
+	(loadBody): Changes to return the allocated body.
+	(getOrigText): Removed.
+	(getMessageType): Rewritten to take the body text as argument.
+	(decrypt): Pass plaintext directly to update_display.  Free
+	plaintext.
+	(sign, encrypt_and_sign): Likewise.
+
+	* olflange.cpp (OnWriteComplete): Always delete PR_BODY on error.
+
 2005-11-30  Werner Koch  <wk at g10code.com>
 
 	* gpgmsg.cpp: Made more strings translatable.

Modified: trunk/src/display.cpp
===================================================================
--- trunk/src/display.cpp	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/display.cpp	2005-12-01 19:24:32 UTC (rev 129)
@@ -129,45 +129,46 @@
 }
 
 
-/* Update the display using the message MSG.  Return 0 on success. */
+/* Update the display with TEXT using the message MSG.  Return 0 on
+   success. */
 int
-update_display (HWND hwnd, GpgMsg *msg, void *exchange_cb, bool is_html)
+update_display (HWND hwnd, GpgMsg *msg, void *exchange_cb, 
+                bool is_html, const char *text)
 {
   HWND window;
 
   window = find_message_window (hwnd);
   if (window)
     {
-      const char *string, *s;
+      const char *s;
 
       log_debug ("%s:%s: window handle %p\n", SRCNAME, __func__, window);
-      string = msg->getDisplayText ();
       
       /* Decide whether we need to use the Unicode version. */
-      for (s=string; *s && !(*s & 0x80); s++)
+      for (s=text; *s && !(*s & 0x80); s++)
         ;
       if (*s)
         {
-          wchar_t *tmp = utf8_to_wchar (string);
+          wchar_t *tmp = utf8_to_wchar (text);
           SetWindowTextW (window, tmp);
           xfree (tmp);
         }
       else
-        SetWindowTextA (window, string);
+        SetWindowTextA (window, text);
       log_debug ("%s:%s: window text is now `%s'",
-                 SRCNAME, __func__, string);
+                 SRCNAME, __func__, text);
       return 0;
     }
   else if (exchange_cb && !opt.compat.no_oom_write)
     {
       log_debug ("updating display using OOM");
       return put_outlook_property (exchange_cb, is_html? "HTMLBody":"Body",
-                                   msg->getDisplayText ());
+                                   text);
     }
   else
     {
-      log_debug ("%s: window handle not found for parent %p\n",
-                 __func__, hwnd);
+      log_debug ("%s:%s: window handle not found for parent %p\n",
+                 SRCNAME, __func__, hwnd);
       return -1;
     }
 }
@@ -180,7 +181,7 @@
 {
   HRESULT hr;
   SPropValue prop;
-  SPropTagArray proparray;
+  //SPropTagArray proparray;
   const char *s;
   
   assert (message);

Modified: trunk/src/display.h
===================================================================
--- trunk/src/display.h	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/display.h	2005-12-01 19:24:32 UTC (rev 129)
@@ -28,7 +28,8 @@
 
 char *add_html_line_endings (const char *body);
 
-int update_display (HWND hwnd, GpgMsg *msg, void *exchange_cb, bool is_html);
+int update_display (HWND hwnd, GpgMsg *msg, void *exchange_cb,
+                    bool is_html, const char *text);
 
 int set_message_body (LPMESSAGE message, const char *string, bool is_html);
 

Modified: trunk/src/engine-gpgme.c
===================================================================
--- trunk/src/engine-gpgme.c	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/engine-gpgme.c	2005-12-01 19:24:32 UTC (rev 129)
@@ -486,7 +486,7 @@
    signature verification will get printed to it. */
 int 
 op_decrypt (const char *inbuf, char **outbuf, int ttl, const char *filename,
-            gpgme_data_t attestation)
+            gpgme_data_t attestation, int preview_mode)
 {
   struct decrypt_key_s dk;
   gpgme_data_t in = NULL;
@@ -513,12 +513,17 @@
 
   gpgme_set_passphrase_cb (ctx, passphrase_callback_box, &dk);
   dk.ctx = ctx;
-  err = gpgme_op_decrypt_verify (ctx, in, out);
+  if (preview_mode)
+    err = gpgme_op_decrypt (ctx, in, out);
+  else
+    err = gpgme_op_decrypt_verify (ctx, in, out);
   dk.ctx = NULL;
   update_passphrase_cache (err, &dk);
 
   /* Act upon the result of the decryption operation. */
-  if (!err) 
+  if (!err && preview_mode) 
+    ;
+  else if (!err) 
     {
       /* Decryption succeeded.  Store the result at OUTBUF. */
       gpgme_verify_result_t res;
@@ -577,7 +582,8 @@
    will get printed to it. */
 static int
 decrypt_stream (gpgme_data_t in, gpgme_data_t out, int ttl,
-                const char *filename, gpgme_data_t attestation)
+                const char *filename, gpgme_data_t attestation, 
+                int preview_mode)
 {    
   struct decrypt_key_s dk;
   gpgme_ctx_t ctx = NULL;
@@ -592,11 +598,16 @@
 
   gpgme_set_passphrase_cb (ctx, passphrase_callback_box, &dk);
   dk.ctx = ctx;
-  err = gpgme_op_decrypt_verify (ctx, in, out);
+  if (preview_mode)
+    err = gpgme_op_decrypt (ctx, in, out);
+  else
+    err = gpgme_op_decrypt_verify (ctx, in, out);
   dk.ctx = NULL;
   update_passphrase_cache (err, &dk);
   /* Act upon the result of the decryption operation. */
-  if (!err) 
+  if (!err && preview_mode) 
+    ;
+  else if (!err) 
     {
       gpgme_verify_result_t res;
 
@@ -656,7 +667,7 @@
   if (!err)
     err = gpgme_data_new_from_cbs (&out, &cbs, outstream);
   if (!err)
-    err = decrypt_stream (in, out, ttl, filename, attestation);
+    err = decrypt_stream (in, out, ttl, filename, attestation, 0);
 
   if (in)
     gpgme_data_release (in);
@@ -689,7 +700,7 @@
   if (!err)
     err = gpgme_data_new (&out);
   if (!err)
-    err = decrypt_stream (in, out, ttl, filename, attestation);
+    err = decrypt_stream (in, out, ttl, filename, attestation, 0);
   if (!err)
     {
       /* Return the buffer but first make sure it is a string. */
@@ -714,7 +725,8 @@
    outputs. */
 int
 op_decrypt_stream_to_gpgme (LPSTREAM instream, gpgme_data_t out, int ttl,
-                            const char *filename, gpgme_data_t attestation)
+                            const char *filename, gpgme_data_t attestation,
+                            int preview_mode)
 {
   struct gpgme_data_cbs cbs;
   gpgme_data_t in = NULL;
@@ -725,7 +737,7 @@
 
   err = gpgme_data_new_from_cbs (&in, &cbs, instream);
   if (!err)
-    err = decrypt_stream (in, out, ttl, filename, attestation);
+    err = decrypt_stream (in, out, ttl, filename, attestation, preview_mode);
 
   if (in)
     gpgme_data_release (in);

Modified: trunk/src/engine.h
===================================================================
--- trunk/src/engine.h	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/engine.h	2005-12-01 19:24:32 UTC (rev 129)
@@ -57,15 +57,16 @@
                     gpgme_key_t sign_key, int ttl);
 
 int op_decrypt (const char *inbuf, char **outbuf, int ttl,
-                const char *filename, gpgme_data_t attestation);
+                const char *filename, gpgme_data_t attestation, 
+                int preview_mode);
 int op_decrypt_stream (LPSTREAM instream, LPSTREAM outstream, int ttl,
                        const char *filename, gpgme_data_t attestation);
 int op_decrypt_stream_to_buffer (LPSTREAM instream, char **outbuf, int ttl,
                                  const char *filename,
                                  gpgme_data_t attestation);
 int op_decrypt_stream_to_gpgme (LPSTREAM instream, gpgme_data_t out, int ttl,
-                                const char *filename,
-                                gpgme_data_t attestation);
+                                const char *filename, gpgme_data_t attestation,
+                                int preview_mode);
 
 int op_verify (const char *inbuf, char **outbuf, const char *filename,
                gpgme_data_t attestation);

Modified: trunk/src/gpgmsg.cpp
===================================================================
--- trunk/src/gpgmsg.cpp	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/gpgmsg.cpp	2005-12-01 19:24:32 UTC (rev 129)
@@ -98,11 +98,9 @@
   {
     message = NULL;
     exchange_cb = NULL;
-    body = NULL;
-    body_plain = NULL;
     is_pgpmime = false;
     has_attestation = false;
-    silent = false;
+    preview = false;
 
     attestation = NULL;
 
@@ -114,8 +112,6 @@
   {
     if (message)
       message->Release ();
-    xfree (body);
-    xfree (body_plain);
 
     if (attestation)
       gpgme_data_release (attestation);
@@ -162,15 +158,13 @@
     exchange_cb = cb;
   }
   
-  void setSilent (bool value)
+  void setPreview (bool value)
   {
-    silent = value;
+    preview = value;
   }
 
-  openpgp_t getMessageType (void);
+  openpgp_t getMessageType (const char *s);
   bool hasAttachments (void);
-  const char *getOrigText (bool want_html);
-  const char *GpgMsgImpl::getDisplayText (void);
   const char *getPlainText (void);
 
   int decrypt (HWND hwnd);
@@ -200,12 +194,10 @@
 private:
   LPMESSAGE message;  /* Pointer to the message. */
   void *exchange_cb;  /* Call back used with the display function. */
-  char *body;         /* utf-8 encoded body string or NULL. */
-  char *body_plain;   /* Plaintext version of BODY or NULL. */
   bool is_pgpmime;    /* True if the message is a PGP/MIME encrypted one. */
   bool has_attestation;/* True if we found an attestation attachment. */
-  bool silent;        /* Don't pop up message boxes.  Currently this
-                         is only used with decryption.  */
+  bool preview;       /* Don't pop up message boxes and run only a
+                         body decryption. */
 
   /* If not NULL, collect attestation information here. */
   gpgme_data_t attestation;
@@ -218,7 +210,7 @@
     LPSRowSet   rows;     /* The retrieved set of rows from the table. */
   } attach;
   
-  void loadBody (bool want_html);
+  char *loadBody (bool want_html);
   bool isPgpmimeVersionPart (int pos);
   void writeAttestation (void);
   attach_info_t gatherAttachmentInfo (void);
@@ -363,9 +355,9 @@
 
 
 
-/* Load the body and make it available as an UTF8 string in the
-   instance variable BODY.  */
-void
+/* Load the body from the MAP and return it as an UTF8 string.
+   Returns NULL on error.  */
+char *
 GpgMsgImpl::loadBody (bool want_html)
 {
   HRESULT hr;
@@ -374,9 +366,10 @@
 //   SPropValue prop;
   STATSTG statInfo;
   ULONG nread;
+  char *body = NULL;
 
-  if (body || !message)
-    return;
+  if (!message)
+    return NULL;
 
   hr = HrGetOneProp ((LPMAPIPROP)message,
                      want_html? PR_BODY_HTML : PR_BODY, &lpspvFEID);
@@ -418,7 +411,7 @@
                 goto ready;
             }
           
-          return;
+          return NULL;
         }
       
       hr = stream->Stat (&statInfo, STATFLAG_NONAME);
@@ -426,7 +419,7 @@
         {
           log_debug ("%s:%s: Stat failed: hr=%#lx", SRCNAME, __func__, hr);
           stream->Release ();
-          return;
+          return NULL;
         }
       
       /* Fixme: We might want to read only the first 1k to decide
@@ -439,9 +432,8 @@
         {
           log_debug ("%s:%s: Read failed: hr=%#lx", SRCNAME, __func__, hr);
           xfree (body);
-          body = NULL;
           stream->Release ();
-          return;
+          return NULL;
         }
       body[nread] = 0;
       body[nread+1] = 0;
@@ -449,13 +441,12 @@
         {
           log_debug ("%s:%s: not enough bytes returned\n", SRCNAME, __func__);
           xfree (body);
-          body = NULL;
           stream->Release ();
-          return;
+          return NULL;
         }
       stream->Release ();
       
-      /* FIXME: We need to optimize this. */
+      /* FIXME: We should to optimize this. */
       {
         char *tmp;
         tmp = wchar_to_utf8 ((wchar_t*)body);
@@ -481,6 +472,7 @@
 //   if (FAILED (hr))
 //     log_debug ("%s:%s: updating message access to 0x%08lx failed: hr=%#lx",
 //                    SRCNAME, __func__, prop.Value.l, hr);
+  return body;
 }
 
 
@@ -561,61 +553,32 @@
 #endif
 
 
-/* Return the type of a message. */
+/* Return the type of a message with the body text in TEXT. */
 openpgp_t
-GpgMsgImpl::getMessageType (void)
+GpgMsgImpl::getMessageType (const char *text)
 {
   const char *s;
-  
-  loadBody (false);
-  
-  if (!body || !(s = strstr (body, "BEGIN PGP ")))
+
+  if (!text || !(s = strstr (text, "BEGIN PGP ")))
     return OPENPGP_NONE;
 
   /* (The extra strstr() above is just a simple optimization.) */
-  if (strstr (body, "BEGIN PGP MESSAGE"))
+  if (strstr (text, "BEGIN PGP MESSAGE"))
     return OPENPGP_MSG;
-  else if (strstr (body, "BEGIN PGP SIGNED MESSAGE"))
+  else if (strstr (text, "BEGIN PGP SIGNED MESSAGE"))
     return OPENPGP_CLEARSIG;
-  else if (strstr (body, "BEGIN PGP SIGNATURE"))
+  else if (strstr (text, "BEGIN PGP SIGNATURE"))
     return OPENPGP_SIG;
-  else if (strstr (body, "BEGIN PGP PUBLIC KEY"))
+  else if (strstr (text, "BEGIN PGP PUBLIC KEY"))
     return OPENPGP_PUBKEY;
-  else if (strstr (body, "BEGIN PGP PRIVATE KEY"))
+  else if (strstr (text, "BEGIN PGP PRIVATE KEY"))
     return OPENPGP_SECKEY;
   else
     return OPENPGP_NONE;
 }
 
 
-/* Return the body text as received or composed.  This is guaranteed
-   to never return NULL.  */
-const char *
-GpgMsgImpl::getOrigText (bool want_html)
-{
-  loadBody (want_html);
-  
-  return body? body : "";
-}
 
-
-/* Return the text of the message to be used for the display.  The
-   message objects has intrinsic knowledge about the correct text.  */
-const char *
-GpgMsgImpl::getDisplayText (void)
-{
-  loadBody (false);
-
-  if (body_plain)
-    return body_plain;
-  else if (body)
-    return body;
-  else
-    return "";
-}
-
-
-
 /* Return an array of strings with the recipients of the message. On
    success a malloced array is returned containing allocated strings
    for each recipient.  The end of the array is marked by NULL.
@@ -857,7 +820,7 @@
 
 
 /* Decrypt the message MSG and update the window.  HWND identifies the
-   current window. */
+   current window.  */
 int 
 GpgMsgImpl::decrypt (HWND hwnd)
 {
@@ -872,8 +835,12 @@
   unsigned int n_signed = 0;
   HRESULT hr;
   int pgpmime_succeeded = 0;
+  char *body;
 
-  mtype = getMessageType ();
+  /* Load the body text into BODY.  Note that body may be NULL but in
+     this case MTYPE will be OPENPGP_NONE. */
+  body = loadBody (false);
+  mtype = getMessageType (body);
 
   /* Check whether this possibly encrypted message has encrypted
      attachments.  We check right now because we need to get into the
@@ -915,20 +882,20 @@
       if (!opt.compat.old_reply_hack
           && (s = msgcache_get_from_mapi (message, &refhandle)))
         {
-          xfree (body_plain);
-          body_plain = xstrdup (s);
-          update_display (hwnd, this, exchange_cb, is_html_body (s));
+          update_display (hwnd, this, exchange_cb, is_html_body (s), s);
           msgcache_unref (refhandle);
           log_debug ("%s:%s: leave (already decrypted)\n", SRCNAME, __func__);
         }
       else
         {
-          MessageBox (hwnd, _("No valid OpenPGP data found."),
-                      _("Decryption"), MB_ICONWARNING|MB_OK);
+          if (!preview)
+            MessageBox (hwnd, _("No valid OpenPGP data found."),
+                        _("Decryption"), MB_ICONWARNING|MB_OK);
           log_debug ("%s:%s: leave (no OpenPGP data)\n", SRCNAME, __func__);
         }
       
       release_attach_info (table);
+      xfree (body);
       return 0;
     }
 
@@ -942,10 +909,9 @@
       log_debug ("%s:%s: we already have an attestation\n",
                  SRCNAME, __func__);
     }
-  else if (!attestation && !opt.compat.no_attestation)
+  else if (!attestation && !opt.compat.no_attestation && !preview)
     gpgme_data_new (&attestation);
   
-
   /* Process according to type of message. */
   if (is_pgpmime)
     {
@@ -953,15 +919,25 @@
       int method;
       LPSTREAM from;
       
+      /* If there is no body text (this should be the case for
+         PGP/MIME), display a message to indicate that this is such a
+         message.  This is useful in case of such messages with
+         longish attachments which might take long to decrypt. */
+      if (!body || !*body)
+        update_display (hwnd, this, exchange_cb, 0, 
+                        _("[This is a PGP/MIME message]"));        
+
       hr = message->OpenAttach (1, NULL, MAPI_BEST_ACCESS, &att);	
       if (FAILED (hr))
         {
           log_error ("%s:%s: can't open PGP/MIME attachment 2: hr=%#lx",
                      SRCNAME, __func__, hr);
-          MessageBox (hwnd, _("Problem decrypting PGP/MIME message"),
-                      _("Decryption"), MB_ICONERROR|MB_OK);
+          if (!preview)
+            MessageBox (hwnd, _("Problem decrypting PGP/MIME message"),
+                        _("Decryption"), MB_ICONERROR|MB_OK);
           log_debug ("%s:%s: leave (PGP/MIME problem)\n", SRCNAME, __func__);
           release_attach_info (table);
+          xfree (body);
           return gpg_error (GPG_ERR_GENERAL);
         }
 
@@ -970,11 +946,13 @@
         {
           log_error ("%s:%s: unsupported method %d for PGP/MIME attachment 2",
                      SRCNAME, __func__, method);
-          MessageBox (hwnd, _("Problem decrypting PGP/MIME message"),
-                      _("Decryption"), MB_ICONERROR|MB_OK);
+          if (!preview)
+            MessageBox (hwnd, _("Problem decrypting PGP/MIME message"),
+                        _("Decryption"), MB_ICONERROR|MB_OK);
           log_debug ("%s:%s: leave (bad PGP/MIME method)\n",SRCNAME,__func__);
           att->Release ();
           release_attach_info (table);
+          xfree (body);
           return gpg_error (GPG_ERR_GENERAL);
         }
 
@@ -984,27 +962,34 @@
         {
           log_error ("%s:%s: can't open data of attachment 2: hr=%#lx",
                      SRCNAME, __func__, hr);
-          MessageBox (hwnd, _("Problem decrypting PGP/MIME message"),
-                      _("Decryption"), MB_ICONERROR|MB_OK);
+          if (!preview)
+            MessageBox (hwnd, _("Problem decrypting PGP/MIME message"),
+                        _("Decryption"), MB_ICONERROR|MB_OK);
           log_debug ("%s:%s: leave (OpenProperty failed)\n",SRCNAME,__func__);
           att->Release ();
           release_attach_info (table);
+          xfree (body);
           return gpg_error (GPG_ERR_GENERAL);
         }
 
       err = pgpmime_decrypt (from, opt.passwd_ttl, &plaintext, attestation,
-                             hwnd);
+                             hwnd, preview);
       
       from->Release ();
       att->Release ();
       if (!err)
         pgpmime_succeeded = 1;
     }
-  else if (mtype == OPENPGP_CLEARSIG)
-    err = op_verify (getOrigText (false), NULL, NULL, attestation);
-  else if (*getOrigText(false))
-    err = op_decrypt (getOrigText (false), &plaintext, opt.passwd_ttl,
-                      NULL, attestation);
+  else if (mtype == OPENPGP_CLEARSIG )
+    {
+      assert (body);
+      err = preview? 0 : op_verify (body, NULL, NULL, attestation);
+    }
+  else if (body && *body)
+    {
+      err = op_decrypt (body, &plaintext, opt.passwd_ttl, NULL,
+                        attestation, preview);
+    }
   else
     err = gpg_error (GPG_ERR_NO_DATA);
   if (err)
@@ -1014,7 +999,7 @@
       else if (mtype == OPENPGP_CLEARSIG)
         MessageBox (hwnd, op_strerror (err),
                     _("Verification Failure"), MB_ICONERROR|MB_OK);
-      else
+      else if (!preview)
         MessageBox (hwnd, op_strerror (err),
                     _("Decryption Failure"), MB_ICONERROR|MB_OK);
     }
@@ -1036,12 +1021,11 @@
       if (opt.compat.old_reply_hack)
         set_message_body (message, plaintext, is_html);
 
-      xfree (body_plain);
-      body_plain = plaintext;
-      plaintext = NULL;
-      msgcache_put (body_plain, 0, message);
+      msgcache_put (plaintext, 0, message);
 
-      if (opt.save_decrypted_attach)
+      if (preview)
+        update_display (hwnd, this, exchange_cb, is_html, plaintext);
+      else if (opt.save_decrypted_attach)
         {
           /* User wants us to replace the encrypted message with the
              plaintext version. */
@@ -1049,10 +1033,10 @@
           if (FAILED (hr))
             log_debug ("%s:%s: SaveChanges failed: hr=%#lx",
                        SRCNAME, __func__, hr);
-          update_display (hwnd, this, exchange_cb, is_html);
+          update_display (hwnd, this, exchange_cb, is_html, plaintext);
           
         }
-      else if (!silent && update_display (hwnd, this, exchange_cb, is_html)) 
+      else if (update_display (hwnd, this, exchange_cb, is_html, plaintext))
         {
           const char *s = 
             _("The message text cannot be displayed.\n"
@@ -1078,7 +1062,7 @@
   /* If we have signed attachments.  Ask whether the signatures should
      be verified; we do this is case of large attachments where
      verification might take long. */
-  if (!silent && n_signed && !pgpmime_succeeded)
+  if (!preview && n_signed && !pgpmime_succeeded)
     {
       /* TRANSLATORS: Keep the @LIST@ verbatim on a separate line; it
          will be expanded to a list of atatchment names. */
@@ -1104,7 +1088,7 @@
         }
     }
 
-  if (!silent && n_encrypted && !pgpmime_succeeded)
+  if (!preview && n_encrypted && !pgpmime_succeeded)
     {
       /* TRANSLATORS: Keep the @LIST@ verbatim on a separate line; it
          will be expanded to a list of atatchment names. */
@@ -1127,9 +1111,12 @@
         }
     }
 
-  writeAttestation ();
+  if (!preview)
+    writeAttestation ();
 
   release_attach_info (table);
+  xfree (plaintext);
+  xfree (body);
   log_debug ("%s:%s: leave (rc=%d)\n", SRCNAME, __func__, err);
   return err;
 }
@@ -1143,7 +1130,7 @@
 GpgMsgImpl::sign (HWND hwnd)
 {
   HRESULT hr;
-  const char *plaintext;
+  char *plaintext;
   char *signedtext = NULL;
   int err = 0;
   gpgme_key_t sign_key = NULL;
@@ -1153,9 +1140,11 @@
   
   /* We don't sign an empty body - a signature on a zero length string
      is pretty much useless. */
-  if (!*(plaintext = getOrigText (false)) && !hasAttachments ()) 
+  plaintext = loadBody (false);
+  if ( (!plaintext || !*plaintext) && !hasAttachments ()) 
     {
       log_debug ("%s:%s: leave (empty)", SRCNAME, __func__);
+      xfree (plaintext);
       return 0; 
     }
 
@@ -1163,10 +1152,11 @@
   if (signer_dialog_box (&sign_key, NULL, 0) == -1)
     {
       log_debug ("%s.%s: leave (dialog failed)\n", SRCNAME, __func__);
+      xfree (plaintext);
       return gpg_error (GPG_ERR_CANCELED);  
     }
 
-  if (*plaintext)
+  if (plaintext && *plaintext)
     {
       err = op_sign (plaintext, &signedtext, 
                      OP_SIG_CLEAR, sign_key, opt.passwd_ttl);
@@ -1194,7 +1184,7 @@
 
   /* Now that we successfully processed the attachments, we can save
      the changes to the body.  */
-  if (*plaintext)
+  if (plaintext && *plaintext)
     {
       err = set_message_body (message, signedtext, 0);
       if (err)
@@ -1226,6 +1216,7 @@
  leave:
   xfree (signedtext);
   gpgme_key_release (sign_key);
+  xfree (plaintext);
   log_debug ("%s:%s: leave (err=%s)\n", SRCNAME, __func__, op_strerror (err));
   return err;
 }
@@ -1234,7 +1225,7 @@
 
 /* Encrypt and optionally sign (if SIGN_FLAG is true) the entire
    message including all attachments.  If WANT_HTML is true, the text
-   to encrypt will be taken from the html property. Returns 0 on
+   to encrypt will also be taken from the html property. Returns 0 on
    success. */
 int 
 GpgMsgImpl::encrypt_and_sign (HWND hwnd, bool want_html, bool sign_flag)
@@ -1243,7 +1234,7 @@
   HRESULT hr;
   gpgme_key_t *keys = NULL;
   gpgme_key_t sign_key = NULL;
-  const char *plaintext;
+  char *plaintext;
   char *ciphertext = NULL;
   char **recipients = NULL;
   char **unknown = NULL;
@@ -1251,10 +1242,11 @@
   size_t n_keys, n_unknown, n_recp;
   SPropValue prop;
     
-  
-  if (!*(plaintext = getOrigText (want_html)) && !hasAttachments ()) 
+  plaintext = loadBody (false);
+  if ( (!plaintext || !*plaintext) && !hasAttachments ()) 
     {
       log_debug ("%s:%s: leave (empty)", SRCNAME, __func__);
+      xfree (plaintext);
       return 0; 
     }
 
@@ -1264,6 +1256,7 @@
       if (signer_dialog_box (&sign_key, NULL, 1) == -1)
         {
           log_debug ("%s.%s: leave (dialog failed)\n", SRCNAME, __func__);
+          xfree (plaintext);
           return gpg_error (GPG_ERR_CANCELED);  
         }
     }
@@ -1311,7 +1304,7 @@
                    i, keyid_from_key (keys[i]), userid_from_key (keys[i]));
     }
 
-  if (*plaintext)
+  if (plaintext && *plaintext)
     {
       err = op_encrypt (plaintext, &ciphertext, 
                         keys, sign_key, opt.passwd_ttl);
@@ -1363,7 +1356,7 @@
 
   /* Now that we successfully processed the attachments, we can save
      the changes to the body.  */
-  if (*plaintext)
+  if (plaintext && *plaintext)
     {
       if (want_html)
         {
@@ -1415,6 +1408,7 @@
   free_string_array (recipients);
   free_string_array (unknown);
   xfree (ciphertext);
+  xfree (plaintext);
   log_debug ("%s:%s: leave (err=%s)\n", SRCNAME, __func__, op_strerror (err));
   return err;
 }

Modified: trunk/src/gpgmsg.hh
===================================================================
--- trunk/src/gpgmsg.hh	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/gpgmsg.hh	2005-12-01 19:24:32 UTC (rev 129)
@@ -50,25 +50,15 @@
   /* Set the callback for Exchange. */
   virtual void setExchangeCallback (void *cb) = 0;
 
-  /* Don't pop up any message boxes. */
-  virtual void setSilent (bool value) = 0;
+  /* Don't pop up any message boxes and run the decryption only on the body. */
+  virtual void setPreview (bool value) = 0;
 
   /* Return the type of the message. */
-  virtual openpgp_t getMessageType (void) = 0;
+  virtual openpgp_t getMessageType (const char *text) = 0;
 
   /* Returns whether the message has any attachments. */
   virtual bool hasAttachments (void) = 0;
 
-  /* Return the body text as received or composed.  This is guaranteed
-     to never return NULL.  Usually getMessageType is used to check
-     whether there is a suitable message. */
-  virtual const char *getOrigText (bool want_html) = 0;
-
-  /* Return the text of the message to be used for the display.  The
-     message objects has intrinsic knowledge about the correct
-     text.  */
-  virtual const char *getDisplayText (void) = 0;
-
   /* Return a malloced array of malloced strings with the recipients
      of the message. Caller is responsible for freeing this array and
      the strings.  On failure NULL is returned.  */

Modified: trunk/src/olflange.cpp
===================================================================
--- trunk/src/olflange.cpp	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/olflange.cpp	2005-12-01 19:24:32 UTC (rev 129)
@@ -781,6 +781,7 @@
   log_debug ("%s:%s: received\n", SRCNAME, __func__);
   if (opt.compat.preview_decryption)
     {
+      TRACEPOINT ();
       HRESULT hr;
       HWND hWnd = NULL;
       LPMESSAGE pMessage = NULL;
@@ -793,7 +794,7 @@
         {
           GpgMsg *m = CreateGpgMsg (pMessage);
           m->setExchangeCallback ((void*)pEECB);
-          m->setSilent (1);
+          m->setPreview (1);
           m->decrypt (hWnd);
           delete m;
 	}
@@ -950,8 +951,10 @@
 
       /* If we are encrypting we need to make sure that the other
          format gets deleted and is not actually sent in the clear.
-         Note that this otehr format is always HTML because we use the
-         regular PR_BODY for sending the _encrypted_ html. */
+         Note that this other format is always HTML because we have
+         moved that into an attachment and kept PR_BODY.  It seems
+         that OL always creates text and HTML if HTML has been
+         selected. */
       if (m_pExchExt->m_gpgEncrypt)
         {
           log_debug ("%s:%s: deleting possible extra property PR_BODY_HTML\n",
@@ -975,12 +978,13 @@
                          SRCNAME, __func__,
                          m_want_html?"PR_BODY":"PR_BODY_HTML");
               proparray.cValues = 1;
-              proparray.aulPropTag[0] = m_want_html? PR_BODY_HTML : PR_BODY;
+              proparray.aulPropTag[0] = PR_BODY;
               hr = msg->DeleteProps (&proparray, NULL);
               if (hr != S_OK)
                 log_debug ("%s:%s: DeleteProps failed: hr=%#lx\n",
                            SRCNAME, __func__, hr);
-              /* FIXME: We should delete the attachments too. */
+              /* FIXME: We should delete the attachments too. 
+                 We really, really should do this!!!          */
             }
           
         }
@@ -1048,6 +1052,7 @@
   m_lContext = 0; 
   m_nCmdEncrypt = 0;  
   m_nCmdSign = 0; 
+  m_nCmdPreviewDecrypt = 0;
   m_nToolbarButtonID1 = 0; 
   m_nToolbarButtonID2 = 0; 
   m_nToolbarBitmap1 = 0;
@@ -1359,6 +1364,13 @@
 
       m_nCmdEncrypt = *pnCommandIDBase;
       (*pnCommandIDBase)++;	
+
+      AppendMenu (hMenuTools, MF_STRING,
+                  *pnCommandIDBase, _("GPG decrypt preview"));
+
+      m_nCmdPreviewDecrypt = *pnCommandIDBase;
+      (*pnCommandIDBase)++;	
+      TRACEPOINT ();
       
       for (nTBIndex = nTBECnt-1; nTBIndex > -1; --nTBIndex)
         {
@@ -1448,7 +1460,12 @@
     }
   
 
-
+  if (nCommandID == m_nCmdPreviewDecrypt && m_lContext == EECONTEXT_VIEWER)
+    {
+      opt.compat.preview_decryption = !opt.compat.preview_decryption;
+      return S_OK;
+    }
+  
   if ((nCommandID != m_nCmdEncrypt) 
       && (nCommandID != m_nCmdSign))
     return S_FALSE; 

Modified: trunk/src/olflange.h
===================================================================
--- trunk/src/olflange.h	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/olflange.h	2005-12-01 19:24:32 UTC (rev 129)
@@ -132,6 +132,7 @@
   
   UINT  m_nCmdEncrypt;
   UINT  m_nCmdSign;
+  UINT  m_nCmdPreviewDecrypt;
 
   UINT  m_nToolbarButtonID1;
   UINT  m_nToolbarButtonID2;     

Modified: trunk/src/pgpmime.c
===================================================================
--- trunk/src/pgpmime.c	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/pgpmime.c	2005-12-01 19:24:32 UTC (rev 129)
@@ -88,6 +88,8 @@
   HWND hwnd;          /* A window handle to be used for message boxes etc. */
   rfc822parse_t msg;  /* The handle of the RFC822 parser. */
 
+  int preview;        /* Do only decryption and pop up no  message bozes.  */
+
   int nesting_level;  /* Current MIME nesting level. */
   int in_data;        /* We are currently in data (body or attachment). */
 
@@ -324,7 +326,8 @@
                 }
               else /* Other type. */
                 {
-                  ctx->collect_attachment = 1;
+                  if (!ctx->preview)
+                    ctx->collect_attachment = 1;
                 }
 
             }
@@ -375,7 +378,7 @@
               if (!gpgme_data_new (&ctx->body))
                 ctx->collect_body = 1;
             }
-          else
+          else if (!ctx->preview)
             ctx->collect_attachment = 1;
         }
 
@@ -403,9 +406,9 @@
             }
         tryagain:
           xfree (ctx->filename);
-          ctx->filename = get_save_filename (ctx->hwnd, p);
+          ctx->filename = ctx->preview? NULL:get_save_filename (ctx->hwnd, p);
           if (!ctx->filename)
-            ctx->collect_attachment = 0; /* User das not want to save it. */
+            ctx->collect_attachment = 0; /* User does not want to save it. */
           else
             {
               hr = OpenStreamOnFile (MAPIAllocateBuffer, MAPIFreeBuffer,
@@ -416,7 +419,7 @@
                   log_error ("%s:%s: can't create file `%s': hr=%#lx\n",
                              SRCNAME, __func__, ctx->filename, hr); 
                   MessageBox (ctx->hwnd, _("Error creating file\n"
-                              "Please select another one"),
+                                           "Please select another one"),
                               _("I/O-Error"), MB_ICONERROR|MB_OK);
                   goto tryagain;
                 }
@@ -549,8 +552,9 @@
                     {
                       log_debug ("%s:%s: Write failed: hr=%#lx",
                                  SRCNAME, __func__, hr);
-                      MessageBox (ctx->hwnd, _("Error writing file"),
-                                  _("I/O-Error"), MB_ICONERROR|MB_OK);
+                      if (!ctx->preview)
+                        MessageBox (ctx->hwnd, _("Error writing file"),
+                                    _("I/O-Error"), MB_ICONERROR|MB_OK);
                       ctx->parser_error = 1;
                       return 0; /* Error. */
                     }
@@ -572,10 +576,11 @@
    newly allocated body will be stored at BODY.  If ATTESTATION is not
    NULL a text with the result of the signature verification will get
    printed to it.  HWND is the window to be used for message box and
-   such. */
+   such.  In PREVIEW_MODE no verification will be done, no messages
+   saved and no messages boxes will pop up. */
 int
 pgpmime_decrypt (LPSTREAM instream, int ttl, char **body,
-                 gpgme_data_t attestation, HWND hwnd)
+                 gpgme_data_t attestation, HWND hwnd, int preview_mode)
 {
   gpg_error_t err;
   struct gpgme_data_cbs cbs;
@@ -590,6 +595,7 @@
   ctx = xcalloc (1, sizeof *ctx + LINEBUFSIZE);
   ctx->linebufsize = LINEBUFSIZE;
   ctx->hwnd = hwnd;
+  ctx->preview = preview_mode;
 
   ctx->msg = rfc822parse_open (message_cb, ctx);
   if (!ctx->msg)
@@ -604,7 +610,8 @@
     goto leave;
 
   err = op_decrypt_stream_to_gpgme (instream, plaintext, ttl,
-                                    _("[PGP/MIME message]"), attestation);
+                                    _("[PGP/MIME message]"), attestation,
+                                    preview_mode);
   if (!err && (ctx->parser_error || ctx->line_too_long))
     err = gpg_error (GPG_ERR_GENERAL);
 

Modified: trunk/src/pgpmime.h
===================================================================
--- trunk/src/pgpmime.h	2005-11-30 16:47:27 UTC (rev 128)
+++ trunk/src/pgpmime.h	2005-12-01 19:24:32 UTC (rev 129)
@@ -29,7 +29,8 @@
 #endif
 
 int pgpmime_decrypt (LPSTREAM instream, int ttl, char **body,
-                     gpgme_data_t attestation, HWND hwnd);
+                     gpgme_data_t attestation, HWND hwnd,
+                     int preview_mode);
 
 
 




More information about the Gnupg-commits mailing list