Skip to content

Commit

Permalink
Always add a Received header, at start if no others. Also include som…
Browse files Browse the repository at this point in the history
…e SSL

information in the fdm Received header. From gmp at wow.st.
  • Loading branch information
nicm committed Oct 24, 2016
1 parent 766fcf6 commit f9cef7d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
41 changes: 39 additions & 2 deletions child-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void fetch_free1(struct mail_ctx *);
int fetch_enqueue(struct account *, struct io *, struct mail *);
int fetch_dequeue(struct account *, struct mail_ctx *);

const char *account_get_method(struct account *);

struct mail_queue fetch_matchq;
struct mail_queue fetch_deliverq;

Expand Down Expand Up @@ -503,6 +505,41 @@ fetch_account(struct account *a, struct io *pio, int nflags, double tim)
return (aborted);
}

/*
* Returns a string describing the connection method, including cipher used (if
* any).
*/
const char *
account_get_method(struct account *a)
{
struct fetch_imap_data *idata;
struct fetch_pop3_data *pdata;
const SSL_CIPHER *cipher;
static char s[128];
char tmp[128];

if (a->fetch == &fetch_imap) {
idata = a->data;
if (idata->io->ssl != NULL)
cipher = SSL_get_current_cipher(idata->io->ssl);
} else if (a->fetch == &fetch_pop3) {
pdata = a->data;
if (pdata->io->ssl != NULL)
cipher = SSL_get_current_cipher(pdata->io->ssl);
} else
cipher = NULL;
if (cipher != NULL) {
snprintf(tmp, sizeof tmp, "version=%s %s %d bits",
SSL_CIPHER_get_version(cipher),
SSL_CIPHER_get_name(cipher),
SSL_CIPHER_get_bits(cipher, NULL));
} else
snprintf(tmp, sizeof tmp, "unencrypted");

snprintf(s, sizeof s, "with %s (%s)", a->fetch->name, tmp);
return (s);
}

/*
* Check mail for various problems, add headers and fill tags, then create an
* mctx and enqueue it onto the fetch queue.
Expand Down Expand Up @@ -616,8 +653,8 @@ fetch_enqueue(struct account *a, struct io *pio, struct mail *m)
rhost = conf.host_name;

error = insert_header(m, "received", "Received: by "
"%.450s (%s " VERSION ", account \"%.450s\");\n\t%s",
rhost, __progname, a->name, rtime);
"%.350s (%s " VERSION ", account \"%.350s\") \n\t%s\n\t%s",
rhost, __progname, a->name, account_get_method(a), rtime);
}
if (error != 0)
log_debug3("%s: couldn't add received header", a->name);
Expand Down
9 changes: 6 additions & 3 deletions mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ insert_header(struct mail *m, const char *before, const char *fmt, ...)
if (before != NULL) {
/* Insert before header. */
ptr = find_header(m, before, &len, 0);
if (ptr == NULL)
return (-1);
off = ptr - m->data;
if (ptr == NULL) {
log_debug3("header \"%s\" not found, adding to the top",
before);
off = 0;
} else
off = ptr - m->data;
} else {
/* Insert at the end. */
if (m->body == 0) {
Expand Down

0 comments on commit f9cef7d

Please sign in to comment.