[balsa] * libbalsa/imap/imap-{commands, handle}.c: catch errors early on
- From: Pawel Salek <pawels src gnome org>
- To: svn-commits-list gnome org
- Subject: [balsa] * libbalsa/imap/imap-{commands, handle}.c: catch errors early on
- Date: Wed, 24 Jun 2009 21:45:39 +0000 (UTC)
commit 28505e846227574330e2422e05b6fdba24a7c7e6
Author: Pawel Salek <pawsa damage localdomain>
Date: Wed Jun 24 23:44:12 2009 +0200
* libbalsa/imap/imap-{commands,handle}.c: catch errors early on
for more accurate error messages.
* libbalsa/imap/imap_search.c: ditto.
* libbalsa/imap/imap-handle.h: warn if idle_disable's result is ignored.
* libbalsa/mailbox_imap.c: correct tranformation of rfc822 groups
from ImapAddress to InternetAddress (together with Peter B).
* src/sendmsg-window.c: check that string is not-null before
setting window title.
ChangeLog | 13 +++++-
libbalsa/imap/imap-commands.c | 13 ++++--
libbalsa/imap/imap-handle.c | 11 +++--
libbalsa/imap/imap-handle.h | 3 +-
libbalsa/imap/imap_search.c | 2 +-
libbalsa/imap/libimap.h | 2 +-
libbalsa/mailbox_imap.c | 92 ++++++++++++++++++++++-------------------
src/balsa-app.c | 6 +-
src/sendmsg-window.c | 2 +-
9 files changed, 84 insertions(+), 60 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 294f7dc..7cec52d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,18 @@
+2006-06-24 Pawel Salek
+
+ * libbalsa/imap/imap-{commands,handle}.c: catch errors early on
+ for more accurate error messages.
+ * libbalsa/imap/imap_search.c: ditto.
+ * libbalsa/imap/imap-handle.h: warn if idle_disable's result is ignored.
+ * libbalsa/mailbox_imap.c: correct tranformation of rfc822 groups
+ from ImapAddress to InternetAddress (together with Peter B).
+ * src/sendmsg-window.c: check that string is not-null before
+ setting window title.
+
2006-06-11 Pawel Salek
* libbalsa/mailbox_imap.c: do not create empty address lists.
- This make message compose code believe that reply-to is set.
+ This makes the message compose code believe that reply-to is set.
2009-06-07 Peter Bloomfield
diff --git a/libbalsa/imap/imap-commands.c b/libbalsa/imap/imap-commands.c
index 414fd1b..b6b94c9 100644
--- a/libbalsa/imap/imap-commands.c
+++ b/libbalsa/imap/imap-commands.c
@@ -493,7 +493,7 @@ imap_mbox_append_multi_real(ImapMboxHandle *handle,
if(uid_sequence)
uid_sequence->ranges = NULL;
- imap_handle_idle_disable(handle);
+ if (!imap_handle_idle_disable(handle)) return IMR_SEVERED;
for(msg_cnt=0;
(msg_size = dump_cb(buf, sizeof(buf),
IMA_STAGE_NEW_MSG, &flags, cb_arg)) >0;
@@ -863,7 +863,9 @@ imap_assure_needed_flags(ImapMboxHandle *h, ImapMsgFlag needed_flags)
case IMSGF_RECENT: flg = "RECENT"; break;
default: g_free(seqno); continue;
}
- if(!cmd) imap_handle_idle_disable(h);
+ if(!cmd) {
+ if (!imap_handle_idle_disable(h)) { rc = IMR_SEVERED; break; }
+ }
cmd = g_strdup_printf(cmd_format, seqno, flg);
g_free(seqno);
flag[issued_cmd] = fnd.flag;
@@ -1588,7 +1590,7 @@ imap_mbox_thread(ImapMboxHandle *h, const char *how, ImapSearchKey *filter)
cmdno = imap_make_tag(tag);
- imap_handle_idle_disable(h);
+ if (!imap_handle_idle_disable(h)) { rc = IMR_SEVERED; goto exit_cleanup; }
sio_printf(h->sio, "%s THREAD %s UTF-8 ", tag, how);
if(!filter)
sio_write(h->sio, "ALL", 3);
@@ -1604,6 +1606,7 @@ imap_mbox_thread(ImapMboxHandle *h, const char *how, ImapSearchKey *filter)
while(rc == IMR_UNTAGGED);
imap_handle_idle_enable(h, 30);
}
+ exit_cleanup:
HANDLE_UNLOCK(h);
return rc;
@@ -1899,7 +1902,7 @@ imap_mbox_sort_filter(ImapMboxHandle *handle, ImapSortKey key, int ascending,
cmdno = imap_make_tag(tag);
keystr = sort_code_to_string(key);
- imap_handle_idle_disable(handle);
+ if (!imap_handle_idle_disable(handle)) { rc = IMR_SEVERED; goto cleanup; }
sio_printf(handle->sio, "%s SORT (%s%s) UTF-8 ", tag,
ascending ? "" : "REVERSE ", keystr);
@@ -1949,7 +1952,7 @@ imap_mbox_sort_filter(ImapMboxHandle *handle, ImapSortKey key, int ascending,
g_node_append_data(handle->thread_root,
GUINT_TO_POINTER(handle->mbox_view.arr[i]));
}
-
+ cleanup:
HANDLE_UNLOCK(handle);
return rc;
diff --git a/libbalsa/imap/imap-handle.c b/libbalsa/imap/imap-handle.c
index 8f222fb..88a9d51 100644
--- a/libbalsa/imap/imap-handle.c
+++ b/libbalsa/imap/imap-handle.c
@@ -466,7 +466,7 @@ imap_cmd_issue(ImapMboxHandle* h, const char* cmd)
return IMR_SEVERED;
/* create sequence for command */
- imap_handle_idle_disable(h);
+ if (!imap_handle_idle_disable(h)) return IMR_SEVERED;
if (imap_cmd_start(h, cmd, &async_cmd)<0)
return IMR_SEVERED; /* irrecoverable connection error. */
@@ -477,7 +477,8 @@ imap_cmd_issue(ImapMboxHandle* h, const char* cmd)
h->iochannel = g_io_channel_unix_new(h->sd);
g_io_channel_set_encoding(h->iochannel, NULL, NULL);
}
- h->async_watch_id = g_io_add_watch(h->iochannel, G_IO_IN, async_process, h);
+ h->async_watch_id = g_io_add_watch(h->iochannel, G_IO_IN|G_IO_HUP,
+ async_process, h);
return IMR_OK /* async_cmd */;
}
@@ -543,7 +544,9 @@ imap_handle_op_cancelled(ImapMboxHandle *h)
void
imap_handle_disconnect(ImapMboxHandle *h)
{
- imap_handle_idle_disable(h);
+ gboolean still_connected __attribute__ ((__unused__));
+
+ still_connected = imap_handle_idle_disable(h);
if(h->sio) {
sio_detach(h->sio); h->sio = NULL;
}
@@ -2057,7 +2060,7 @@ imap_cmd_exec_cmdno(ImapMboxHandle* handle, const char* cmd,
return IMR_SEVERED;
/* create sequence for command */
- imap_handle_idle_disable(handle);
+ if (!imap_handle_idle_disable(handle)) return IMR_SEVERED;
if (imap_cmd_start(handle, cmd, &cmdno)<0)
return IMR_SEVERED; /* irrecoverable connection error. */
diff --git a/libbalsa/imap/imap-handle.h b/libbalsa/imap/imap-handle.h
index 94fd445..3667597 100644
--- a/libbalsa/imap/imap-handle.h
+++ b/libbalsa/imap/imap-handle.h
@@ -125,7 +125,8 @@ void imap_handle_set_usercb(ImapMboxHandle* h, ImapUserCb cb, void*);
void imap_handle_set_flagscb(ImapMboxHandle* h, ImapFlagsCb cb, void*);
int imap_handle_set_timeout(ImapMboxHandle *, int milliseconds);
gboolean imap_handle_idle_enable(ImapMboxHandle *, int seconds);
-gboolean imap_handle_idle_disable(ImapMboxHandle *);
+gboolean imap_handle_idle_disable(ImapMboxHandle *)
+ __attribute__ ((warn_unused_result));
gboolean imap_handle_op_cancelled(ImapMboxHandle *h);
ImapResult imap_mbox_handle_connect(ImapMboxHandle* r, const char *hst,
int over_ssl);
diff --git a/libbalsa/imap/imap_search.c b/libbalsa/imap/imap_search.c
index e45b129..a790965 100644
--- a/libbalsa/imap/imap_search.c
+++ b/libbalsa/imap/imap_search.c
@@ -505,7 +505,7 @@ imap_search_exec_unlocked(ImapMboxHandle *h, gboolean uid,
ocb = h->search_cb; h->search_cb = (ImapSearchCb)cb;
oarg = h->search_arg; h->search_arg = cb_arg;
- imap_handle_idle_disable(h);
+ if (!imap_handle_idle_disable(h)) return IMR_SEVERED;
split = imap_search_checks(s, IMSE_SEQUENCE);
if(split) {
diff --git a/libbalsa/imap/libimap.h b/libbalsa/imap/libimap.h
index 3a57a78..c4a2376 100644
--- a/libbalsa/imap/libimap.h
+++ b/libbalsa/imap/libimap.h
@@ -104,7 +104,7 @@ typedef enum {
typedef unsigned ImapUID;
typedef time_t ImapDate;
-/* ImapAddress is an anddress as seen by IMAP/RFC2822.
+/* ImapAddress is an address as seen by IMAP/RFC2822.
ImapAddress conventions:
- mailbox == NULL: begin group (See RFC2822, sec 3.4), name
contains group's name.
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index 579f655..70deeea 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -1812,49 +1812,23 @@ libbalsa_mailbox_imap_sync(LibBalsaMailbox * mailbox, gboolean expunge)
return res;
}
-static InternetAddressList
- *internet_address_new_list_from_imap_address_list(ImapAddress * list);
-
-static InternetAddress *
-internet_address_new_from_imap_address(ImapAddress ** list)
-{
- ImapAddress *addr = *list;
- InternetAddress *address;
-
- if (!addr || (addr->name==NULL && addr->addr_spec==NULL))
- return NULL;
-
- /* it will be owned by the caller */
-
- if (addr->addr_spec) {
- gchar *tmp = g_mime_utils_header_decode_text(addr->addr_spec);
- address = internet_address_mailbox_new(NULL, tmp);
- g_free(tmp);
- if (addr->name) {
- tmp = g_mime_utils_header_decode_text(addr->name);
- internet_address_set_name(address, tmp);
- g_free(tmp);
- }
- } else {
- /* Begin group */
- gchar *tmp = g_mime_utils_header_decode_text(addr->name);
- address = internet_address_group_new(tmp);
+static InternetAddress*
+imap_address_to_gmime_mailbox(ImapAddress *addr)
+{
+ gchar *tmp = g_mime_utils_header_decode_text(addr->addr_spec);
+ InternetAddress *address = internet_address_mailbox_new(NULL, tmp);
+ g_free(tmp);
+ if (addr->name) {
+ tmp = g_mime_utils_header_decode_text(addr->name);
+ internet_address_set_name(address, tmp);
g_free(tmp);
-
- internet_address_group_set_members
- (INTERNET_ADDRESS_GROUP(address),
- internet_address_new_list_from_imap_address_list(addr->next));
- /* Skip to end of group */
- while (addr && addr->addr_spec)
- addr = addr->next;
- *list = addr;
}
-
return address;
}
static InternetAddressList *
-internet_address_new_list_from_imap_address_list(ImapAddress *list)
+internet_address_new_list_from_imap_address(ImapAddress *list,
+ ImapAddress **tail)
{
InternetAddress *addr;
InternetAddressList *res;
@@ -1862,16 +1836,48 @@ internet_address_new_list_from_imap_address_list(ImapAddress *list)
if (!list)
return NULL;
- for (res = internet_address_list_new(); list; list = list->next) {
- addr = internet_address_new_from_imap_address(&list);
- if (addr) {
- internet_address_list_add(res, addr);
- g_object_unref(addr);
- }
- }
+ res = internet_address_list_new();
+ do {
+ if (list->addr_spec) {
+ addr = imap_address_to_gmime_mailbox(list);
+ } else {
+ /* Group */
+ if (list->name) {
+ /* Group head */
+ ImapAddress *tail = NULL;
+ InternetAddressList *l;
+ gchar *tmp = g_mime_utils_header_decode_text(list->name);
+ addr = internet_address_group_new(tmp);
+ g_free(tmp);
+ l = internet_address_new_list_from_imap_address(list->next,
+ &tail);
+ if (l) {
+ internet_address_group_set_members
+ (INTERNET_ADDRESS_GROUP(addr), l);
+ g_object_unref(l);
+ }
+ list = tail;
+ } else {
+ /* tail */
+ if (tail)
+ *tail = list;
+ return res;
+ }
+
+ }
+ internet_address_list_add(res, addr);
+ g_object_unref(addr);
+
+ } while (list && (list = list->next) != NULL);
return res;
}
+static InternetAddressList *
+internet_address_new_list_from_imap_address_list(ImapAddress *list)
+{
+ return internet_address_new_list_from_imap_address(list, NULL);
+}
+
static void
lb_set_headers(LibBalsaMessageHeaders *headers, ImapEnvelope * envelope,
gboolean is_embedded)
diff --git a/src/balsa-app.c b/src/balsa-app.c
index e2f97dd..cdd9b9e 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -501,8 +501,8 @@ update_timer(gboolean update, guint minutes)
*/
static void
-open_mailboxes_idle_func(const gchar * url, LibBalsaMailboxView * view,
- GString * str)
+append_url_if_open(const gchar * url, LibBalsaMailboxView * view,
+ GString * str)
{
if (view->open) {
if (str->len)
@@ -529,7 +529,7 @@ open_mailboxes_idle_cb(gchar ** urls)
str = g_string_new(NULL);
g_hash_table_foreach(libbalsa_mailbox_view_table,
- (GHFunc) open_mailboxes_idle_func, str);
+ (GHFunc) append_url_if_open, str);
urls = g_strsplit(str->str, ";", 0);
g_string_free(str, TRUE);
}
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index a4764f7..9c651ab 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -6850,7 +6850,7 @@ sendmsg_window_set_title(BalsaSendmsg * bsmsg)
to_string = internet_address_list_to_string(list, FALSE);
g_object_unref(list);
- title = g_strdup_printf(title_format, to_string,
+ title = g_strdup_printf(title_format, to_string ? to_string : "",
gtk_entry_get_text(GTK_ENTRY(bsmsg->subject[1])));
g_free(to_string);
gtk_window_set_title(GTK_WINDOW(bsmsg->window), title);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]