diff --git a/include/Mailer/account.h b/include/Mailer/account.h index 87d2430..25b7127 100644 --- a/include/Mailer/account.h +++ b/include/Mailer/account.h @@ -60,7 +60,7 @@ typedef struct _AccountPluginHelper { Account * account; int (*error)(Account * account, char const * message, int ret); - void (*status)(Account * account, char const * message); + void (*status)(Account * account, char const * format, ...); /* folders */ Folder * (*folder_new)(Account * account, AccountFolder * folder, Folder * parent, FolderType type, char const * name); diff --git a/src/account.c b/src/account.c index d82c3de..f408f5c 100644 --- a/src/account.c +++ b/src/account.c @@ -15,6 +15,7 @@ +#include #include #include #include @@ -66,7 +67,7 @@ static gboolean _account_get_iter(Account * account, GtkTreeIter * iter); /* useful */ static int _account_helper_error(Account * account, char const * message, int ret); -static void _account_helper_status(Account * account, char const * message); +static void _account_helper_status(Account * account, char const * format, ...); static Folder * _account_helper_folder_new(Account * account, AccountFolder * folder, Folder * parent, FolderType type, char const * name); @@ -411,12 +412,27 @@ static int _account_helper_error(Account * account, char const * message, /* account_helper_status */ -static void _account_helper_status(Account * account, char const * message) +static void _account_helper_status(Account * account, char const * format, ...) { -#ifdef DEBUG - fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, message); -#endif - /* FIXME implement */ + va_list ap; + int res; + size_t size; + char * p = NULL; + + va_start(ap, format); + res = vsprintf(NULL, format, ap); + va_end(ap); + if(res >= 0) + { + va_start(ap, format); + size = res; + if((p = malloc(++size)) != NULL) + vsnprintf(p, size, format, ap); + va_end(ap); + } + if(p != NULL) + mailer_set_status(account->mailer, p); + free(p); } diff --git a/src/account/imap4.c b/src/account/imap4.c index e0af17f..cfa9847 100644 --- a/src/account/imap4.c +++ b/src/account/imap4.c @@ -721,7 +721,9 @@ static gboolean _on_idle(gpointer data) static gboolean _idle_connect(AccountPlugin * plugin) { + AccountPluginHelper * helper = plugin->helper; IMAP4 * imap4 = plugin->priv; + char const * hostname; char const * p; struct hostent * he; unsigned short port; @@ -731,11 +733,11 @@ static gboolean _idle_connect(AccountPlugin * plugin) fprintf(stderr, "DEBUG: %s()\n", __func__); #endif /* FIXME report errors */ - if((p = plugin->config[2].value) == NULL) + if((hostname = plugin->config[2].value) == NULL) return FALSE; - if((he = gethostbyname(p)) == NULL) + if((he = gethostbyname(hostname)) == NULL) { - plugin->helper->error(NULL, hstrerror(h_errno), 1); + helper->error(NULL, hstrerror(h_errno), 1); return FALSE; } if((p = plugin->config[3].value) == NULL) @@ -743,19 +745,17 @@ static gboolean _idle_connect(AccountPlugin * plugin) port = (unsigned long)p; if((imap4->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - plugin->helper->error(NULL, strerror(errno), 1); + helper->error(NULL, strerror(errno), 1); return FALSE; } sa.sin_family = AF_INET; sa.sin_port = htons(port); sa.sin_addr.s_addr = *((uint32_t*)he->h_addr_list[0]); -#ifdef DEBUG - fprintf(stderr, "DEBUG: %s() connecting to %s:%u\n", __func__, + helper->status(helper->account, "Connecting to %s (%s:%u)", hostname, inet_ntoa(sa.sin_addr), port); -#endif if(connect(imap4->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0) { - plugin->helper->error(NULL, strerror(errno), 1); + helper->error(NULL, strerror(errno), 1); close(imap4->fd); imap4->fd = -1; return FALSE; diff --git a/src/account/pop3.c b/src/account/pop3.c index 39b603a..bbfc640 100644 --- a/src/account/pop3.c +++ b/src/account/pop3.c @@ -536,7 +536,9 @@ static gboolean _on_idle(gpointer data) static gboolean _idle_connect(AccountPlugin * plugin) { + AccountPluginHelper * helper = plugin->helper; POP3 * pop3 = plugin->priv; + char const * hostname; char const * p; struct hostent * he; unsigned short port; @@ -546,11 +548,11 @@ static gboolean _idle_connect(AccountPlugin * plugin) fprintf(stderr, "DEBUG: %s()\n", __func__); #endif /* FIXME report errors */ - if((p = plugin->config[2].value) == NULL) + if((hostname = plugin->config[2].value) == NULL) return FALSE; - if((he = gethostbyname(p)) == NULL) + if((he = gethostbyname(hostname)) == NULL) { - plugin->helper->error(NULL, hstrerror(h_errno), 1); + helper->error(NULL, hstrerror(h_errno), 1); return FALSE; } if((p = plugin->config[3].value) == NULL) @@ -558,19 +560,17 @@ static gboolean _idle_connect(AccountPlugin * plugin) port = (unsigned long)p; if((pop3->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - plugin->helper->error(NULL, strerror(errno), 1); + helper->error(NULL, strerror(errno), 1); return FALSE; } sa.sin_family = AF_INET; sa.sin_port = htons(port); sa.sin_addr.s_addr = *((uint32_t*)he->h_addr_list[0]); -#ifdef DEBUG - fprintf(stderr, "DEBUG: %s() connecting to %s:%u\n", __func__, + helper->status(helper->account, "Connecting to %s (%s:%u)", hostname, inet_ntoa(sa.sin_addr), port); -#endif if(connect(pop3->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0) { - plugin->helper->error(NULL, strerror(errno), 1); + helper->error(NULL, strerror(errno), 1); close(pop3->fd); pop3->fd = -1; return FALSE;