[svn] GpgOL - r221 - in trunk: doc po src

svn author wk cvs at cvs.gnupg.org
Wed Feb 13 20:18:56 CET 2008


Author: wk
Date: 2008-02-13 20:18:55 +0100 (Wed, 13 Feb 2008)
New Revision: 221

Modified:
   trunk/doc/gpgol.texi
   trunk/po/de.po
   trunk/po/sv.po
   trunk/src/ChangeLog
   trunk/src/mapihelp.cpp
   trunk/src/mapihelp.h
   trunk/src/mimeparser.c
Log:
Take care of other charsets than utf-8.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-02-11 10:36:20 UTC (rev 220)
+++ trunk/src/ChangeLog	2008-02-13 19:18:55 UTC (rev 221)
@@ -1,3 +1,11 @@
+2008-02-13  Werner Koch  <wk at g10code.com>
+
+	* mapihelp.cpp (get_gpgolcharset_tag, mapi_get_gpgol_charset) 
+	(mapi_set_gpgol_charset): New. 
+	(mapi_get_gpgol_body_attachment): Transcode from Latin-1.
+	* mimeparser.c (start_attachment): Set the charset property.
+	(struct mime_context): Remove is_utf8 field.
+
 2008-02-11  Werner Koch  <wk at g10code.com>
 
 	* common.h (tlvinfo_t): New.

Modified: trunk/doc/gpgol.texi
===================================================================
--- trunk/doc/gpgol.texi	2008-02-11 10:36:20 UTC (rev 220)
+++ trunk/doc/gpgol.texi	2008-02-13 19:18:55 UTC (rev 221)
@@ -600,6 +600,11 @@
 re-encrypted attachment.  The existence of this property indicates that
 the attachment has been encrypted under the non-permanent session key.
 
+ at item GpgOL Charset
+This is a property of type STRING8 and used to describe the character
+set of an attachment or of the body.  If this propery is missing the
+default of UTF-8 is assumed.
+
 @item GpgOL Last Decrypted
 This binary property is used on the message to save a session marker to
 tell GpgOL whether the message as already been decrypted.  If this

Modified: trunk/po/de.po  [not shown]
Modified: trunk/po/sv.po  [not shown]
Modified: trunk/src/mapihelp.cpp
===================================================================
--- trunk/src/mapihelp.cpp	2008-02-11 10:36:20 UTC (rev 220)
+++ trunk/src/mapihelp.cpp	2008-02-13 19:18:55 UTC (rev 221)
@@ -21,6 +21,7 @@
 #include <config.h>
 #endif
 
+#include <ctype.h>
 #include <windows.h>
 
 #include "mymapi.h"
@@ -198,7 +199,17 @@
 }
 
 
+/* Return the property tag for GpgOL Charset. */
+int 
+get_gpgolcharset_tag (LPMESSAGE message, ULONG *r_tag)
+{
+  if (!(*r_tag = create_gpgol_tag (message, L"GpgOL Charset", __func__)))
+    return -1;
+  *r_tag |= PT_STRING8;
+  return 0;
+}
 
+
 /* Set an arbitary header in the message MSG with NAME to the value
    VAL. */
 int
@@ -1792,6 +1803,69 @@
 }
 
 
+/* Return the charset as assigned by GpgOL to an attachment.  This may
+   return NULL it is has not been assigned or is the standard
+   (UTF-8). */
+char *
+mapi_get_gpgol_charset (LPMESSAGE obj)
+{
+  HRESULT hr;
+  LPSPropValue propval = NULL;
+  ULONG tag;
+  char *retstr;
+
+  if (get_gpgolcharset_tag (obj, &tag) )
+    return NULL; /* Error.  */
+  hr = HrGetOneProp ((LPMAPIPROP)obj, tag, &propval);
+  if (FAILED (hr))
+    return NULL;
+  if (PROP_TYPE (propval->ulPropTag) == PT_STRING8)
+    {
+      if (!strcmp (propval->Value.lpszA, "utf-8"))
+        retstr = NULL;
+      else
+        retstr = xstrdup (propval->Value.lpszA);
+    }
+  else
+    retstr = NULL;
+
+  MAPIFreeBuffer (propval);
+  return retstr;
+}
+
+
+/* Set the GpgOl charset t an asstachment. 
+   Note that this function does not call SaveChanges.  */
+int 
+mapi_set_gpgol_charset (LPMESSAGE obj, const char *charset)
+{
+  HRESULT hr;
+  SPropValue prop;
+  char *p;
+
+  /* Note that we lowercase the value and cut it to a max of 32
+     characters.  The latter is required to make sure that
+     HrSetOneProp will always work.  */
+  if (get_gpgolcharset_tag (obj, &prop.ulPropTag) )
+    return -1;
+  prop.Value.lpszA = xstrdup (charset);
+  for (p=prop.Value.lpszA; *p; p++)
+    *p = tolower (*(unsigned char*)p);
+  if (strlen (prop.Value.lpszA) > 32)
+    prop.Value.lpszA[32] = 0;
+  hr = HrSetOneProp ((LPMAPIPROP)obj, &prop);	
+  xfree (prop.Value.lpszA);
+  if (hr)
+    {
+      log_error ("%s:%s: can't set %s property: hr=%#lx\n",
+                 SRCNAME, __func__, "GpgOL Charset", hr); 
+      return -1;
+    }
+
+  return 0;
+}
+
+
 /* Return the MIME info as an allocated string.  Will never return
    NULL.  */
 char *
@@ -2130,8 +2204,22 @@
           found = 1;
           if (r_body)
             {
+              char *charset;
+              
               if (get_attach_method (att) == ATTACH_BY_VALUE)
                 body = attach_to_buffer (att, r_nbytes, 1, r_protected);
+              if (body && (charset = mapi_get_gpgol_charset ((LPMESSAGE)att)))
+                {
+                  /* We only support transcoding from Latin-1 for now.  */
+                  if (strcmp (charset, "iso-8859-1") 
+                      && !strcmp (charset, "latin-1"))
+                    log_debug ("%s:%s: Using Latin-1 instead of %s",
+                               SRCNAME, __func__, charset);
+                  xfree (charset);
+                  charset = latin1_to_utf8 (body);
+                  xfree (body);
+                  body = charset;
+                }
             }
           att->Release ();
           if (r_ishtml)

Modified: trunk/src/mapihelp.h
===================================================================
--- trunk/src/mapihelp.h	2008-02-11 10:36:20 UTC (rev 220)
+++ trunk/src/mapihelp.h	2008-02-13 19:18:55 UTC (rev 221)
@@ -121,6 +121,9 @@
 
 int mapi_set_gpgol_msg_class (LPMESSAGE message, const char *name);
 
+char *mapi_get_gpgol_charset (LPMESSAGE obj);
+int mapi_set_gpgol_charset (LPMESSAGE obj, const char *charset);
+
 int  mapi_set_attach_hidden (LPATTACH attach);
 
 char *mapi_get_mime_info (LPMESSAGE msg);

Modified: trunk/src/mimeparser.c
===================================================================
--- trunk/src/mimeparser.c	2008-02-11 10:36:20 UTC (rev 220)
+++ trunk/src/mimeparser.c	2008-02-13 19:18:55 UTC (rev 221)
@@ -110,7 +110,6 @@
   int hashing_level;      /* MIME level where we started hashing. */
   int is_qp_encoded;      /* Current part is QP encoded. */
   int is_base64_encoded;  /* Current part is base 64 encoded. */
-  int is_utf8;            /* Current part has charset utf-8. */
   int is_body;            /* The current part belongs to the body.  */
   protocol_t protocol;    /* The detected crypto protocol.  */
 
@@ -386,7 +385,17 @@
       goto leave;
     }
 
+  /* If we have the MIME info and a charset info and that is not
+     UTF-8, set our own Charset property.  */
+  if (ctx->mimestruct_cur)
+    {
+      const char *s = ctx->mimestruct_cur->charset;
+      if (s && strcmp (s, "utf-8") && strcmp (s, "UTF-8")
+          && strcmp (s, "utf8") && strcmp (s, "UTF8"))
+        mapi_set_gpgol_charset ((LPMESSAGE)newatt, s);
+    }
 
+
   /* If we are in protect mode (i.e. working on a decrypted message,
      we need to setup the symkey context to protect (encrypt) the
      attachment in the MAPI.  */
@@ -750,11 +759,9 @@
              SRCNAME, __func__, ctx, ctmain, ctsub);
 #endif
 
-  /* We only support UTF-8 for now.  Check here.  */
   s = rfc822parse_query_parameter (field, "charset", 0);
   if (s)
     charset = xstrdup (s);
-  ctx->is_utf8 = (s && !strcmp (s, "utf-8"));
 
   /* Update our idea of the entire MIME structure.  */
   {
@@ -829,8 +836,9 @@
   ctx->in_data = 1;
 
 #ifdef DEBUG_PARSER
-  log_debug ("%s: this body: nesting=%d part_counter=%d is_text=%d\n",
-             SRCNAME, ctx->nesting_level, ctx->part_counter, is_text);
+  log_debug ("%s: this body: nesting=%d partno=%d is_text=%d charset=\"%s\"\n",
+             SRCNAME, ctx->nesting_level, ctx->part_counter, is_text, 
+             ctx->mimestruct_cur->charset?ctx->mimestruct_cur->charset:"");
 #endif
 
   /* If this is a text part, decide whether we treat it as our body. */




More information about the Gnupg-commits mailing list