#include <sys/wait.h>
#include <gtk/gtk.h>
+#include <log.h>
#include "etpan-thread-manager.h"
+#include "utils.h"
+
+#define DISABLE_LOG_DURING_LOGIN
static struct etpan_thread_manager * thread_manager = NULL;
static chash * courier_workaround_hash = NULL;
return TRUE;
}
+void imap_logger(int direction, const char * str, size_t size)
+{
+ gchar buf[512];
+ strncpy(buf, str, 511);
+ buf[511] = '\0';
+ if (size < 511)
+ buf[size] = '\0';
+ if (!strncmp(buf, "<<<<<<<", 7)
+ || !strncmp(buf, ">>>>>>>", 7)
+ || buf[0] == '\r' || buf[0] == '\n')
+ return;
+
+ while (strstr(buf, "\r"))
+ *strstr(buf, "\r") = ' ';
+ while (strstr(buf, "\n"))
+ *strstr(buf, "\n") = ' ';
+
+ log_print("IMAP4%c %s\n", direction?'>':'<', buf);
+}
#define ETPAN_DEFAULT_NETWORK_TIMEOUT 60
mailstream_network_delay.tv_sec = ETPAN_DEFAULT_NETWORK_TIMEOUT;
mailstream_network_delay.tv_usec = 0;
-
-#if 0
+
mailstream_debug = 1;
-#endif
+ mailstream_logger = imap_logger;
+
imap_hash = chash_new(CHASH_COPYKEY, CHASH_DEFAULTSIZE);
session_hash = chash_new(CHASH_COPYKEY, CHASH_DEFAULTSIZE);
courier_workaround_hash = chash_new(CHASH_COPYKEY, CHASH_DEFAULTSIZE);
struct login_param * param;
struct login_result * result;
int r;
+#ifdef DISABLE_LOG_DURING_LOGIN
+ int old_debug;
+#endif
param = op->param;
+
+#ifdef DISABLE_LOG_DURING_LOGIN
+ old_debug = mailstream_debug;
+ mailstream_debug = 0;
+#endif
+
r = mailimap_login(param->imap,
param->login, param->password);
+#ifdef DISABLE_LOG_DURING_LOGIN
+ mailstream_debug = old_debug;
+#endif
+
result = op->result;
result->error = r;
debug_print("imap login run - end %i\n", r);
result = op->result;
result->error = r;
debug_print("imap starttls run - end %i\n", r);
+
+ if (r == 0) {
+ mailimap *imap = param->imap;
+ mailstream_low *plain_low = NULL;
+ mailstream_low *tls_low = NULL;
+ int fd = -1;
+
+ plain_low = mailstream_get_low(imap->imap_stream);
+ fd = mailstream_low_get_fd(plain_low);
+ if (fd == -1) {
+ debug_print("imap starttls run - can't get fd\n");
+ result->error = MAIL_ERROR_STREAM;
+ return;
+ }
+ tls_low = mailstream_low_ssl_open(fd);
+ if (tls_low == NULL) {
+ debug_print("imap starttls run - can't ssl_open\n");
+ result->error = MAIL_ERROR_STREAM;
+ return;
+ }
+ mailstream_low_free(plain_low);
+ mailstream_set_low(imap->imap_stream, tls_low);
+ }
}
int imap_threaded_starttls(Folder * folder)