log_debug ( "%s:%s: attachment %d has no pgp extension\n", __FILE__, __func__);
log_debug ("%s:%s: attachment %d has no pgp extension\n", __FILE__, __func__, pos);
GpgMsgImpl::decryptAttachment (HWND hwnd, int pos, bool save_plaintext,                               int ttl){      HRESULT hr;  LPATTACH att;  int method, err;  /* Make sure that we can access the attachment table. */  if (!message || !getAttachments ())    {      log_debug ("%s:%s: no attachemnts at all", __FILE__, __func__);      return;    }  if (!save_plaintext)    {      log_error ("%s:%s: save_plaintext not requested", __FILE__, __func__);      return;    }  hr = message->OpenAttach (pos, NULL, MAPI_BEST_ACCESS, &att);	  if (FAILED (hr))    {      log_debug ("%s:%s: can't open attachment %d: hr=%#lx",                 __FILE__, __func__, pos, hr);      return;    }  method = get_attach_method (att);  if ( method == ATTACH_EMBEDDED_MSG)    {      /* This is an embedded message.  The orginal G-DATA plugin         decrypted the message and then updated the attachemnt;         i.e. stored the plaintext.  This seemed to ensure that the         attachemnt message was properly displayed.  I am not sure         what we should do - it might be necessary to have a callback         to allow displaying the attachment.  Needs further         experiments. */      LPMESSAGE emb;            hr = att->OpenProperty (PR_ATTACH_DATA_OBJ, &IID_IMessage, 0,                               MAPI_MODIFY, (LPUNKNOWN*)&emb);      if (FAILED (hr))        {          log_error ("%s:%s: can't open data obj of attachment %d: hr=%#lx",                     __FILE__, __func__, pos, hr);          goto leave;        }      //FIXME  Not sure what to do here.  Did it ever work?      // 	setWindow (hwnd);      // 	setMessage (emb);      //if (doCmdAttach (action))      //  success = FALSE;      //XXX;      //emb->SaveChanges (FORCE_SAVE);      //att->SaveChanges (FORCE_SAVE);      emb->Release ();    }  else if (method == ATTACH_BY_VALUE)    {      const char *s;      char *outname;      char *suggested_name;      LPSTREAM from, to;      suggested_name = get_attach_filename (att);      /* We only want to automatically decrypt attachmenst with         certain extensions.  FIXME: Also look for content-types. */      if (!suggested_name           || !(s = strrchr (suggested_name, '.'))          || (stricmp (s, ".pgp")               && stricmp (s, ".gpg")               && stricmp (s, ".asc")))        {          log_debug ( "%s:%s: attachment %d has no pgp extension\n",                       __FILE__, __func__);          goto leave;        }      outname = get_save_filename (hwnd, suggested_name);      xfree (suggested_name);      hr = att->OpenProperty (PR_ATTACH_DATA_BIN, &IID_IStream,                               0, 0, (LPUNKNOWN*) &from);      if (FAILED (hr))        {          log_error ("%s:%s: can't open data of attachment %d: hr=%#lx",                     __FILE__, __func__, pos, hr);          xfree (outname);          goto leave;        }      hr = OpenStreamOnFile (MAPIAllocateBuffer, MAPIFreeBuffer,                             (STGM_CREATE | STGM_READWRITE),                             outname, NULL, &to);       if (FAILED (hr))         {          log_error ("%s:%s: can't create stream for `%s': hr=%#lx\n",                     __FILE__, __func__, outname, hr);           from->Release ();          xfree (outname);          goto leave;        }            err = op_decrypt_stream (from, to, ttl);      if (err)        {          log_debug ("%s:%s: decrypt stream failed: %s",                     __FILE__, __func__, op_strerror (err));           to->Revert ();          to->Release ();          from->Release ();          MessageBox (NULL, op_strerror (err),                      "GPG Attachment Decryption", MB_ICONERROR|MB_OK);          /* FIXME: We might need to delete outname now.  However a             sensible implementation of the stream object should have             done it trhough the Revert call. */          xfree (outname);          goto leave;        }              to->Commit (0);      to->Release ();      from->Release ();      /*  Hmmm: Why are we deleting the attachment now?????           Disabled until clarified.   FIXME */      //if (message->DeleteAttach (pos, 0, NULL, 0) == S_OK)      //   show error;      xfree (outname);    }  else    {      log_error ("%s:%s: attachment %d: method %d not supported",                 __FILE__, __func__, pos, method);    } leave:  /* Close this attachment. */  att->Release ();}