int err = 0;
gpgme_data_t data;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
fptmp = safe_fopen (tempfile, "w+");
if (!fptmp)
{
buf[0] = c;
gpgme_data_write (data, buf, 1);
}
- fclose(fptmp);
+ safe_fclose (&fptmp);
gpgme_data_seek (data, 0, SEEK_SET);
}
else
{
- fclose(fptmp);
+ safe_fclose (&fptmp);
err = gpgme_data_new_from_file (&data, tempfile, 1);
}
unlink (tempfile);
FILE *fp;
size_t nread = 0;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
fp = safe_fopen (tempfile, "w+");
if (!fp)
{
if (fwrite (buf, nread, 1, fp) != 1)
{
mutt_perror (tempfile);
- fclose (fp);
+ safe_fclose (&fp);
unlink (tempfile);
return NULL;
}
if (ret_fp)
rewind (fp);
else
- fclose (fp);
+ safe_fclose (&fp);
if (nread == -1)
{
mutt_error (_("error reading data object: %s\n"), gpgme_strerror (err));
unlink (tempfile);
- fclose (fp);
+ safe_fclose (&fp);
return NULL;
}
if (ret_fp)
{
t->subtype = safe_strdup ("pgp-signature");
t->use_disp = 0;
- t->disposition = DISPINLINE;
+ t->disposition = DISPNONE;
t->encoding = ENC7BIT;
}
t->filename = sigfile;
t->parts->next->encoding = ENC7BIT;
t->parts->next->filename = outfile;
t->parts->next->use_disp = 1;
- t->parts->next->disposition = DISPINLINE;
+ t->parts->next->disposition = DISPATTACH;
t->parts->next->unlink = 1; /* delete after sending the message */
t->parts->next->d_filename = safe_strdup ("msg.asc"); /* non pgp/mime
can save */
memset (&s, 0, sizeof (s));
s.fpin = fpin;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (!(*fpout = safe_fopen (tempfile, "w+")))
{
mutt_perror (tempfile);
memset (&s, 0, sizeof (s));
s.fpin = fpin;
fseeko (s.fpin, b->offset, 0);
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (!(tmpfp = safe_fopen (tempfile, "w+")))
{
mutt_perror (tempfile);
memset (&s, 0, sizeof (s));
s.fpin = tmpfp;
s.fpout = 0;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (!(*fpout = safe_fopen (tempfile, "w+")))
{
mutt_perror (tempfile);
b->type = saved_b_type;
b->length = saved_b_length;
b->offset = saved_b_offset;
- fclose (tmpfp);
+ safe_fclose (&tmpfp);
rewind (*fpout);
if (*cur && !is_signed && !(*cur)->parts && mutt_is_application_smime (*cur))
{
memset (&s, 0, sizeof (s));
s.fpin = *fpout;
fseeko (s.fpin, bb->offset, 0);
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (!(tmpfp = safe_fopen (tempfile, "w+")))
{
mutt_perror (tempfile);
bb->length = ftello (s.fpout);
bb->offset = 0;
rewind (tmpfp);
- fclose (*fpout);
+ safe_fclose (fpout);
memset (&s, 0, sizeof (s));
s.fpin = tmpfp;
s.fpout = 0;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (!(*fpout = safe_fopen (tempfile, "w+")))
{
mutt_perror (tempfile);
bb->type = saved_b_type;
bb->length = saved_b_length;
bb->offset = saved_b_offset;
- fclose (tmpfp);
+ safe_fclose (&tmpfp);
rewind (*fpout);
mutt_free_body (cur);
*cur = tmp_b;
goto err_tmpdir;
}
- mutt_mktemp (tmpfile);
+ mutt_mktemp (tmpfile, sizeof (tmpfile));
*fp = safe_fopen (tmpfile, "w+");
if (!*fp)
{
err_fp:
if (rc)
- {
- fclose (*fp);
- *fp = NULL;
- }
+ safe_fclose (fp);
err_tmpdir:
if (dryrun)
mutt_rmtree (tmpdir);
if (tagged_only && !b->tagged)
return 0;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0)
{
unlink (tempfile);
dprint (1, (debugfile, "error converting key file into data object\n"));
return;
}
- fclose (in);
+ safe_fclose (&in);
if (!pgp_gpgme_extract_keys (keydata, &out, 0))
{
outlen = ftell (out);
fseek (out, 0, SEEK_SET);
mutt_copy_bytes (out, stdout, outlen);
- fclose (out);
+ safe_fclose (&out);
}
else
printf (_("Error extracting key data!\n"));
}
fgetconv_close (&fc);
- fclose (fp);
+ safe_fclose (&fp);
}
safe_fclose (&pgpout);
}
}
-#if 0
else
{
- /* why would we want to display this at all? */
+ /* A traditional PGP part may mix signed and unsigned content */
/* XXX - we may wish to recode here */
if (s->prefix)
state_puts (s->prefix, s);
state_puts (buf, s);
}
-#endif
}
m->goodsig = (maybe_goodsig && have_any_sigs);
/* Move forward to the application/pgp-encrypted body. */
a = a->next;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (!(fpout = safe_fopen (tempfile, "w+")))
{
if (s->flags & M_DISPLAY)
mutt_free_body (&tattach);
}
- fclose (fpout);
+ safe_fclose (&fpout);
mutt_unlink(tempfile);
dprint (2, (debugfile, "Leaving pgp_encrypted handler\n"));
dprint (2, (debugfile, "Entering smime_encrypted handler\n"));
a->warnsig = 0;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (!(fpout = safe_fopen (tempfile, "w+")))
{
if (s->flags & M_DISPLAY)
mutt_free_body (&tattach);
}
- fclose (fpout);
+ safe_fclose (&fpout);
mutt_unlink(tempfile);
dprint (2, (debugfile, "Leaving smime_encrypted handler\n"));
gpgme_key_t k = NULL;
int maxdepth = 100;
- mutt_mktemp (tempfile);
+ mutt_mktemp (tempfile, sizeof (tempfile));
if (!(fp = safe_fopen (tempfile, "w")))
{
mutt_perror _("Can't create temporary file");
leave:
gpgme_key_release (k);
gpgme_release (listctx);
- fclose (fp);
+ safe_fclose (&fp);
mutt_clear_error ();
snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"), crypt_keyid (key));
mutt_do_pager (cmd, tempfile, 0, NULL);
default: abort ();
}
- *last = rfc822_cpy_adr (p);
+ *last = rfc822_cpy_adr (p, 0);
while (*last)
last = &((*last)->next);
}
}
if (sender)
+ {
+ if (signature_key)
{
- if (signature_key)
- {
- gpgme_key_t key = signature_key;
- gpgme_user_id_t uid = NULL;
- int sender_length = 0;
- int uid_length = 0;
+ gpgme_key_t key = signature_key;
+ gpgme_user_id_t uid = NULL;
+ int sender_length = 0;
+ int uid_length = 0;
- sender_length = strlen (sender->mailbox);
- for (uid = key->uids; uid && ret; uid = uid->next)
- {
- uid_length = strlen (uid->email);
- if (1
- && (uid->email[0] == '<')
- && (uid->email[uid_length - 1] == '>')
- && (uid_length == sender_length + 2)
- && (! strncmp (uid->email + 1, sender->mailbox, sender_length)))
- ret = 0;
- }
+ sender_length = strlen (sender->mailbox);
+ for (uid = key->uids; uid && ret; uid = uid->next)
+ {
+ uid_length = strlen (uid->email);
+ if (1
+ && (uid->email[0] == '<')
+ && (uid->email[uid_length - 1] == '>')
+ && (uid_length == sender_length + 2))
+ {
+ const char* at_sign = strchr(uid->email + 1, '@');
+ if (at_sign == NULL)
+ {
+ if (! strncmp (uid->email + 1, sender->mailbox, sender_length))
+ ret = 0;
+ }
+ else
+ {
+ /*
+ * Assume address is 'mailbox@domainname'.
+ * The mailbox part is case-sensitive,
+ * the domainname is not. (RFC 2821)
+ */
+ const char* tmp_email = uid->email + 1;
+ const char* tmp_sender = sender->mailbox;
+ /* length of mailbox part including '@' */
+ int mailbox_length = at_sign - tmp_email + 1;
+ int domainname_length = sender_length - mailbox_length;
+ int mailbox_match, domainname_match;
+
+ mailbox_match = (! strncmp (tmp_email, tmp_sender,
+ mailbox_length));
+ tmp_email += mailbox_length;
+ tmp_sender += mailbox_length;
+ domainname_match = (! strncasecmp (tmp_email, tmp_sender,
+ domainname_length));
+ if (mailbox_match && domainname_match)
+ ret = 0;
+ }
}
- else
- mutt_any_key_to_continue (_("Failed to verify sender"));
+ }
}
+ else
+ mutt_any_key_to_continue (_("Failed to verify sender"));
+ }
else
mutt_any_key_to_continue (_("Failed to figure out sender"));
if (signature_key)
- {
- gpgme_key_release (signature_key);
- signature_key = NULL;
- }
+ {
+ gpgme_key_release (signature_key);
+ signature_key = NULL;
+ }
return ret;
}