[Goodies-commits] r3901 - in xfce4-mailwatch-plugin/trunk: . libmailwatch-core
Brian Tarricone
kelnos at xfce.org
Thu Jan 31 12:40:13 CET 2008
Author: kelnos
Date: 2008-01-31 11:40:13 +0000 (Thu, 31 Jan 2008)
New Revision: 3901
Removed:
xfce4-mailwatch-plugin/trunk/INSTALL
Modified:
xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-imap.c
xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-pop3.c
Log:
clean up some code, fix banner not getting completely read on connect sometimes
Deleted: xfce4-mailwatch-plugin/trunk/INSTALL
Modified: xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-imap.c
===================================================================
--- xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-imap.c 2008-01-31 11:40:03 UTC (rev 3900)
+++ xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-imap.c 2008-01-31 11:40:13 UTC (rev 3901)
@@ -473,14 +473,34 @@
return TRUE;
}
+static inline gboolean
+imap_slurp_banner(XfceMailwatchIMAPMailbox *imailbox)
+{
+ gchar buf[2048];
+ gint bin;
+
+ do {
+ bin = imap_recv(imailbox, buf, sizeof(buf)-1);
+ if(bin < 0) {
+ DBG("failed to get banner");
+ shutdown(imailbox->sockfd, SHUT_RDWR);
+ close(imailbox->sockfd);
+ imailbox->sockfd = -1;
+ } else {
+ buf[bin] = 0;
+ DBG("got banner, discarding: %s\n", buf);
+ }
+ } while(bin != -1 && !strchr(buf, '\n'));
+
+ return (bin != -1);
+}
+
static gboolean
imap_authenticate(XfceMailwatchIMAPMailbox *imailbox, const gchar *host,
const gchar *username, const gchar *password,
XfceMailwatchAuthType auth_type, gint nonstandard_port)
{
-#define BUFSIZE 2047
gboolean ret = FALSE;
- gchar buf[BUFSIZE+1];
TRACE("entering, auth_type is %d", auth_type);
@@ -488,34 +508,20 @@
case AUTH_NONE:
imailbox->security_info.using_tls = FALSE;
ret = imap_connect(imailbox, host, "imap", nonstandard_port);
-
- /* discard opening banner */
- if(ret && imap_recv(imailbox, buf, BUFSIZE) < 0) {
- DBG("failed to get banner");
- shutdown(imailbox->sockfd, SHUT_RDWR);
- close(imailbox->sockfd);
- imailbox->sockfd = -1;
- }
+ if(ret)
+ ret = imap_slurp_banner(imailbox);
break;
case AUTH_STARTTLS:
imailbox->security_info.using_tls = FALSE;
ret = imap_connect(imailbox, host, "imap", nonstandard_port);
-
- if(ret) {
- /* discard opening banner */
- if(imap_recv(imailbox, buf, BUFSIZE) < 0) {
- DBG("failed to get banner");
- shutdown(imailbox->sockfd, SHUT_RDWR);
- close(imailbox->sockfd);
- imailbox->sockfd = -1;
- }
-
+ if(ret)
+ ret = imap_slurp_banner(imailbox);
+ if(ret)
ret = imap_do_starttls(imailbox, host, username, password);
- if(ret)
- ret = imap_negotiate_ssl(imailbox, host);
- imailbox->security_info.using_tls = TRUE;
- }
+ if(ret)
+ ret = imap_negotiate_ssl(imailbox, host);
+ imailbox->security_info.using_tls = TRUE;
break;
case AUTH_SSL_PORT:
@@ -523,14 +529,8 @@
ret = imap_connect(imailbox, host, "imaps", nonstandard_port);
if(ret)
ret = imap_negotiate_ssl(imailbox, host);
-
- /* discard opening banner */
- if(ret && imap_recv(imailbox, buf, BUFSIZE) < 0) {
- DBG("failed to get banner");
- shutdown(imailbox->sockfd, SHUT_RDWR);
- close(imailbox->sockfd);
- imailbox->sockfd = -1;
- }
+ if(ret)
+ ret = imap_slurp_banner(imailbox);
break;
default:
@@ -540,11 +540,10 @@
DBG("using_tls is %s", imailbox->security_info.using_tls?"TRUE":"FALSE");
- if(ret && !imap_send_login_info(imailbox, username, password))
- return FALSE;
+ if(ret)
+ ret = imap_send_login_info(imailbox, username, password);
return ret;
-#undef BUFSIZE
}
static guint
Modified: xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-pop3.c
===================================================================
--- xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-pop3.c 2008-01-31 11:40:03 UTC (rev 3900)
+++ xfce4-mailwatch-plugin/trunk/libmailwatch-core/mailwatch-mailbox-pop3.c 2008-01-31 11:40:13 UTC (rev 3901)
@@ -432,13 +432,34 @@
return TRUE;
}
+static inline gboolean
+pop3_slurp_banner(XfceMailwatchPOP3Mailbox *pmailbox)
+{
+ gchar buf[2048];
+ gint bin;
+
+ do {
+ bin = pop3_recv(pmailbox, buf, sizeof(buf)-1);
+ if(bin < 0) {
+ DBG("failed to get banner");
+ shutdown(pmailbox->sockfd, SHUT_RDWR);
+ close(pmailbox->sockfd);
+ pmailbox->sockfd = -1;
+ } else {
+ buf[bin] = 0;
+ DBG("got banner, discarding: %s\n", buf);
+ }
+ } while(bin != -1 && !strchr(buf, '\n'));
+
+ return (bin != -1);
+}
+
static gboolean
pop3_authenticate(XfceMailwatchPOP3Mailbox *pmailbox, const gchar *host,
const gchar *username, const gchar *password,
XfceMailwatchAuthType auth_type, gint nonstandard_port)
{
gboolean ret = FALSE;
- gchar buf[1024];
TRACE("entering, auth_type is %d", auth_type);
@@ -446,34 +467,20 @@
case AUTH_NONE:
pmailbox->security_info.using_tls = FALSE;
ret = pop3_connect(pmailbox, host, "pop3", nonstandard_port);
-
- /* discard opening banner */
- if(ret && pop3_recv(pmailbox, buf, 1023) < 0) {
- DBG("failed to get banner");
- shutdown(pmailbox->sockfd, SHUT_RDWR);
- close(pmailbox->sockfd);
- pmailbox->sockfd = -1;
- }
+ if(ret)
+ ret = pop3_slurp_banner(pmailbox);
break;
case AUTH_STARTTLS:
pmailbox->security_info.using_tls = FALSE;
ret = pop3_connect(pmailbox, host, "pop3", nonstandard_port);
-
- if(ret) {
- /* discard opening banner */
- if(pop3_recv(pmailbox, buf, 1023) < 0) {
- DBG("failed to get banner");
- shutdown(pmailbox->sockfd, SHUT_RDWR);
- close(pmailbox->sockfd);
- pmailbox->sockfd = -1;
- }
-
+ if(ret)
+ ret = pop3_slurp_banner(pmailbox);
+ if(ret)
ret = pop3_do_stls(pmailbox, host, username, password);
- if(ret)
- ret = pop3_negotiate_ssl(pmailbox, host);
- pmailbox->security_info.using_tls = TRUE;
- }
+ if(ret)
+ ret = pop3_negotiate_ssl(pmailbox, host);
+ pmailbox->security_info.using_tls = TRUE;
break;
case AUTH_SSL_PORT:
@@ -481,14 +488,8 @@
ret = pop3_connect(pmailbox, host, "pop3s", nonstandard_port);
if(ret)
ret = pop3_negotiate_ssl(pmailbox, host);
-
- /* discard opening banner */
- if(ret && pop3_recv(pmailbox, buf, 1023) < 0) {
- DBG("failed to get banner");
- shutdown(pmailbox->sockfd, SHUT_RDWR);
- close(pmailbox->sockfd);
- pmailbox->sockfd = -1;
- }
+ if(ret)
+ ret = pop3_slurp_banner(pmailbox);
break;
default:
More information about the Goodies-commits
mailing list