[git] GpgOL - branch, nomapi, updated. gpgol-1.4.0-61-gef8ea4a

by Andre Heinecke cvs at cvs.gnupg.org
Wed Sep 28 14:34:17 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG extension for MS Outlook".

The branch, nomapi has been updated
       via  ef8ea4a537110d49503a4ceb2bb6d7214c7b2594 (commit)
       via  a03012210f54663f276f9e043363c3dd6f9e41bf (commit)
       via  6138fb13820c312bb94664241d06f64359a9d650 (commit)
       via  dbf10ad74b3ba1bd3955e4c1ef3fae57b3fee3af (commit)
      from  3600d2b2e9193458e47d3849dcd2df58429aed05 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ef8ea4a537110d49503a4ceb2bb6d7214c7b2594
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Sep 28 14:32:39 2016 +0200

    tests: Add test for data with no headers
    
    * tests/data/openpgp-encrypted-attachment-no-headers.mbox: New.
    * tests/t-parser: Use it. Correct some types.

diff --git a/tests/data/openpgp-encrypted-attachment-no-headers.mbox b/tests/data/openpgp-encrypted-attachment-no-headers.mbox
new file mode 100644
index 0000000..57725a2
--- /dev/null
+++ b/tests/data/openpgp-encrypted-attachment-no-headers.mbox
@@ -0,0 +1,32 @@
+-----BEGIN PGP MESSAGE-----
+Version: GnuPG v2
+
+hIwDGJlthTT7oq0BBACLMnR5Mln6JGCccvqZCgM3qUkFWZ7a33b7Nl2g5lSOLX6q
+dlGOr/0jAuqdkRwCDTom3hsrH2vf1kARTSST+5cewngS2CgBTAwwc8JymEagTkKf
+VK/tTnM6G7puMVkwuafpuRggyJAUYvjktgUKOUaXtuxX71g0NagAFQGqlvGuq4UB
+DAMMzkNap8zaOwEH+wWSs5xdV1x37T11EnUvkhoOMu+uId2U7NEx2JdQ/FGJZdti
+mtqfM9GKTtQlGVcn3ISH7Wmrw3x0bsOLuW7oxkU4xIS3tVvibxaaWdmponN5TUai
+Dr4LCTEmG7+jLNopF6V4zPmpQ9YxMwQOm8ITml+auNOg9EtHxavwr3Xd1hOYA92N
+1bkOiHzmb9hQtUy1GfRRk91tRqtRPoaamczLxWV9yROFDRNuSSbZ8oBU/K4YgSTL
+D+/FhCt6MxV0DQzp+UCSL7ZsMx+ldPnZK44Udd17+U3xQDDUffo6cSg6FAF425Rh
+v3ZQP0j7LtSIwDh2Rxc+Is4DuSmfZksL5nLPH5nS6QGJnsVEqVcZgQPktl1Zaeil
+x/6WaWruuJm92G2fd9x2/giTLZnk918BVi/n00xR/n4bnSQmmFhXVqAVjGlG6Tr9
+dxej8dSiFdxO8ZjFe5tguQw76xlCu/9MxmSXTP7Mfvm4jqdcjUOINwHOzR/h2T62
+ZlrmqoxMHm4RN0PQ334tSzQXD4gcoUHL+xq62ATt7/jx0p0pIXPmPVUFopCk8k1E
+m2ErPLnyfGLd4LNZRL03oP0jCjX6Q/LFWLTjCIdU6+aM6nT26CZy98yZV0SRGyhu
+qYxN0aVW+RatmDRWWtouOJllQouQ7ZaqmjHLgyOj32/oT8cYUWWdFswSsnMhJjxb
+r6iajUeAZgiN+zqwgf6j1Z8/mMvb+yirP+Rn9ME1fq3XSYHlnIOxKNBa+St8DdaP
+/ZvrkwNTpVp1GmaZLBXdqdeLmflJ4U/X7wphZGR3sgjOwj0oYotX1Zb8OrtlP5WC
+VXhhrt40e7Ilt2B0x7Xe9DWKByDCqrQUhwxwTS3miiKH9G1VEcHko70O98RjKJQ3
+I4VW6e/Gqv2zAMiiOu1MBTeGfPQItca4bUrVzhKjm27twtZD4wLSQDTQECxrCWHC
+BFAdzvsIry0FIXoO6Vh16Hojq+YZ8tpmknGfpg0pnuRvAdDWU+0uuECXDE0UZFWC
+2g3Bs2Dn2BYYyrI6X92swHz8qP3JvdxN0dpsYMkMdHN4yWXJogNSfXzy2udf0A4P
+NNZMOonhlwH+DBRfcWS0A/j0/fdDCDzR5Ca5dbX7lL4EscbBeoCP1JJyVoOp6DUc
+ICuHJGGrnpNdG9DMa97tqpyGRHTAwI3lJXPKTDEHN9v9XobIyndFgi/tcPLZ7QWz
+9mN94NKLmeYWjrMiRbNQk8BYXR9K17SHb4BkIMdBxRsJjgMEC8qniUH64Nnf8/x4
+yaRCuUo0bkHDE3AqCzZE1R0he66dDkfOIz+mLwcpG8jZWjFm7sXAflBe3jvIc0lm
+NyWQ1WnMkP83fWm/+YqrLLf+tTQtievRPeS1Dd/7v9yqUWEmQ0pUOj3MNf9Ej2KI
+vu5ap7fHIevcBn42BPwQgSnp4YmXEY0ir5Ccwogusnt7QliNSRmkN6Jap4AF
+=AVJ4
+-----END PGP MESSAGE-----
+
diff --git a/tests/t-parser.cpp b/tests/t-parser.cpp
index 0d1f494..d1c260e 100644
--- a/tests/t-parser.cpp
+++ b/tests/t-parser.cpp
@@ -51,13 +51,20 @@ struct
     0,
     "iso-8859-1"},
   { DATADIR "/openpgp-encrypted+signed.mbox",
-    MSGTYPE_GPGOL_MULTIPART_SIGNED,
+    MSGTYPE_GPGOL_MULTIPART_ENCRYPTED,
     DATADIR "/openpgp-encrypted+signed.plain",
     NULL,
     0,
     "us-ascii"},
   { DATADIR "/openpgp-encrypted-attachment.mbox",
-    MSGTYPE_GPGOL_MULTIPART_SIGNED,
+    MSGTYPE_GPGOL_MULTIPART_ENCRYPTED,
+    DATADIR "/openpgp-encrypted-attachment.plain",
+    NULL,
+    1,
+    "us-ascii"},
+  /* Same as above but without any headers */
+  { DATADIR "/openpgp-encrypted-attachment-no-headers.mbox",
+    MSGTYPE_GPGOL_MULTIPART_ENCRYPTED,
     DATADIR "/openpgp-encrypted-attachment.plain",
     NULL,
     1,

commit a03012210f54663f276f9e043363c3dd6f9e41bf
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Sep 28 14:25:55 2016 +0200

    Add error handling for decryption errors
    
    * src/mail.cpp (update_body): New helper.
    * src/parsecontroller.cpp (format_error): New.
    (format_recipients): New.
    (ParseController::Parse): Store formatted error, change signature.
    (get_formatted_error): Get a HTML Formatted error.
    * tests/run-parser.cpp (main),
    tests/t-parser.cpp (main): Adjust to new API

diff --git a/src/mail.cpp b/src/mail.cpp
index dd6ca68..4c488eb 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -67,19 +67,6 @@ static std::map<LPDISPATCH, Mail*> g_mail_map;
 "</td></tr>" \
 "</table></body></html>"
 
-#define WAIT_TEMPLATE \
-"<html><head></head><body>" \
-"<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#0069cc\">" \
-"<tr>" \
-"<td bgcolor=\"#0080ff\">" \
-"<p><span style=\"font-weight:600; background-color:#0080ff;\"><center>This message is encrypted</center><span></p></td></tr>" \
-"<tr>" \
-"<td bgcolor=\"#e0f0ff\">" \
-"<center>" \
-"<br/>Please wait while the message is decrypted by GpgOL..." \
-"</td></tr>" \
-"</table></body></html>"
-
 Mail::Mail (LPDISPATCH mailitem) :
     m_mailitem(mailitem),
     m_processed(false),
@@ -296,20 +283,32 @@ Mail::decrypt_verify()
     }
 
   m_processed = true;
-  /* Inser placeholder */
-  if (put_oom_string (m_mailitem, "HTMLBody", WAIT_TEMPLATE))
+  /* Insert placeholder */
+  char *placeholder_buf;
+  if (gpgrt_asprintf (&placeholder_buf, decrypt_template,
+                      is_smime() ? "S/MIME" : "OpenPGP",
+                      _("Encrypted message"),
+                      _("Please wait while the message is being decrypted...")) == -1)
+    {
+      log_error ("%s:%s: Failed to format placeholder.",
+                 SRCNAME, __func__);
+      return 1;
+    }
+
+  if (put_oom_string (m_mailitem, "HTMLBody", placeholder_buf))
     {
       log_error ("%s:%s: Failed to modify html body of item.",
                  SRCNAME, __func__);
+      xfree (placeholder_buf);
       return 1;
     }
+  xfree (placeholder_buf);
 
   /* Do the actual parsing */
   auto cipherstream = get_cipherstream (m_mailitem, m_moss_position);
 
   if (!cipherstream)
     {
-      /* TODO Error message? */
       log_debug ("%s:%s: Failed to get cipherstream.",
                  SRCNAME, __func__);
       return 1;
@@ -323,10 +322,20 @@ Mail::decrypt_verify()
   return 0;
 }
 
-void Mail::parsing_done()
+void
+Mail::update_body()
 {
-  m_needs_wipe = true;
-  /* Update the body */
+  const auto error = m_parser->get_formatted_error ();
+  if (!error.empty())
+    {
+      if (put_oom_string (m_mailitem, "HTMLBody",
+                          error.c_str ()))
+        {
+          log_error ("%s:%s: Failed to modify html body of item.",
+                     SRCNAME, __func__);
+        }
+      return;
+    }
   const auto html = m_parser->get_html_body();
   if (!html.empty())
     {
@@ -347,6 +356,14 @@ void Mail::parsing_done()
           return;
         }
     }
+}
+
+void
+Mail::parsing_done()
+{
+  m_needs_wipe = true;
+  /* Update the body */
+  update_body();
 
   /* Update attachments */
   if (add_attachments (m_mailitem, m_parser->get_attachments()))
diff --git a/src/mail.h b/src/mail.h
index dcca439..af47f13 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -195,6 +195,8 @@ public:
   */
   void parsing_done ();
 private:
+  void update_body ();
+
   LPDISPATCH m_mailitem;
   LPDISPATCH m_event_sink;
   bool m_processed,    /* The message has been porcessed by us.  */
diff --git a/src/parsecontroller.cpp b/src/parsecontroller.cpp
index b88eaa7..2235c30 100644
--- a/src/parsecontroller.cpp
+++ b/src/parsecontroller.cpp
@@ -134,7 +134,64 @@ is_opaque_signed (Data &data)
   return id == Data::CMSSigned;
 }
 
-std::string
+static std::string
+format_recipients(GpgME::DecryptionResult result)
+{
+  std::string msg;
+  for (const auto recipient: result.recipients())
+    {
+      msg += std::string("<br/>0x") + recipient.keyID() + "</a>";
+    }
+  return msg;
+}
+
+static std::string
+format_error(GpgME::DecryptionResult result, Protocol protocol)
+{
+  char *buf;
+  bool no_sec = false;
+  std::string msg;
+
+  if (result.error ().isCanceled () ||
+      result.error ().code () == GPG_ERR_NO_SECKEY)
+    {
+       msg = _("Decryption canceled or timed out.");
+    }
+
+  if (result.error ().code () == GPG_ERR_DECRYPT_FAILED)
+    {
+      no_sec = true;
+      for (const auto &recipient: result.recipients ()) {
+        no_sec &= (recipient.status ().code () == GPG_ERR_NO_SECKEY);
+      }
+    }
+
+  if (no_sec)
+    {
+      msg = _("No secret key found to decrypt the message."
+              "It is encrypted for following keys:");
+      msg += format_recipients (result);
+    }
+  else
+    {
+      msg = _("Could not decrypt the data.");
+    }
+
+  if (gpgrt_asprintf (&buf, decrypt_template,
+                      protocol == OpenPGP ? "OpenPGP" : "S/MIME",
+                      _("Encrypted message (decryption not possible)"),
+                      msg.c_str()) == -1)
+    {
+      log_error ("%s:%s:Failed to Format error.",
+                 SRCNAME, __func__);
+      return "Failed to Format error.";
+    }
+  msg = buf;
+  return msg;
+}
+
+
+void
 ParseController::parse()
 {
   // Wrap the input stream in an attachment / GpgME Data
@@ -146,26 +203,28 @@ ParseController::parse()
     {
       log_error ("%s:%s:Failed to create context. Installation broken.",
                  SRCNAME, __func__);
-      // TODO proper error handling
-      return std::string("Bad installation");
+      char *buf;
+      const char *proto = protocol == OpenPGP ? "OpenPGP" : "S/MIME";
+      if (gpgrt_asprintf (&buf, decrypt_template,
+                          proto,
+                          _("Encrypted message (decryption not possible)"),
+                          _("Failed to find GnuPG please ensure that GnuPG or "
+                            "Gpg4win is properly installed.")) == -1)
+        {
+          log_error ("%s:%s:Failed format error.",
+                     SRCNAME, __func__);
+          /* Should never happen */
+          m_error = std::string("Bad installation");
+        }
+      m_error = buf;
+      xfree (buf);
+      return;
     }
   ctx->setArmor(true);
 
   Data output(m_outputprovider);
 
-  Data input;
-  if (m_type == MSGTYPE_GPGOL_CLEAR_SIGNED ||
-      m_type == MSGTYPE_GPGOL_PGP_MESSAGE)
-    {
-      /* For clearsigned and PGP Message take the body.
-         This does not copy the data. */
-      input = Data (m_inputprovider->get_body().c_str(),
-                    m_inputprovider->get_body().size(), false);
-    }
-  else
-    {
-      input = Data (m_inputprovider);
-    }
+  Data input (m_inputprovider);
   log_debug ("%s:%s: decrypt: %i verify: %i with protocol: %s",
              SRCNAME, __func__,
              decrypt, verify,
@@ -195,6 +254,10 @@ ParseController::parse()
         {
           verify = false;
         }
+      if (m_decrypt_result.error())
+        {
+          m_error = format_error (m_decrypt_result, protocol);
+        }
     }
   if (verify)
     {
@@ -230,13 +293,7 @@ ParseController::parse()
        ss << m_decrypt_result << '\n' << m_verify_result;
        log_debug ("Decrypt / Verify result: %s", ss.str().c_str());
     }
-  /*
-  Attachment *att = new Attachment ();
-  att->write ("Hello attachment", strlen ("Hello attachment"));
-  att->set_display_name ("The Attachment.txt");
-  m_attachments.push_back (std::shared_ptr<Attachment>(att));
-  */
-  return std::string();
+  return;
 }
 
 const std::string
diff --git a/src/parsecontroller.h b/src/parsecontroller.h
index 350350d..1dd036b 100644
--- a/src/parsecontroller.h
+++ b/src/parsecontroller.h
@@ -43,6 +43,9 @@ class MimeDataProvider;
 #include "oomhelp.h"
 #endif
 
+/* A template for decryption errors / status message. */
+extern const char decrypt_template[];
+
 class ParseController
 {
 public:
@@ -57,13 +60,9 @@ public:
 
   ~ParseController();
 
-  /** Construct a new ParseController for an inline message where
-    the content is pointet to by body.
-  ParseController(const char *body, msgtype_t type);
-  */
-  /** Main entry point. Parses the Mail returns an
-    * empty string on success or an error message on failure. */
-  std::string parse();
+  /** Main entry point. After execution getters will become
+  valid. */
+  void parse();
 
   /** Get the Body. Call parse first. */
   const std::string get_body() const;
@@ -89,12 +88,15 @@ public:
   const GpgME::VerificationResult verify_result() const
   { return m_verify_result; }
 
+  const std::string get_formatted_error() const
+  { return m_error; }
+
 private:
   /* State variables */
   MimeDataProvider *m_inputprovider;
   MimeDataProvider *m_outputprovider;
   msgtype_t m_type;
-  bool m_error;
+  std::string m_error;
   GpgME::DecryptionResult m_decrypt_result;
   GpgME::VerificationResult m_verify_result;
 };
diff --git a/tests/run-parser.cpp b/tests/run-parser.cpp
index 4c804fd..b6db615 100644
--- a/tests/run-parser.cpp
+++ b/tests/run-parser.cpp
@@ -106,7 +106,7 @@ int main(int argc, char **argv)
 
     {
       ParseController parser(fp_in, msgtype);
-      std::cout << "Parse result: " << parser.parse();
+      std::cout << "Parse error: " << parser.get_formatted_error ();
       std::cout << "\nDecrypt result:\n" << parser.decrypt_result()
                 << "\nVerify result:\n" << parser.verify_result()
                 << "\nBEGIN BODY\n" << parser.get_body() << "\nEND BODY"
diff --git a/tests/t-parser.cpp b/tests/t-parser.cpp
index b6b9f33..0d1f494 100644
--- a/tests/t-parser.cpp
+++ b/tests/t-parser.cpp
@@ -29,7 +29,6 @@ struct
   msgtype_t type;
   const char *expected_body_file;
   const char *expected_html_body_file;
-  const char *expected_return;
   int attachment_cnt;
   const char *expected_charset;
 } test_data[] = {
@@ -37,59 +36,51 @@ struct
     MSGTYPE_GPGOL_PGP_MESSAGE,
     DATADIR "/inlinepgpencrypted.plain",
     NULL,
-    NULL,
     0,
     NULL},
   { DATADIR "/openpgp-encrypted.mbox",
     MSGTYPE_GPGOL_MULTIPART_ENCRYPTED,
     DATADIR "/openpgp-encrypted.plain",
     NULL,
-    NULL,
     0,
     NULL},
   { DATADIR "/openpgp-signed-no-attach.mbox",
     MSGTYPE_GPGOL_MULTIPART_SIGNED,
     DATADIR "/openpgp-signed-no-attach.plain",
     NULL,
-    NULL,
     0,
     "iso-8859-1"},
   { DATADIR "/openpgp-encrypted+signed.mbox",
     MSGTYPE_GPGOL_MULTIPART_SIGNED,
     DATADIR "/openpgp-encrypted+signed.plain",
     NULL,
-    NULL,
     0,
     "us-ascii"},
   { DATADIR "/openpgp-encrypted-attachment.mbox",
     MSGTYPE_GPGOL_MULTIPART_SIGNED,
     DATADIR "/openpgp-encrypted-attachment.plain",
     NULL,
-    NULL,
     1,
     "us-ascii"},
   { DATADIR "/smime-opaque-sign.mbox",
     MSGTYPE_GPGOL_OPAQUE_SIGNED,
     DATADIR "/smime-opaque-sign.plain",
     NULL,
-    NULL,
     0,
     "utf-8"},
   { DATADIR "/smime-encrypted.mbox",
     MSGTYPE_GPGOL_OPAQUE_ENCRYPTED,
     DATADIR "/smime-encrypted.plain",
     NULL,
-    NULL,
     0,
     "us-ascii"},
   { DATADIR "/smime-opaque-signed-encrypted-attachment.mbox",
     MSGTYPE_GPGOL_OPAQUE_ENCRYPTED,
     DATADIR "/smime-opaque-signed-encrypted-attachment.plain",
     NULL,
-    NULL,
     1,
     "us-ascii"},
-  { NULL, MSGTYPE_UNKNOWN, NULL, NULL, NULL, 0, NULL }
+  { NULL, MSGTYPE_UNKNOWN, NULL, NULL, 0, NULL }
 };
 
 
@@ -112,7 +103,7 @@ int main()
 
       fclose(input);
 
-      auto result = parser.parse();
+      parser.parse();
 
       auto decResult = parser.decrypt_result();
       auto verifyResult = parser.verify_result();
@@ -125,15 +116,6 @@ int main()
           exit(1);
         }
 
-      if (test_data[i].expected_return)
-        {
-          if (result != test_data[i].expected_return)
-            {
-              fprintf (stderr, "Failed to get expected return. Return was: %s\n",
-                       result.c_str());
-              exit(1);
-            }
-        }
       if (test_data[i].expected_body_file)
         {
           auto expected_body = fopen (test_data[i].expected_body_file, "rb");

commit 6138fb13820c312bb94664241d06f64359a9d650
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Sep 28 14:21:47 2016 +0200

    Fix handling of MIMEData without Headers
    
    * src/mimedataprovider.cpp (MimeDataProvider): Add ctor
    variants with no_headers field.
    * src/mimedataprovider.h: Update Accordingly.
    * src/parsecontroller.cpp (expect_no_headers): Expect
    no headers except for some messages.
    (decrypt_template): New to be used for status messages.
    
    --
    This covers the problem that GpgOL only sees crypto data as an
    attachment and not the original outer mime structure.

diff --git a/src/mimedataprovider.cpp b/src/mimedataprovider.cpp
index 27ad3ee..20f2fe1 100644
--- a/src/mimedataprovider.cpp
+++ b/src/mimedataprovider.cpp
@@ -375,15 +375,18 @@ message_cb (void *opaque, rfc822parse_event_t event,
   debug_message_event (event);
   if (ctx->no_mail_header)
     {
-      /* Assume that this is not a regular mail but plain text. */
       if (event == RFC822PARSE_OPEN)
-        return 0; /*  We need to skip the OPEN event.  */
+        {
+          /* We ignore the open event */
+          return 0;
+        }
+      /* Assume that this is not a regular mail but plain text. */
       if (!ctx->body_seen)
         {
           log_mime_parser ("%s:%s: assuming this is plain text without headers\n",
                            SRCNAME, __func__);
-          ctx->in_data = 1;
-          ctx->collect_attachment = 2; /* 2 so we don't skip the first line. */
+          ctx->start_hashing = 1;
+          ctx->collect_crypto_data = 1;
           ctx->body_seen = 1;
           /* Create a fake MIME structure.  */
           /* Fixme: We might want to take it from the enclosing message.  */
@@ -402,7 +405,6 @@ message_cb (void *opaque, rfc822parse_event_t event,
             ms->filename = NULL;
             ms->charset = NULL;
           }
-          ctx->collect_body = 1;
         }
       return 0;
     }
@@ -467,17 +469,21 @@ message_cb (void *opaque, rfc822parse_event_t event,
   return retval;
 }
 
-MimeDataProvider::MimeDataProvider() :
+MimeDataProvider::MimeDataProvider(bool no_headers) :
   m_signature(nullptr)
 {
   m_mime_ctx = (mime_context_t) xcalloc (1, sizeof *m_mime_ctx);
   m_mime_ctx->msg = rfc822parse_open (message_cb, this);
   m_mime_ctx->mimestruct_tail = &m_mime_ctx->mimestruct;
+  if (no_headers)
+    {
+      m_mime_ctx->no_mail_header = 1;
+    }
 }
 
 #ifdef HAVE_W32_SYSTEM
-MimeDataProvider::MimeDataProvider(LPSTREAM stream):
-  MimeDataProvider()
+MimeDataProvider::MimeDataProvider(LPSTREAM stream, bool no_headers):
+  MimeDataProvider(no_headers)
 {
   if (stream)
     {
@@ -495,8 +501,8 @@ MimeDataProvider::MimeDataProvider(LPSTREAM stream):
 }
 #endif
 
-MimeDataProvider::MimeDataProvider(FILE *stream):
-  MimeDataProvider()
+MimeDataProvider::MimeDataProvider(FILE *stream, bool no_headers):
+  MimeDataProvider(no_headers)
 {
   log_mime_parser ("%s:%s Collecting data from file.", SRCNAME, __func__);
   collect_data (stream);
diff --git a/src/mimedataprovider.h b/src/mimedataprovider.h
index 28661a7..661e0ca 100644
--- a/src/mimedataprovider.h
+++ b/src/mimedataprovider.h
@@ -61,14 +61,19 @@ class MimeDataProvider : public GpgME::DataProvider
 {
 public:
   /* Create an empty dataprovider, useful for writing to. */
-  MimeDataProvider();
+  MimeDataProvider(bool no_headers = false);
 #ifdef HAVE_W32_SYSTEM
   /* Read and parse the stream. Does not hold a reference
-     to the stream but releases it after read. */
-  MimeDataProvider(LPSTREAM stream);
+     to the stream but releases it after read.
+
+     If no_headers is set to true, assume that there are no
+     headers and immediately start collecting crypto data.
+     Eg. When decrypting a MOSS Attachment.
+     */
+  MimeDataProvider(LPSTREAM stream, bool no_headers = false);
 #endif
   /* Test instrumentation. */
-  MimeDataProvider(FILE *stream);
+  MimeDataProvider(FILE *stream, bool no_headers = false);
   ~MimeDataProvider();
 
   /* Dataprovider interface */
diff --git a/src/parsecontroller.cpp b/src/parsecontroller.cpp
index acec830..b88eaa7 100644
--- a/src/parsecontroller.cpp
+++ b/src/parsecontroller.cpp
@@ -29,28 +29,60 @@
 
 #include <sstream>
 
+#ifdef HAVE_W32_SYSTEM
+#include "common.h"
+/* We use UTF-8 internally. */
+#undef _
+# define _(a) utf8_gettext (a)
+#else
+# define _(a) a
+#endif
+
+
+
+const char decrypt_template[] = {
+"<html><head></head><body>"
+"<table border=\"0\" width=\"100%%\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#0069cc\">"
+"<tr>"
+"<td bgcolor=\"#0080ff\">"
+"<p><span style=\"font-weight:600; background-color:#0080ff;\"><center>%s %s</center><span></p></td></tr>"
+"<tr>"
+"<td bgcolor=\"#e0f0ff\">"
+"<center>"
+"<br/>%s"
+"</td></tr>"
+"</table></body></html>"};
+
 using namespace GpgME;
 
+static bool
+expect_no_headers (msgtype_t type)
+{
+  return type != MSGTYPE_GPGOL_MULTIPART_SIGNED &&
+         type != MSGTYPE_GPGOL_OPAQUE_SIGNED &&
+         type != MSGTYPE_GPGOL_OPAQUE_ENCRYPTED;
+}
+
 #ifdef HAVE_W32_SYSTEM
 ParseController::ParseController(LPSTREAM instream, msgtype_t type):
-    m_inputprovider  (new MimeDataProvider(instream)),
+    m_inputprovider  (new MimeDataProvider(instream,
+                          expect_no_headers(type))),
     m_outputprovider (new MimeDataProvider()),
-    m_type (type),
-    m_error (false)
+    m_type (type)
 {
-  log_mime_parser ("%s:%s: Creating parser for stream: %p",
-                   SRCNAME, __func__, instream);
+  log_mime_parser ("%s:%s: Creating parser for stream: %p of type %i",
+                   SRCNAME, __func__, instream, type);
 }
 #endif
 
 ParseController::ParseController(FILE *instream, msgtype_t type):
-    m_inputprovider  (new MimeDataProvider(instream)),
+    m_inputprovider  (new MimeDataProvider(instream,
+                          expect_no_headers(type))),
     m_outputprovider (new MimeDataProvider()),
-    m_type (type),
-    m_error (false)
+    m_type (type)
 {
-  log_mime_parser ("%s:%s: Creating parser for stream: %p",
-                   SRCNAME, __func__, instream);
+  log_mime_parser ("%s:%s: Creating parser for stream: %p of type %i",
+                   SRCNAME, __func__, instream, type);
 }
 
 ParseController::~ParseController()

commit dbf10ad74b3ba1bd3955e4c1ef3fae57b3fee3af
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Tue Sep 27 15:04:11 2016 +0200

    Remove unused variable
    
    * src/mimedataprovider.cpp (t2body): Remove smtype.
    
    --
    smtype is no longer needed. We let GpgME decide if we have
    S/MIME Data after decryption.

diff --git a/src/mimedataprovider.cpp b/src/mimedataprovider.cpp
index 1727da2..27ad3ee 100644
--- a/src/mimedataprovider.cpp
+++ b/src/mimedataprovider.cpp
@@ -319,8 +319,6 @@ t2body (MimeDataProvider *provider, rfc822parse_t msg)
           && (!strcmp (ctsub, "pkcs7-mime")
               || !strcmp (ctsub, "x-pkcs7-mime")))
         {
-          const char *smtype = rfc822parse_query_parameter (field,
-                                                            "smime-type", 0);
           ctx->collect_crypto_data = 1;
         }
     }

-----------------------------------------------------------------------

Summary of changes:
 src/mail.cpp                                       |  55 +++++---
 src/mail.h                                         |   2 +
 src/mimedataprovider.cpp                           |  28 ++--
 src/mimedataprovider.h                             |  13 +-
 src/parsecontroller.cpp                            | 155 ++++++++++++++++-----
 src/parsecontroller.h                              |  18 +--
 ...> openpgp-encrypted-attachment-no-headers.mbox} |  89 +++++-------
 tests/run-parser.cpp                               |   2 +-
 tests/t-parser.cpp                                 |  31 ++---
 9 files changed, 238 insertions(+), 155 deletions(-)
 copy tests/data/{openpgp-encrypted-attachment.mbox => openpgp-encrypted-attachment-no-headers.mbox} (68%)


hooks/post-receive
-- 
GnuPG extension for MS Outlook
http://git.gnupg.org




More information about the Gnupg-commits mailing list