#include <imap.h>
#include <sys/types.h>
#include <sys/stat.h>
+#if defined (__NetBSD__)
+#include <sys/socket.h>
+#endif
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <gtk/gtk.h>
+#include <log.h>
#include "etpan-thread-manager.h"
#include "utils.h"
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 (debug_get_mode())
- mailstream_debug = 1;
-
+ mailstream_debug = 1;
+ 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);
#ifdef DISABLE_LOG_DURING_LOGIN
old_debug = mailstream_debug;
+ mailstream_debug = 0;
#endif
r = mailimap_login(param->imap,
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 = MAILIMAP_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 = MAILIMAP_ERROR_STREAM;
+ return;
+ }
+ mailstream_low_free(plain_low);
+ mailstream_set_low(imap->imap_stream, tls_low);
+ }
}
int imap_threaded_starttls(Folder * folder)
}
+#define ENV_BUFFER_SIZE 512
static void do_exec_command(int fd, const char * command,
const char * servername, uint16_t port)
{
int i, maxopen;
-
+#ifdef SOLARIS
+ char env_buffer[ENV_BUFFER_SIZE];
+#endif
+
if (fork() > 0) {
/* Fork again to become a child of init rather than
the etpan client. */
exit(0);
}
+#ifdef SOLARIS
+ if (servername)
+ snprintf(env_buffer, ENV_BUFFER_SIZE,
+ "ETPANSERVER=%s", servername);
+ else
+ snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANSERVER=");
+ putenv(env_buffer);
+#else
if (servername)
setenv("ETPANSERVER", servername, 1);
else
unsetenv("ETPANSERVER");
+#endif
+#ifdef SOLARIS
+ if (port)
+ snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANPORT=%d", port);
+ else
+ snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANPORT=");
+ putenv(env_buffer);
+#else
if (port) {
char porttext[20];
-
+
snprintf(porttext, sizeof(porttext), "%d", port);
setenv("ETPANPORT", porttext, 1);
}
else {
unsetenv("ETPANPORT");
}
-
+#endif
+
/* Not a lot we can do if there's an error other than bail. */
if (dup2(fd, 0) == -1)
exit(1);