From: Pietro Cerutti Date: Tue, 2 Apr 2019 10:47:28 +0000 (+0000) Subject: Make sure email size is consistently computed in status bar and index X-Git-Tag: 2019-10-25~282 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ae87f840f693f2bfa8dcd6be7b4c99360a3fd994;p=neomutt Make sure email size is consistently computed in status bar and index --- diff --git a/email/email.c b/email/email.c index b9b952dce..15b8a5af1 100644 --- a/email/email.c +++ b/email/email.c @@ -100,3 +100,15 @@ bool mutt_email_cmp_strict(const struct Email *e1, const struct Email *e2) return false; } } + +/** + * mutt_email_size - compute the size of an email + * @param e Email + * @retval num Size of the email, in bytes + */ +size_t mutt_email_size(const struct Email *e) +{ + if (!e || !e->content) + return 0; + return e->content->length + e->content->offset - e->content->hdr_offset; +} diff --git a/email/email.h b/email/email.h index 052f23923..4b5249848 100644 --- a/email/email.h +++ b/email/email.h @@ -129,5 +129,6 @@ STAILQ_HEAD(EmailList, EmailNode); bool mutt_email_cmp_strict(const struct Email *e1, const struct Email *e2); void mutt_email_free(struct Email **e); struct Email *mutt_email_new(void); +size_t mutt_email_size(const struct Email *e); #endif /* MUTT_EMAIL_EMAIL_H */ diff --git a/hdrline.c b/hdrline.c index a1023c89c..8571d192a 100644 --- a/hdrline.c +++ b/hdrline.c @@ -643,7 +643,7 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co case 'c': colorlen = add_index_color(buf, buflen, flags, MT_COLOR_INDEX_SIZE); - mutt_str_pretty_size(tmp, sizeof(tmp), (long) e->content->length); + mutt_str_pretty_size(tmp, sizeof(tmp), mutt_email_size(e)); mutt_format_s(buf + colorlen, buflen - colorlen, prec, tmp); add_index_color(buf + colorlen, buflen - colorlen, flags, MT_COLOR_INDEX); break; diff --git a/mailbox.c b/mailbox.c index 73af24afc..c91cd3fbf 100644 --- a/mailbox.c +++ b/mailbox.c @@ -534,19 +534,6 @@ void mutt_mailbox_changed(struct Mailbox *m, enum MailboxNotification action) m->notify(m, action); } -/** - * email_size - Helper function to make sure we always use the same metric to - * compute the size of an email - * @param e Email - * @retval num Size of the email, in bytes - */ -static size_t email_size(const struct Email *e) -{ - if (!e || !e->content) - return 0; - return e->content->length + e->content->offset - e->content->hdr_offset; -} - /** * mutt_mailbox_size_add - Add an email's size to the total size of a Mailbox * @param m Mailbox @@ -554,7 +541,7 @@ static size_t email_size(const struct Email *e) */ void mutt_mailbox_size_add(struct Mailbox *m, const struct Email *e) { - m->size += email_size(e); + m->size += mutt_email_size(e); } /** @@ -564,6 +551,6 @@ void mutt_mailbox_size_add(struct Mailbox *m, const struct Email *e) */ void mutt_mailbox_size_sub(struct Mailbox *m, const struct Email *e) { - m->size -= email_size(e); + m->size -= mutt_email_size(e); }