#include "pager.h"
#include "sort.h"
+#include "lib/mem.h"
+#include "lib/intl.h"
+#include "lib/str.h"
+#include "lib/debug.h"
+
#include <sys/wait.h>
#include <string.h>
#include <stdlib.h>
* General helper functions.
*/
-/* return true when S pints to a didgit or letter. */
+/* return true when S points to a didgit or letter. */
static int digit_or_letter (const unsigned char *s)
{
- return ((*s >= '0' && *s < '9')
+ return ((*s >= '0' && *s <= '9')
|| (*s >= 'A' && *s <= 'Z')
|| (*s >= 'a' && *s <= 'z'));
}
if (k->kobj && k->kobj->subkeys) {
s = k->kobj->subkeys->keyid;
- if ((!option (OPTPGPLONGIDS)) && (strlen (s) == 16))
+ if ((!option (OPTPGPLONGIDS)) && (mutt_strlen (s) == 16))
/* Return only the short keyID. */
s += 8;
}
rv |= CRYPT_KV_STRONGID;
if (addr->mailbox && u_addr->mailbox
- && mutt_strcasecmp (addr->mailbox, u_addr->mailbox) == 0)
+ && safe_strcasecmp (addr->mailbox, u_addr->mailbox) == 0)
rv |= CRYPT_KV_ADDR;
if (addr->personal && u_addr->personal
- && mutt_strcasecmp (addr->personal, u_addr->personal) == 0)
+ && safe_strcasecmp (addr->personal, u_addr->personal) == 0)
rv |= CRYPT_KV_STRING;
return rv;
err = gpgme_new (&ctx);
if (err) {
- mutt_error ("error creating gpgme context: %s\n", gpgme_strerror (err));
+ mutt_error (_("error creating gpgme context: %s\n"), gpgme_strerror (err));
sleep (2);
mutt_exit (1);
}
if (for_smime) {
err = gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
if (err) {
- mutt_error ("error enabling CMS protocol: %s\n", gpgme_strerror (err));
+ mutt_error (_("error enabling CMS protocol: %s\n"), gpgme_strerror (err));
sleep (2);
mutt_exit (1);
}
err = gpgme_data_new (&data);
if (err) {
- mutt_error ("error creating gpgme data object: %s\n",
+ mutt_error (_("error creating gpgme data object: %s\n"),
gpgme_strerror (err));
sleep (2);
mutt_exit (1);
}
unlink (tempfile);
if (err) {
- mutt_error ("error allocating data object: %s\n", gpgme_strerror (err));
+ mutt_error (_("error allocating data object: %s\n"), gpgme_strerror (err));
return NULL;
}
err = gpgme_data_new_from_filepart (&data, NULL, fp, offset, length);
if (err) {
- mutt_error ("error allocating data object: %s\n", gpgme_strerror (err));
+ mutt_error (_("error allocating data object: %s\n"), gpgme_strerror (err));
return NULL;
}
err = ((gpgme_data_seek (data, 0, SEEK_SET) == -1)
? gpgme_error_from_errno (errno) : 0);
if (err) {
- mutt_error ("error rewinding data object: %s\n", gpgme_strerror (err));
+ mutt_error (_("error rewinding data object: %s\n"), gpgme_strerror (err));
return -1;
}
}
}
if (nread == -1) {
- mutt_error ("error reading data object: %s\n", strerror (errno));
+ mutt_error (_("error reading data object: %s\n"), strerror (errno));
return -1;
}
return 0;
else
fclose (fp);
if (nread == -1) {
- mutt_error ("error reading data object: %s\n", gpgme_strerror (err));
+ mutt_error (_("error reading data object: %s\n"), gpgme_strerror (err));
unlink (tempfile);
fclose (fp);
return NULL;
rset[rset_n++] = key;
}
else {
- mutt_error ("error adding recipient `%s': %s\n",
+ mutt_error (_("error adding recipient `%s': %s\n"),
buf, gpgme_strerror (err));
FREE (&rset);
return NULL;
gpgme_key_release (key);
gpgme_key_release (key2);
gpgme_release (listctx);
- mutt_error (_("ambiguous specfication of secret key `%s'\n"), signid);
+ mutt_error (_("ambiguous specification of secret key `%s'\n"), signid);
return -1;
}
gpgme_op_keylist_end (listctx);
plaintext, ciphertext);
mutt_need_hard_redraw ();
if (err) {
- mutt_error ("error encrypting data: %s\n", gpgme_strerror (err));
+ mutt_error (_("error encrypting data: %s\n"), gpgme_strerror (err));
gpgme_data_release (ciphertext);
gpgme_release (ctx);
return NULL;
if (err) {
gpgme_data_release (signature);
gpgme_release (ctx);
- mutt_error ("error signing data: %s\n", gpgme_strerror (err));
+ mutt_error (_("error signing data: %s\n"), gpgme_strerror (err));
return NULL;
}
gpgme_signature_t sig;
unsigned int i;
- state_attach_puts (_("A system error occured"), s);
+ state_attach_puts (_("A system error occurred"), s);
/* Try to figure out some more detailed system error information. */
result = gpgme_op_verify_result (ctx);
state_attach_puts (": ", s);
if (t0)
state_attach_puts (t0, s);
- if (t1 && !(t0 && !strcmp (t0, t1))) {
+ if (t1 && !(t0 && !mutt_strcmp (t0, t1))) {
if (t0)
state_attach_puts (",", s);
state_attach_puts (t1, s);
return;
is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP);
- buf = safe_malloc (strlen (prefix) + strlen (s) * 4 + 2);
+ buf = safe_malloc (mutt_strlen (prefix) + mutt_strlen (s) * 4 + 2);
strcpy (buf, prefix); /* __STRCPY_CHECKED__ */
- p = buf + strlen (buf);
- if (is_pgp && strlen (s) == 40) { /* PGP v4 style formatted. */
+ p = buf + mutt_strlen (buf);
+ if (is_pgp && mutt_strlen (s) == 40) { /* PGP v4 style formatted. */
for (i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) {
*p++ = s[0];
*p++ = s[1];
err = gpgme_data_new_from_file (&message, tempfile, 1);
if (err) {
gpgme_data_release (signature);
- mutt_error ("error allocating data object: %s\n", gpgme_strerror (err));
+ mutt_error (_("error allocating data object: %s\n"), gpgme_strerror (err));
return -1;
}
ctx = create_gpgme_context (is_smime);
if (notation->value) {
state_attach_puts (notation->value, s);
if (!(*notation->value
- && (notation->value[strlen (notation->value) - 1] ==
+ && (notation->value[mutt_strlen (notation->value) - 1] ==
'\n')))
state_attach_puts ("\n", s);
}
gpgme_release (ctx);
state_attach_puts (_("[-- End signature information --]\n\n"), s);
- dprint (1, (debugfile, "verify_one: returning %d.\n", badsig));
+ debug_print (1, ("returning %d.\n", badsig));
return badsig ? 1 : anywarn ? 2 : 0;
}
}
while (fgets (buf, sizeof (buf), tfp)) {
- if (!mutt_strncmp ("-----BEGIN PGP ", buf, 15)) {
+ if (!safe_strncmp ("-----BEGIN PGP ", buf, 15)) {
if (!mutt_strcmp ("MESSAGE-----\n", buf + 15))
enc = 1;
else if (!mutt_strcmp ("SIGNED MESSAGE-----\n", buf + 15))
char body_charset[STRING]; /* Only used for clearsigned messages. */
- dprint (2, (debugfile, "Entering pgp_application_pgp handler\n"));
+ debug_print (2, ("Entering pgp_application_pgp handler\n"));
/* For clearsigned messages we won't be able to get a character set
but we know that this may only be text thus we assume Latin-1
bytes -= (offset - last_pos); /* don't rely on mutt_strlen(buf) */
last_pos = offset;
- if (!mutt_strncmp ("-----BEGIN PGP ", buf, 15)) {
+ if (!safe_strncmp ("-----BEGIN PGP ", buf, 15)) {
clearsign = 0;
start_pos = last_pos;
/* Copy PGP material to an data container */
armored_data = create_gpgme_data ();
- gpgme_data_write (armored_data, buf, strlen (buf));
+ gpgme_data_write (armored_data, buf, mutt_strlen (buf));
while (bytes > 0 && fgets (buf, sizeof (buf) - 1, s->fpin) != NULL) {
offset = ftell (s->fpin);
bytes -= (offset - last_pos); /* don't rely on mutt_strlen(buf) */
last_pos = offset;
- gpgme_data_write (armored_data, buf, strlen (buf));
+ gpgme_data_write (armored_data, buf, mutt_strlen (buf));
if ((needpass && !mutt_strcmp ("-----END PGP MESSAGE-----\n", buf))
|| (!needpass
" of PGP message! --]\n\n"), s);
return;
}
- dprint (2, (debugfile, "Leaving pgp_application_pgp handler\n"));
+ debug_print (2, ("Leaving pgp_application_pgp handler\n"));
}
/*
BODY *orig_body = a;
int is_signed;
- dprint (2, (debugfile, "Entering pgp_encrypted handler\n"));
+ debug_print (2, ("Entering pgp_encrypted handler\n"));
a = a->parts;
if (!a || a->type != TYPEAPPLICATION || !a->subtype
|| ascii_strcasecmp ("pgp-encrypted", a->subtype)
fclose (fpout);
mutt_unlink (tempfile);
- dprint (2, (debugfile, "Leaving pgp_encrypted handler\n"));
+ debug_print (2, ("Leaving pgp_encrypted handler\n"));
}
/* Support for application/smime */
int is_signed;
- dprint (2, (debugfile, "Entering smime_encrypted handler\n"));
+ debug_print (2, ("Entering smime_encrypted handler\n"));
a->warnsig = 0;
mutt_mktemp (tempfile);
fclose (fpout);
mutt_unlink (tempfile);
- dprint (2, (debugfile, "Leaving smime_encrypted handler\n"));
+ debug_print (2, ("Leaving smime_encrypted handler\n"));
}
crypt_key_t **t = (crypt_key_t **) b;
int r;
- if ((r = mutt_strcasecmp ((*s)->uid, (*t)->uid)))
+ if ((r = safe_strcasecmp ((*s)->uid, (*t)->uid)))
return r > 0;
else
- return mutt_strcasecmp (crypt_keyid (*s), crypt_keyid (*t)) > 0;
+ return safe_strcasecmp (crypt_keyid (*s), crypt_keyid (*t)) > 0;
}
static int crypt_compare_address (const void *a, const void *b)
crypt_key_t **t = (crypt_key_t **) b;
int r;
- if ((r = mutt_strcasecmp (crypt_keyid (*s), crypt_keyid (*t))))
+ if ((r = safe_strcasecmp (crypt_keyid (*s), crypt_keyid (*t))))
return r > 0;
else
- return mutt_strcasecmp ((*s)->uid, (*t)->uid) > 0;
+ return safe_strcasecmp ((*s)->uid, (*t)->uid) > 0;
}
static int crypt_compare_keyid (const void *a, const void *b)
if (ts < tt)
return 0;
- return mutt_strcasecmp ((*s)->uid, (*t)->uid) > 0;
+ return safe_strcasecmp ((*s)->uid, (*t)->uid) > 0;
}
static int crypt_compare_date (const void *a, const void *b)
if (ts < tt)
return 0;
- if ((r = mutt_strcasecmp ((*s)->uid, (*t)->uid)))
+ if ((r = safe_strcasecmp ((*s)->uid, (*t)->uid)))
return r > 0;
- return (mutt_strcasecmp (crypt_keyid ((*s)), crypt_keyid ((*t)))) > 0;
+ return (safe_strcasecmp (crypt_keyid ((*s)), crypt_keyid ((*t)))) > 0;
}
static int crypt_compare_trust (const void *a, const void *b)
int any = 0;
for (; dn->key; dn++) {
- if (!strcmp (dn->key, key)) {
+ if (!mutt_strcmp (dn->key, key)) {
if (any)
fputs (" + ", fp);
- print_utf8 (fp, dn->value, strlen (dn->value));
+ print_utf8 (fp, dn->value, mutt_strlen (dn->value));
any = 1;
}
}
/* now print the rest without any specific ordering */
for (; dn->key; dn++) {
for (i = 0; stdpart[i]; i++) {
- if (!strcmp (dn->key, stdpart[i]))
+ if (!mutt_strcmp (dn->key, stdpart[i]))
break;
}
if (!stdpart[i]) {
putc (' ', fp);
}
if (is_pgp)
- print_utf8 (fp, s, strlen (s));
+ print_utf8 (fp, s, mutt_strlen (s));
else
parse_and_print_user_id (fp, s);
putc ('\n', fp);
if (key->subkeys) {
s = key->subkeys->fpr;
fputs (_("Fingerprint: "), fp);
- if (is_pgp && strlen (s) == 40) {
+ if (is_pgp && mutt_strlen (s) == 40) {
for (i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) {
putc (*s, fp);
putc (s[1], fp);
s = subkey->keyid;
putc ('\n', fp);
- if (strlen (s) == 16)
+ if (mutt_strlen (s) == 16)
s += 8; /* display only the short keyID */
fprintf (fp, "Subkey ....: 0x%s", s);
if (subkey->revoked) {
mutt_mktemp (tempfile);
if (!(fp = safe_fopen (tempfile, "w"))) {
- mutt_perror _("Can't create temporary file");
+ mutt_perror (_("Can't create temporary file"));
return;
}
k = key->kobj;
gpgme_key_ref (k);
- while ((s = k->chain_id) && k->subkeys && strcmp (s, k->subkeys->fpr)) {
+ while ((s = k->chain_id) && k->subkeys && mutt_strcmp (s, k->subkeys->fpr)) {
putc ('\n', fp);
err = gpgme_op_keylist_start (listctx, s, 0);
gpgme_key_release (k);
err = gpgme_new (&ctx);
if (err) {
- mutt_error ("gpgme_new failed: %s", gpgme_strerror (err));
+ mutt_error (_("gpgme_new failed: %s"), gpgme_strerror (err));
FREE (&pattern);
return NULL;
}
FREE (&patarr[n]);
FREE (&patarr);
if (err) {
- mutt_error ("gpgme_op_keylist_start failed: %s", gpgme_strerror (err));
+ mutt_error (_("gpgme_op_keylist_start failed: %s"), gpgme_strerror (err));
gpgme_release (ctx);
FREE (&pattern);
return NULL;
}
}
if (gpg_err_code (err) != GPG_ERR_EOF)
- mutt_error ("gpgme_op_keylist_next failed: %s", gpgme_strerror (err));
+ mutt_error (_("gpgme_op_keylist_next failed: %s"), gpgme_strerror (err));
gpgme_op_keylist_end (ctx);
no_pgphints:
;
gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS);
err = gpgme_op_keylist_start (ctx, pattern, 0);
if (err) {
- mutt_error ("gpgme_op_keylist_start failed: %s", gpgme_strerror (err));
+ mutt_error (_("gpgme_op_keylist_start failed: %s"), gpgme_strerror (err));
gpgme_release (ctx);
FREE (&pattern);
return NULL;
}
}
if (gpg_err_code (err) != GPG_ERR_EOF)
- mutt_error ("gpgme_op_keylist_next failed: %s", gpgme_strerror (err));
+ mutt_error (_("gpgme_op_keylist_next failed: %s"), gpgme_strerror (err));
gpgme_op_keylist_end (ctx);
}
for (t = strtok (scratch, " ,.:\"()<>\n"); t;
t = strtok (NULL, " ,.:\"()<>\n")) {
- if (strlen (t) > 3)
+ if (mutt_strlen (t) > 3)
hints = mutt_add_list (hints, t);
}
if (!keys)
return NULL;
- dprint (5, (debugfile, "crypt_getkeybyaddr: looking for %s <%s>.",
- a->personal, a->mailbox));
+ debug_print (5, ("looking for %s <%s>.\n", a->personal, a->mailbox));
for (k = keys; k; k = k->next) {
- dprint (5, (debugfile, " looking at key: %s `%.15s'\n",
- crypt_keyid (k), k->uid));
+ debug_print (5, (" looking at key: %s `%.15s'\n", crypt_keyid (k), k->uid));
if (abilities && !(k->flags & abilities)) {
- dprint (5, (debugfile, " insufficient abilities: Has %x, want %x\n",
- k->flags, abilities));
+ debug_print (5, (" insufficient abilities: Has %x, want %x\n", k->flags, abilities));
continue;
}
continue;
match = 0;
- dprint (5, (debugfile, "crypt_getkeybystr: matching \"%s\" against "
- "key %s, \"%s\": ", p, crypt_keyid (k), k->uid));
+ debug_print (5, ("matching \"%s\" against " "key %s, \"%s\":\n", p, crypt_keyid (k), k->uid));
- if (!*p || !mutt_strcasecmp (p, crypt_keyid (k))
- || (!mutt_strncasecmp (p, "0x", 2)
- && !mutt_strcasecmp (p + 2, crypt_keyid (k)))
+ if (!*p || !safe_strcasecmp (p, crypt_keyid (k))
+ || (!safe_strncasecmp (p, "0x", 2)
+ && !safe_strcasecmp (p + 2, crypt_keyid (k)))
|| (option (OPTPGPLONGIDS)
- && !mutt_strncasecmp (p, "0x", 2)
- && !mutt_strcasecmp (p + 2, crypt_keyid (k) + 8))
- || mutt_stristr (k->uid, p)) {
+ && !safe_strncasecmp (p, "0x", 2)
+ && !safe_strcasecmp (p + 2, crypt_keyid (k) + 8))
+ || str_isstr (k->uid, p)) {
crypt_key_t *tmp;
- dprint (5, (debugfile, "match.\n"));
+ debug_print (5, ("match.\n"));
*matches_endp = tmp = crypt_copy_key (k);
matches_endp = &tmp->next;
if (whatfor) {
for (l = id_defaults; l; l = l->next)
- if (!mutt_strcasecmp (whatfor, l->what)) {
+ if (!safe_strcasecmp (whatfor, l->what)) {
strfcpy (resp, NONULL (l->dflt), sizeof (resp));
break;
}
if (whatfor) {
if (l)
- mutt_str_replace (&l->dflt, resp);
+ str_replace (&l->dflt, resp);
else {
l = safe_malloc (sizeof (struct crypt_cache));
l->next = id_defaults;
if (is_smime)
choice =
mutt_multi_choice (_
- ("S/MIME (e)ncrypt, (s)ign, sign (a)s, (b)oth, (t)oggle or (f)orget it?"),
- _("esabtf"));
+ ("S/MIME (e)ncrypt, (s)ign, sign (a)s, (b)oth, (p)gp or (c)lear?"),
+ _("esabpfc"));
else
choice =
mutt_multi_choice (_
- ("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, (t)oggle or (f)orget it?"),
- _("esabtf"));
+ ("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, s/(m)ime or (c)lear?"),
+ _("esabmfc"));
switch (choice) {
case 1: /* (e)ncrypt */
msg->security |= (is_smime ? SMIMEENCRYPT : PGPENCRYPT);
+ msg->security &= ~(is_smime ? SMIMESIGN : PGPSIGN);
break;
case 2: /* (s)ign */
msg->security |= (is_smime ? SMIMESIGN : PGPSIGN);
+ msg->security &= ~(is_smime ? SMIMEENCRYPT : PGPENCRYPT);
break;
case 3: /* sign (a)s */
is_smime ? APPLICATION_SMIME :
APPLICATION_PGP, NULL))) {
snprintf (input_signas, sizeof (input_signas), "0x%s", crypt_keyid (p));
- mutt_str_replace (is_smime ? &SmimeDefaultKey : &PgpSignAs,
+ str_replace (is_smime ? &SmimeDefaultKey : &PgpSignAs,
input_signas);
crypt_free_key (&p);
msg->security |= (is_smime ? SMIMESIGN : PGPSIGN);
}
+#if 0
else {
msg->security &= (is_smime ? ~SMIMESIGN : ~PGPSIGN);
}
+#endif
*redraw = REDRAW_FULL;
break;
(is_smime ? (SMIMEENCRYPT | SMIMESIGN) : (PGPENCRYPT | PGPSIGN));
break;
- case 5: /* (t)oggle */
+ case 5: /* (p)gp or s/(m)ime */
is_smime = !is_smime;
break;
- case 6: /* (f)orget it */
+ case 6: /* (c)lear */
msg->security = 0;
break;
}
- if (choice == 6);
+ if (choice == 6 || choice == 7);
else if (is_smime) {
msg->security &= ~APPLICATION_PGP;
msg->security |= APPLICATION_SMIME;
int sender_length = 0;
int uid_length = 0;
- sender_length = strlen (sender->mailbox);
+ sender_length = mutt_strlen (sender->mailbox);
for (uid = key->uids; uid && ret; uid = uid->next) {
- uid_length = strlen (uid->email);
+ uid_length = mutt_strlen (uid->email);
if (1 && (uid->email[0] == '<')
&& (uid->email[uid_length - 1] == '>')
&& (uid_length == sender_length + 2)