[svn] GpgOL - r227 - trunk/src
svn author wk
cvs at cvs.gnupg.org
Fri Mar 7 11:31:55 CET 2008
Author: wk
Date: 2008-03-07 11:31:54 +0100 (Fri, 07 Mar 2008)
New Revision: 227
Modified:
trunk/src/ChangeLog
trunk/src/common.h
trunk/src/engine.c
trunk/src/engine.h
trunk/src/ext-commands.cpp
trunk/src/message.cpp
trunk/src/mimeparser.c
trunk/src/mimeparser.h
trunk/src/user-events.cpp
Log:
Fix a problem with plain PGP messages. Decryption works now.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/ChangeLog 2008-03-07 10:31:54 UTC (rev 227)
@@ -1,3 +1,17 @@
+2008-03-07 Werner Koch <wk at g10code.com>
+
+ * engine.c (struct engine_filter_s): Add field ADD_EXTRA_LF.
+ (engine_request_exra_lf): New.
+ (engine_wait): Implement that.
+ * mimeparser.c (mime_decrypt): Add arg SIMPLE_PGP and call
+ engine_request_exra_lf.
+ (struct mime_context): Add field NO_MAIL_HEADER.
+ (message_cb): Implement it.
+ * message.cpp (message_decrypt): Set that flag for old style PGP.
+
+ * common.h (DBG_COMMANDS, debug_commands): New.
+ * ext-commands.cpp: Use it.
+
2008-03-06 Werner Koch <wk at g10code.com>
* mimemaker.c (do_mime_sign): Figure out the protocol to use.
Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/common.h 2008-03-07 10:31:54 UTC (rev 227)
@@ -150,8 +150,12 @@
#define DBG_FILTER 8
#define DBG_FILTER_EXTRA 16
#define DBG_MEMORY 32
+#define DBG_COMMANDS 64
+/* Macros to used in conditionals to enabel debug output. */
+#define debug_commands (opt.enable_debug & DBG_COMMANDS)
+
/* Type and constants used with parse_tlv. */
struct tlvinfo_s
{
Modified: trunk/src/engine.c
===================================================================
--- trunk/src/engine.c 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/engine.c 2008-03-07 10:31:54 UTC (rev 227)
@@ -88,6 +88,9 @@
char buffer[FILTER_BUFFER_SIZE];
} out;
+ /* Flag to push an extra LF out. */
+ int add_extra_lf;
+
/* The data sink as set by engine_create_filter. */
int (*outfnc) (void *, const void *, size_t);
void *outfncdata;
@@ -544,7 +547,14 @@
}
+/* Set the FILTER in a mode which pushes an extra lineffed out. */
+void
+engine_request_exra_lf (engine_filter_t filter)
+{
+ filter->add_extra_lf = 1;
+}
+
/* Wait for FILTER to finish. Returns 0 on success. FILTER is not
valid after the function has returned success. */
int
@@ -552,6 +562,7 @@
{
gpg_error_t err;
int more;
+ int nbytes;
if (!filter || !filter->outfnc)
return gpg_error (GPG_ERR_INV_VALUE);
@@ -568,8 +579,6 @@
take_out_lock (filter, __func__);
if (filter->out.length)
{
- int nbytes;
-
nbytes = filter->outfnc (filter->outfncdata,
filter->out.buffer, filter->out.length);
if (nbytes < 0)
@@ -604,6 +613,49 @@
}
while (more);
+ /* If requested write an extra LF, so that the MIME parser sees a
+ complete line. */
+ if (filter->add_extra_lf)
+ {
+ int extra_written = 0;
+ do
+ {
+ more = 0;
+ take_out_lock (filter, __func__);
+ if (!extra_written)
+ {
+ nbytes = filter->outfnc (filter->outfncdata, "\n", 1);
+ if (nbytes < 0)
+ {
+ log_error ("%s:%s: error writing extra lf\n",
+ SRCNAME, __func__);
+ release_out_lock (filter, __func__);
+ return gpg_error (GPG_ERR_EIO);
+ }
+ if (!nbytes)
+ {
+ if (debug_filter_extra)
+ log_debug ("%s:%s: extra lf still pending for outfnc\n",
+ SRCNAME, __func__);
+ more = 1;
+ }
+ else
+ extra_written = 1;
+ }
+ if (!PulseEvent (filter->out.condvar))
+ log_error_w32 (-1, "%s:%s: PulseEvent(out) failed",
+ SRCNAME, __func__);
+ release_out_lock (filter, __func__);
+ take_in_lock (filter, __func__);
+ if (!filter->in.ready)
+ more = 1;
+ release_in_lock (filter, __func__);
+ if (more)
+ Sleep (50);
+ }
+ while (more);
+ }
+
if (WaitForSingleObject (filter->in.ready_event, INFINITE) != WAIT_OBJECT_0)
{
log_error_w32 (-1, "%s:%s: WFSO failed", SRCNAME, __func__);
Modified: trunk/src/engine.h
===================================================================
--- trunk/src/engine.h 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/engine.h 2008-03-07 10:31:54 UTC (rev 227)
@@ -59,6 +59,7 @@
int engine_create_filter (engine_filter_t *r_filter,
int (*outfnc) (void *, const void *, size_t),
void *outfncdata);
+void engine_request_exra_lf (engine_filter_t filter);
int engine_wait (engine_filter_t filter);
void engine_cancel (engine_filter_t filter);
Modified: trunk/src/ext-commands.cpp
===================================================================
--- trunk/src/ext-commands.cpp 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/ext-commands.cpp 2008-03-07 10:31:54 UTC (rev 227)
@@ -204,8 +204,9 @@
HMENU menu;
eecb->GetMenuPos (EECMDID_ToolsCustomizeToolbar, &menu, NULL, NULL, 0);
- log_debug ("check_menu: eecb=%p menu_id=%u checked=%d -> menu=%p\n",
- eecb, menu_id, checked, menu);
+ if (debug_commands)
+ log_debug ("check_menu: eecb=%p menu_id=%u checked=%d -> menu=%p\n",
+ eecb, menu_id, checked, menu);
CheckMenuItem (menu, menu_id,
MF_BYCOMMAND | (checked?MF_CHECKED:MF_UNCHECKED));
}
@@ -263,9 +264,10 @@
tb_info->next = m_toolbar_info;
m_toolbar_info = tb_info;
- log_debug ("%s:%s: ctx=%lx button_id=%d cmd_id=%d '%s'\n",
- SRCNAME, __func__, m_lContext,
- tb_info->button_id, tb_info->cmd_id, tb_info->desc);
+ if (debug_commands)
+ log_debug ("%s:%s: ctx=%lx button_id=%d cmd_id=%d '%s'\n",
+ SRCNAME, __func__, m_lContext,
+ tb_info->button_id, tb_info->cmd_id, tb_info->desc);
}
}
@@ -298,8 +300,9 @@
int force_encrypt = 0;
- log_debug ("%s:%s: context=%s flags=0x%lx\n", SRCNAME, __func__,
- ext_context_name (m_lContext), lFlags);
+ if (debug_commands)
+ log_debug ("%s:%s: context=%s flags=0x%lx\n", SRCNAME, __func__,
+ ext_context_name (m_lContext), lFlags);
/* Outlook 2003 sometimes displays the plaintext and sometimes the
@@ -521,9 +524,10 @@
if (FAILED (eecb->GetWindow (&hwnd)))
hwnd = NULL;
- log_debug ("%s:%s: commandID=%u (%#x) context=%s hwnd=%p\n",
- SRCNAME, __func__, nCommandID, nCommandID,
- ext_context_name (m_lContext), hwnd);
+ if (debug_commands)
+ log_debug ("%s:%s: commandID=%u (%#x) context=%s hwnd=%p\n",
+ SRCNAME, __func__, nCommandID, nCommandID,
+ ext_context_name (m_lContext), hwnd);
if (nCommandID == SC_CLOSE && m_lContext == EECONTEXT_READNOTEMESSAGE)
{
@@ -536,7 +540,8 @@
DISPPARAMS dispparams;
VARIANT aVariant;
- log_debug ("%s:%s: command Close called\n", SRCNAME, __func__);
+ if (debug_commands)
+ log_debug ("%s:%s: command Close called\n", SRCNAME, __func__);
pDisp = find_outlook_property (eecb, "Close", &dispid);
if (pDisp)
{
@@ -574,7 +579,8 @@
}
else if (nCommandID == EECMDID_ComposeReplyToSender)
{
- log_debug ("%s:%s: command Reply called\n", SRCNAME, __func__);
+ if (debug_commands)
+ log_debug ("%s:%s: command Reply called\n", SRCNAME, __func__);
/* What we might want to do is to call Reply, then GetInspector
and then Activate - this allows us to get full control over
the quoted message and avoids the ugly msgcache. */
@@ -582,12 +588,14 @@
}
else if (nCommandID == EECMDID_ComposeReplyToAll)
{
- log_debug ("%s:%s: command ReplyAll called\n", SRCNAME, __func__);
+ if (debug_commands)
+ log_debug ("%s:%s: command ReplyAll called\n", SRCNAME, __func__);
return S_FALSE; /* Pass it on. */
}
else if (nCommandID == EECMDID_ComposeForward)
{
- log_debug ("%s:%s: command Forward called\n", SRCNAME, __func__);
+ if (debug_commands)
+ log_debug ("%s:%s: command Forward called\n", SRCNAME, __func__);
return S_FALSE; /* Pass it on. */
}
else if (nCommandID == m_nCmdDecrypt
@@ -641,7 +649,7 @@
else if (nCommandID == m_nCmdProtoPgpmime
&& m_lContext == EECONTEXT_SENDNOTEMESSAGE)
{
- log_debug ("%s:%s: command ProroPggmime called\n", SRCNAME, __func__);
+ log_debug ("%s:%s: command ProtoPgpmime called\n", SRCNAME, __func__);
check_menu (eecb, m_nCmdProtoAuto, FALSE);
check_menu (eecb, m_nCmdProtoPgpmime, TRUE);
check_menu (eecb, m_nCmdProtoSmime, FALSE);
@@ -712,7 +720,8 @@
}
else
{
- log_debug ("%s:%s: command passed on\n", SRCNAME, __func__);
+ if (debug_commands)
+ log_debug ("%s:%s: command passed on\n", SRCNAME, __func__);
return S_FALSE; /* Pass on unknown command. */
}
@@ -912,9 +921,11 @@
if (!tb_info)
return S_FALSE; /* Not one of our toolbar buttons. */
- log_debug ("%s:%s: ctx=%lx tbid=%ld button_id(req)=%d got=%d cmd_id=%d '%s'\n",
- SRCNAME, __func__, m_lContext, toolbarid, buttonid,
- tb_info->button_id, tb_info->cmd_id, tb_info->desc);
+ if (debug_commands)
+ log_debug ("%s:%s: ctx=%lx tbid=%ld button_id(req)=%d got=%d"
+ " cmd_id=%d '%s'\n",
+ SRCNAME, __func__, m_lContext, toolbarid, buttonid,
+ tb_info->button_id, tb_info->cmd_id, tb_info->desc);
pTBB->iBitmap = tb_info->bitmap;
pTBB->idCommand = tb_info->cmd_id;
Modified: trunk/src/message.cpp
===================================================================
--- trunk/src/message.cpp 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/message.cpp 2008-03-07 10:31:54 UTC (rev 227)
@@ -843,6 +843,8 @@
LPATTACH saved_attach = NULL;
int need_saved_attach = 0;
int need_rfc822_parser = 0;
+ int is_simple_pgp = 0;
+
switch (msgtype)
{
@@ -922,6 +924,8 @@
goto leave; /* Problem getting the attachment. */
protocol = PROTOCOL_OPENPGP;
need_rfc822_parser = 1;
+ is_simple_pgp = 1;
+
}
else
{
@@ -1064,7 +1068,7 @@
}
err = mime_decrypt (protocol, cipherstream, message,
- need_rfc822_parser, hwnd, 0);
+ need_rfc822_parser, is_simple_pgp, hwnd, 0);
log_debug ("mime_decrypt returned %d (%s)", err, gpg_strerror (err));
if (err)
{
Modified: trunk/src/mimeparser.c
===================================================================
--- trunk/src/mimeparser.c 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/mimeparser.c 2008-03-07 10:31:54 UTC (rev 227)
@@ -88,6 +88,7 @@
int protect_mode; /* Encrypt all attachments etc. (cf. SYMENC). */
int verify_mode; /* True if we want to verify a signature. */
+ int no_mail_header; /* True if we want to bypass all MIME parsing. */
int nesting_level; /* Current MIME nesting level. */
int in_data; /* We are currently in data (body or attachment). */
@@ -919,6 +920,39 @@
mime_context_t ctx = opaque;
debug_message_event (ctx, event);
+ if (ctx->no_mail_header)
+ {
+ /* Assume that this is not a regular mail but plain text. */
+ if (!ctx->body_seen)
+ {
+#ifdef DEBUG_PARSER
+ log_debug ("%s:%s: assuming this is plain text without headers\n",
+ SRCNAME, __func__);
+#endif
+ ctx->in_data = 1;
+ ctx->collect_attachment = 2; /* 2 so we don't skip the first line. */
+ ctx->body_seen = 1;
+ /* Create a fake MIME structure. */
+ /* Fixme: We might want to take it from the enclosing message. */
+ {
+ const char ctmain[] = "text";
+ const char ctsub[] = "plain";
+ mimestruct_item_t ms;
+
+ ms = xmalloc (sizeof *ms + strlen (ctmain) + 1 + strlen (ctsub));
+ ctx->mimestruct_cur = ms;
+ *ctx->mimestruct_tail = ms;
+ ctx->mimestruct_tail = &ms->next;
+ ms->next = NULL;
+ strcpy (stpcpy (stpcpy (ms->content_type, ctmain), "/"), ctsub);
+ ms->level = 0;
+ }
+ if (start_attachment (ctx, 1))
+ return -1;
+ assert (ctx->outstream);
+ }
+ return 0;
+ }
if (event == RFC822PARSE_BEGIN_HEADER || event == RFC822PARSE_T2BODY)
{
@@ -1012,6 +1046,8 @@
if (pos && ctx->linebuf[pos-1] == '\r')
pos--;
+/* log_debug ("%s:%s: ctx=%p, line=`%.*s'\n", */
+/* SRCNAME, __func__, ctx, (int)pos, ctx->linebuf); */
if (rfc822parse_insert (ctx->msg, ctx->linebuf, pos))
{
log_error ("%s: ctx=%p, rfc822 parser failed: %s\n",
@@ -1493,6 +1529,8 @@
if (pos && ctx->linebuf[pos-1] == '\r')
pos--;
+/* log_debug ("%s:%s: ctx=%p, line=`%.*s'\n", */
+/* SRCNAME, __func__, ctx, (int)pos, ctx->linebuf); */
if (rfc822parse_insert (ctx->msg, ctx->linebuf, pos))
{
log_error ("%s:%s: ctx=%p, rfc822 parser failed: %s\n",
@@ -1547,10 +1585,11 @@
window to be used for message box and such. In PREVIEW_MODE no
verification will be done, no messages saved and no messages boxes
will pop up. If IS_RFC822 is set, the message is expected to be in
- rfc822 format. */
+ rfc822 format. The caller should send SIMPLE_PGP is the input
+ message is a simple PGP message. */
int
mime_decrypt (protocol_t protocol, LPSTREAM instream, LPMESSAGE mapi_message,
- int is_rfc822, HWND hwnd, int preview_mode)
+ int is_rfc822, int simple_pgp, HWND hwnd, int preview_mode)
{
gpg_error_t err;
mime_context_t decctx, ctx;
@@ -1575,6 +1614,7 @@
ctx->preview = preview_mode;
ctx->mapi_message = mapi_message;
ctx->mimestruct_tail = &ctx->mimestruct;
+ ctx->no_mail_header = simple_pgp;
if (decctx)
{
@@ -1602,6 +1642,8 @@
/* title = native_to_utf8 (_("[Encrypted PGP/MIME message]")); */
if ((err=engine_create_filter (&filter, plaintext_handler, ctx)))
goto leave;
+ if (simple_pgp)
+ engine_request_exra_lf (filter);
if ((err=engine_decrypt_start (filter, hwnd, protocol, !preview_mode)))
goto leave;
Modified: trunk/src/mimeparser.h
===================================================================
--- trunk/src/mimeparser.h 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/mimeparser.h 2008-03-07 10:31:54 UTC (rev 227)
@@ -35,7 +35,7 @@
LPMESSAGE mapi_message, HWND hwnd, int preview_mode);
int mime_decrypt (protocol_t protocol,
LPSTREAM instream, LPMESSAGE mapi_message, int is_rfc822,
- HWND hwnd, int preview_mode);
+ int simple_pgp, HWND hwnd, int preview_mode);
#ifdef __cplusplus
Modified: trunk/src/user-events.cpp
===================================================================
--- trunk/src/user-events.cpp 2008-03-06 15:05:48 UTC (rev 226)
+++ trunk/src/user-events.cpp 2008-03-07 10:31:54 UTC (rev 227)
@@ -101,7 +101,8 @@
LPENTRYID entryid = NULL;
ULONG entryidlen;
- log_debug ("%s:%s: received\n", SRCNAME, __func__);
+ if (debug_commands)
+ log_debug ("%s:%s: received\n", SRCNAME, __func__);
hr = eecb->GetSelectionCount (&count);
if (SUCCEEDED (hr) && count > 0)
@@ -112,8 +113,9 @@
&msgflags, 0L);
if (SUCCEEDED(hr) && objtype == MAPI_MESSAGE)
{
- log_debug ("%s:%s: message class: %s\n",
- SRCNAME, __func__, msgclass);
+ if (debug_commands)
+ log_debug ("%s:%s: message class: %s\n",
+ SRCNAME, __func__, msgclass);
/* If SMIME has been enabled and the current message is of
class SMIME or in the past processed by CryptoEx, we
@@ -163,8 +165,9 @@
}
else if (SUCCEEDED(hr) && objtype == MAPI_FOLDER)
{
- log_debug ("%s:%s: objtype: %lu\n",
- SRCNAME, __func__, objtype);
+ if (debug_commands)
+ log_debug ("%s:%s: objtype: %lu\n",
+ SRCNAME, __func__, objtype);
}
}
@@ -179,7 +182,7 @@
STDMETHODIMP_ (VOID)
GpgolUserEvents::OnObjectChange (LPEXCHEXTCALLBACK eecb)
{
- log_debug ("%s:%s: received\n", SRCNAME, __func__);
-
+ if (debug_commands)
+ log_debug ("%s:%s: received\n", SRCNAME, __func__);
}
More information about the Gnupg-commits
mailing list