[balsa/70-libbalsa-message-structure] message: declare LibBalsaMessage:length as gint64
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/70-libbalsa-message-structure] message: declare LibBalsaMessage:length as gint64
- Date: Thu, 7 Apr 2022 22:33:44 +0000 (UTC)
commit 6bebb429b53baea454f323dc9d227226027d0da5
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Thu Apr 7 18:30:16 2022 -0400
message: declare LibBalsaMessage:length as gint64
instead of glong, and revise accessors. Also use strtoll() to populate
it instead of atoi(), and replace the value with -1 on error.
libbalsa/libbalsa_private.h | 2 +-
libbalsa/mailbox.c | 8 ++++++--
libbalsa/message.c | 35 +++++++++++++++++++++++------------
libbalsa/message.h | 5 ++---
4 files changed, 32 insertions(+), 18 deletions(-)
---
diff --git a/libbalsa/libbalsa_private.h b/libbalsa/libbalsa_private.h
index 11ff99496..734bdb54c 100644
--- a/libbalsa/libbalsa_private.h
+++ b/libbalsa/libbalsa_private.h
@@ -37,7 +37,7 @@ struct LibBalsaMailboxIndexEntry_ {
time_t internal_date;
unsigned short status_icon;
unsigned short attach_icon;
- unsigned long size;
+ gint64 size;
gchar *foreground;
gchar *background;
unsigned foreground_set:1;
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 2619a38e9..ec72a0dac 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -3259,8 +3259,12 @@ mailbox_model_get_value(GtkTreeModel *tree_model,
break;
case LB_MBOX_SIZE_COL:
if(msg) {
- tmp = libbalsa_size_to_gchar(msg->size);
- g_value_take_string(value, tmp);
+ if (msg->size != -1) {
+ tmp = libbalsa_size_to_gchar(msg->size);
+ g_value_take_string(value, tmp);
+ } else {
+ g_value_set_static_string(value, "?");
+ }
}
else g_value_set_static_string(value, " ");
break;
diff --git a/libbalsa/message.c b/libbalsa/message.c
index 34f3da640..6682d9928 100644
--- a/libbalsa/message.c
+++ b/libbalsa/message.c
@@ -100,10 +100,10 @@ struct _LibBalsaMessage {
/* message body */
LibBalsaMessageBody *body_list;
- /* end of pointers, begin long ints */
- glong length; /* byte len */
+ /* end of pointers, begin 64-bit ints */
+ gint64 length; /* byte len */
- /* end of longs, begin ints */
+ /* end of 64-bit ints, begin ints */
/* GnuPG or S/MIME sign and/or encrypt message (sending), or status of received message */
guint crypt_mode;
@@ -1074,8 +1074,15 @@ libbalsa_message_init_from_gmime(LibBalsaMessage * message,
libbalsa_message_set_subject_from_header(message, header);
header = g_mime_object_get_header(GMIME_OBJECT(mime_msg), "Content-Length");
- if (header)
- message->length = atoi(header);
+ if (header) {
+ char *endptr;
+
+ message->length = strtoll(header, &endptr, 10);
+ if (*endptr != '\0') {
+ message->length = -1;
+ g_debug("Bad Content-Length header: ā%sā; using -1", header);
+ }
+ }
header = g_mime_message_get_message_id(mime_msg);
if (header)
@@ -1242,11 +1249,15 @@ lbmsg_set_header(LibBalsaMessage *message,
} else if ((headers->dispnotify_to == NULL) &&
(g_ascii_strcasecmp(name, "Disposition-Notification-To") == 0)) {
headers->dispnotify_to = internet_address_list_parse(libbalsa_parser_options(), value);
- } else
- if (g_ascii_strcasecmp(name, "Content-Length") == 0) {
- message->length = atoi(value);
- } else
- if (all) {
+ } else if (g_ascii_strcasecmp(name, "Content-Length") == 0) {
+ char *endptr;
+
+ message->length = strtoll(value, &endptr, 10);
+ if (*endptr != '\0') {
+ message->length = -1;
+ g_debug("Bad Content-Length header: ā%sā; using -1", value);
+ }
+ } else if (all) {
headers->user_hdrs =
g_list_prepend(headers->user_hdrs,
libbalsa_create_hdr_pair(name, g_strdup(value)));
@@ -1544,7 +1555,7 @@ libbalsa_message_get_msgno(LibBalsaMessage *message)
}
-glong
+gint64
libbalsa_message_get_length(LibBalsaMessage *message)
{
g_return_val_if_fail(LIBBALSA_IS_MESSAGE(message), 0);
@@ -1718,7 +1729,7 @@ libbalsa_message_set_has_all_headers(LibBalsaMessage *message,
void
libbalsa_message_set_length(LibBalsaMessage *message,
- glong length)
+ gint64 length)
{
g_return_if_fail(LIBBALSA_IS_MESSAGE(message));
diff --git a/libbalsa/message.h b/libbalsa/message.h
index 4a396180a..272227941 100644
--- a/libbalsa/message.h
+++ b/libbalsa/message.h
@@ -260,7 +260,6 @@ void libbalsa_message_set_subject_from_header(LibBalsaMessage * message,
function out if we find a way.
*/
const gchar* libbalsa_message_get_subject(LibBalsaMessage* message);
-glong libbalsa_message_get_no(LibBalsaMessage* msg);
LibBalsaMessageAttach libbalsa_message_get_attach_icon(LibBalsaMessage *
message);
#define libbalsa_message_date_to_utf8(m, f) \
@@ -296,7 +295,7 @@ GMimeMessage *libbalsa_message_get_mime_message(LibBalsaMessage *messa
LibBalsaMessageFlag libbalsa_message_get_flags(LibBalsaMessage *message);
const gchar *libbalsa_message_get_message_id(LibBalsaMessage *message);
guint libbalsa_message_get_msgno(LibBalsaMessage *message);
-glong libbalsa_message_get_length(LibBalsaMessage *message);
+gint64 libbalsa_message_get_length(LibBalsaMessage *message);
gboolean libbalsa_message_get_has_all_headers(LibBalsaMessage *message);
InternetAddressList *libbalsa_message_get_sender(LibBalsaMessage *message);
gboolean libbalsa_message_get_request_dsn(LibBalsaMessage *message);
@@ -323,7 +322,7 @@ void libbalsa_message_set_msgno(LibBalsaMessage *message,
void libbalsa_message_set_has_all_headers(LibBalsaMessage *message,
gboolean has_all_headers);
void libbalsa_message_set_length(LibBalsaMessage *message,
- glong length);
+ gint64 length);
void libbalsa_message_set_mime_message(LibBalsaMessage *message,
GMimeMessage *mime_message);
void libbalsa_message_set_sender(LibBalsaMessage *message,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]