From 7fc4d40eb2aea4c96cb69e1ee5c23add03022ae0 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sun, 27 Sep 2009 10:40:06 -0700 Subject: [PATCH] Allow spaces in mail folder names for pop/imap. For example, you can specify "-f '[Gmail]/All Mail'" in your mail args to view all mails in your Google mail IMAP folder. --- doc/config_settings.xml | 6 +++--- doc/variables.xml | 8 ++++---- src/mail.c | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/doc/config_settings.xml b/doc/config_settings.xml index 1b71f439..3bb152a5 100644 --- a/doc/config_settings.xml +++ b/doc/config_settings.xml @@ -316,8 +316,8 @@ Default global IMAP server. Arguments are: "host - user pass [-i interval (in seconds)] [-f folder] [-p port] - [-e command] [-r retries]". Default port is 143, default + user pass [-i interval (in seconds)] [-f 'folder'] [-p port] + [-e 'command'] [-r retries]". Default port is 143, default folder is 'INBOX', default interval is 5 minutes, and default number of retries before giving up is 5. If the password is supplied as '*', you will be prompted to enter @@ -704,7 +704,7 @@ Default global POP3 server. Arguments are: "host - user pass [-i interval (in seconds)] [-p port] [-e command] + user pass [-i interval (in seconds)] [-p port] [-e 'command'] [-r retries]". Default port is 110, default interval is 5 minutes, and default number of retries before giving up is 5. If the password is supplied as '*', you will be prompted diff --git a/doc/variables.xml b/doc/variables.xml index 1eea412b..3472c787 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -1701,7 +1701,7 @@ IMAP inbox by default. You can define individual IMAP inboxes seperately by passing arguments to this object. Arguments are: "host user pass [-i interval (in seconds)] - [-f folder] [-p port] [-e command] [-r retries]". Default + [-f 'folder'] [-p port] [-e 'command'] [-r retries]". Default port is 143, default folder is 'INBOX', default interval is 5 minutes, and default number of retries before giving up is 5. If the password is supplied as '*', you will be @@ -1719,7 +1719,7 @@ global IMAP inbox by default. You can define individual IMAP inboxes seperately by passing arguments to this object. Arguments are: "host user pass [-i interval (in - seconds)] [-f folder] [-p port] [-e command] [-r retries]". + seconds)] [-f 'folder'] [-p port] [-e 'command'] [-r retries]". Default port is 143, default folder is 'INBOX', default interval is 5 minutes, and default number of retries before giving up is 5. If the password is supplied as '*', you @@ -2514,7 +2514,7 @@ global POP3 inbox by default. You can define individual POP3 inboxes seperately by passing arguments to this object. Arguments are: "host user pass [-i interval (in - seconds)] [-p port] [-e command] [-r retries]". Default + seconds)] [-p port] [-e 'command'] [-r retries]". Default port is 110, default interval is 5 minutes, and default number of retries before giving up is 5. If the password is supplied as '*', you will be prompted to enter the password @@ -2532,7 +2532,7 @@ in your global POP3 inbox by default. You can define individual POP3 inboxes seperately by passing arguments to this object. Arguments are: "host user pass [-i interval - (in seconds)] [-p port] [-e command] [-r retries]". Default + (in seconds)] [-p port] [-e 'command'] [-r retries]". Default port is 110, default interval is 5 minutes, and default number of retries before giving up is 5. If the password is supplied as '*', you will be prompted to enter the password diff --git a/src/mail.c b/src/mail.c index ec1fbc98..6504dc10 100644 --- a/src/mail.c +++ b/src/mail.c @@ -355,8 +355,15 @@ struct mail_s *parse_mail_args(char type, const char *arg) if (type == IMAP_TYPE) { tmp = strstr(arg, "-f "); if (tmp) { + int len = 1024; tmp += 3; - sscanf(tmp, "%s", mail->folder); + if (tmp[0] == '\'') { + len = strstr(tmp + 1, "'") - tmp - 1; + if (len > 1024) { + len = 1024; + } + } + strncpy(mail->folder, tmp + 1, len); } else { strncpy(mail->folder, "INBOX", 128); // default imap inbox } @@ -542,9 +549,9 @@ void *imap_thread(void *arg) break; } - strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE); + strncpy(sendbuf, "a2 STATUS \"", MAXDATASIZE); strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1); - strncat(sendbuf, " (MESSAGES UNSEEN)\r\n", + strncat(sendbuf, "\" (MESSAGES UNSEEN)\r\n", MAXDATASIZE - strlen(sendbuf) - 1); if (imap_command(sockfd, sendbuf, recvbuf, "a2 OK")) { fail++; @@ -561,9 +568,9 @@ void *imap_thread(void *arg) old_messages = mail->messages; if (has_idle) { - strncpy(sendbuf, "a4 SELECT ", MAXDATASIZE); + strncpy(sendbuf, "a4 SELECT \"", MAXDATASIZE); strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1); - strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1); + strncat(sendbuf, "\"\r\n", MAXDATASIZE - strlen(sendbuf) - 1); if (imap_command(sockfd, sendbuf, recvbuf, "a4 OK")) { fail++; break; @@ -653,9 +660,9 @@ void *imap_thread(void *arg) fail++; break; } - strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE); + strncpy(sendbuf, "a2 STATUS \"", MAXDATASIZE); strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1); - strncat(sendbuf, " (MESSAGES UNSEEN)\r\n", + strncat(sendbuf, "\" (MESSAGES UNSEEN)\r\n", MAXDATASIZE - strlen(sendbuf) - 1); if (imap_command(sockfd, sendbuf, recvbuf, "a2 OK")) { fail++;