setCipherText (add_html_line_endings (ciphertext), true); else setCipherText (ciphertext, false); ciphertext = NULL;
{ char *tmp = add_html_line_endings (ciphertext); xfree (ciphertext); ciphertext = tmp; }
GpgMsgImpl::encrypt_and_sign (HWND hwnd, bool sign){  log_debug ("%s:%s: enter\n", __FILE__, __func__);  gpgme_key_t *keys = NULL;  gpgme_key_t sign_key = NULL;  bool is_html;  const char *plaintext;  char *ciphertext = NULL;  char **recipients = NULL;  char **unknown = NULL;  int err = 0;  size_t all = 0;  int n_keys;    if (!*(plaintext = getOrigText ()) && !hasAttachments ())     {      log_debug ("%s:%s: leave (empty)", __FILE__, __func__);      return 0;     }  /* Pop up a dialog box to ask for the signer of the message. */  if (sign)    {      if (signer_dialog_box (&sign_key, NULL) == -1)        {          log_debug ("%s.%s: leave (dialog failed)\n", __FILE__, __func__);          return gpg_error (GPG_ERR_CANCELED);          }    }  /* Gather the keys for the recipients. */  recipients = getRecipients ();  n_keys = op_lookup_keys (recipients, &keys, &unknown, &all);  log_debug ("%s:%s: found %d recipients, need %d, unknown=%p\n",             __FILE__, __func__, n_keys, all, unknown);    if (n_keys != count_recipients (recipients))    {      int opts = 0;      gpgme_key_t *keys2 = NULL;      /* FIXME: The implementation is not correct: op_lookup_keys         returns the number of missing keys but we compare against the         total number of keys; thus the box would pop up even when all         have been found. */      log_debug ("%s:%s: calling recipient_dialog_box2", __FILE__, __func__);      recipient_dialog_box2 (keys, unknown, all, &keys2, &opts);      xfree (keys);      keys = keys2;      if (opts & OPT_FLAG_CANCEL)         {          err = gpg_error (GPG_ERR_CANCELED);          goto leave;	}    }  if (sign_key)    log_debug ("%s:%s: signer: 0x%s %s\n",  __FILE__, __func__,               keyid_from_key (sign_key), userid_from_key (sign_key));  else    log_debug ("%s:%s: no signer\n", __FILE__, __func__);  if (keys)    {      for (int i=0; keys[i] != NULL; i++)        log_debug ("%s.%s: recp.%d 0x%s %s\n", __FILE__, __func__,                   i, keyid_from_key (keys[i]), userid_from_key (keys[i]));    }  if (*plaintext)    {      is_html = is_html_body (plaintext);      err = op_encrypt (plaintext, &ciphertext, keys, NULL, 0);      if (err)        {          MessageBox (NULL, op_strerror (err),                      "GPG Encryption", MB_ICONERROR|MB_OK);          goto leave;        }      if (is_html)         setCipherText (add_html_line_endings (ciphertext), true);      else        setCipherText (ciphertext, false);      ciphertext = NULL;//       {//         HRESULT hr;//         SPropValue prop;//         prop.ulPropTag=PR_MESSAGE_CLASS_A;//         prop.Value.lpszA="IPM.Note.OPENPGP";//         hr = HrSetOneProp (message, &prop);//         if (hr != S_OK)//           {//             log_error ("%s:%s: can't set message class: hr=%#lx\n",//                        __FILE__, __func__, hr); //           }//         prop.ulPropTag=PR_CONTENT_TYPE_A;//         prop.Value.lpszA="application/encrypted;foo=bar;type=mytype";//         hr = HrSetOneProp (message, &prop);//         if (hr != S_OK)//           {//             log_error ("%s:%s: can't set content type: hr=%#lx\n",//                        __FILE__, __func__, hr); //           }//       }    }  if (hasAttachments ())    {      unsigned int n;            n = getAttachments ();      log_debug ("%s:%s: message has %u attachments\n", __FILE__, __func__, n);      for (int i=0; !err && i < n; i++)         err = encryptAttachment (hwnd, i, keys, NULL, 0);      if (err)        MessageBox (NULL, op_strerror (err),                    "GPG Attachment Encryption", MB_ICONERROR|MB_OK);    } leave:  for (int i=0; i < n_keys; i++)    xfree (unknown[i]);  if (n_keys)    xfree (unknown);  free_key_array (keys);  free_recipient_array (recipients);  xfree (ciphertext);  log_debug ("%s:%s: leave (err=%s)\n", __FILE__, __func__, op_strerror (err));  return err;}