sync with sylpheed 0.5.0pre2 release
authorPaul Mangan <paul@claws-mail.org>
Mon, 25 Jun 2001 07:48:30 +0000 (07:48 +0000)
committerPaul Mangan <paul@claws-mail.org>
Mon, 25 Jun 2001 07:48:30 +0000 (07:48 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
src/imap.c
src/main.c
src/utils.c
src/utils.h

index 7e38299..63f892d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2001-06-25
+
+       * src/imap.c: imap_create_tree(): pass the path that is separated
+         by the local filesystem separator to imap_create_folder().
+         imap_create_folder(): examine the existence of folders using
+         LIST command instead of STATUS.
+         imap_cmd_list(): new.
+         imap_query_password(): new.
+         imap_session_new(): query password if it is not set.
+
+2001-06-24
+
+       * src/imap.c: imap_parse_envelope(): FETCH results can be parsed
+         with arbitrary order.
+         imap_parse_fetch_element(): new. it parses one pair of name and
+         value of FETCH results.
+         imap_parse_flags(): modified for more flexibility.
+       * src/utils.[ch]: set_log_file(): new. it opens a new file for
+         logging.
+         close_log_file(): new. it closes the opened log file.
+         log_print(), log_message(), log_warning(), log_error(): also
+         output to log file.
+
 2001-06-22
 
        * src/imap.c: imap_cmd_status(): check the pointer to "value"
 2001-06-22
 
        * src/imap.c: imap_cmd_status(): check the pointer to "value"
index 153433f..f66b08e 100644 (file)
@@ -1,3 +1,7 @@
+2001-06-25 [paul]
+
+        * sync with sylpheed 0.5.0pre2 release
+
 2001-06-24 [christoph]
 
        * src/prefs_common.c
 2001-06-24 [christoph]
 
        * src/prefs_common.c
index 622c2f4..1f97d9a 100644 (file)
@@ -1,3 +1,27 @@
+2001-06-25
+
+       * src/imap.c: imap_create_tree(): imap_create_folder() ¤Ë¥í¡¼¥«¥ë
+         ¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Î¥»¥Ñ¥ì¡¼¥¿¤Ç¶èÀÚ¤é¤ì¤Æ¤¤¤ë¥Ñ¥¹¤òÅϤ¹¤è¤¦¤Ë¤·¤¿¡£
+         imap_create_folder(): STATUS ¥³¥Þ¥ó¥É¤ÎÂå¤ï¤ê¤Ë LIST ¤ò»È¤Ã¤Æ
+         ¥Õ¥©¥ë¥À¤Î¸ºß¤òÄ´¤Ù¤ë¤è¤¦¤Ë¤·¤¿¡£
+         imap_cmd_list(): ¿·µ¬¡£
+         imap_query_password(): ¿·µ¬¡£
+         imap_session_new(): ¥Ñ¥¹¥ï¡¼¥É¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¿Ò¤Í¤ë¤è¤¦¤Ë
+         ¤·¤¿¡£
+
+2001-06-24
+
+       * src/imap.c: imap_parse_envelope(): FETCH ¤Î·ë²Ì¤òǤ°Õ¤Î½ç½ø¤Ç
+         ²òÀϤǤ­¤ë¤è¤¦¤Ë¤·¤¿¡£
+         imap_parse_fetch_element(): ¿·µ¬¡£ FETCH ¤Î·ë²Ì¤Î̾Á°¤ÈÃͤΥڥ¢
+         ¤ò²òÀϤ¹¤ë¡£
+         imap_parse_flags(): ¤è¤ê½ÀÆðÀ­¤ò»ý¤¿¤»¤ë¤¿¤á¤Ë½¤Àµ¡£
+       * src/utils.[ch]: set_log_file(): ¿·µ¬¡£¥í¥®¥ó¥°¤Î¤¿¤á¤Ë¿·¤·¤¤
+         ¥Õ¥¡¥¤¥ë¤ò³«¤¯¡£
+         close_log_file(): ¿·µ¬¡£³«¤¤¤¿¥í¥°¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë¡£
+         log_print(), log_message(), log_warning(), log_error(): ¥í¥°
+         ¥Õ¥¡¥¤¥ë¤Ë¤â½ÐÎϤ¹¤ë¤è¤¦¤Ë¤·¤¿¡£
+
 2001-06-22
 
        * src/imap.c: imap_cmd_status(): ÂåÆþ¤ÎÁ°¤Ë "value" ¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò
 2001-06-22
 
        * src/imap.c: imap_cmd_status(): ÂåÆþ¤ÎÁ°¤Ë "value" ¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò
index fd61bb4..17bc19b 100644 (file)
 #include "prefs_account.h"
 #include "codeconv.h"
 #include "utils.h"
 #include "prefs_account.h"
 #include "codeconv.h"
 #include "utils.h"
+#include "inputdialog.h"
 
 #define IMAP4_PORT     143
 
 
 #define IMAP4_PORT     143
 
+typedef struct _FetchElement   FetchElement;
+
+struct _FetchElement
+{
+       gchar *name;
+       gchar *value;
+};
+
 static GList *session_list = NULL;
 
 static gint imap_cmd_count = 0;
 
 static IMAPSession *imap_session_get   (Folder         *folder);
 static GList *session_list = NULL;
 
 static gint imap_cmd_count = 0;
 
 static IMAPSession *imap_session_get   (Folder         *folder);
+static gchar *imap_query_password      (const gchar    *server,
+                                        const gchar    *user);
 
 static gint imap_do_copy               (Folder         *folder,
                                         FolderItem     *dest,
 
 static gint imap_do_copy               (Folder         *folder,
                                         FolderItem     *dest,
@@ -114,6 +125,8 @@ static gchar *imap_parse_address    (SockInfo       *sock,
                                         gchar         **out_fromname_str,
                                         gchar          *orig_buf);
 static MsgFlags imap_parse_flags       (const gchar    *flag_str);
                                         gchar         **out_fromname_str,
                                         gchar          *orig_buf);
 static MsgFlags imap_parse_flags       (const gchar    *flag_str);
+static gchar *imap_parse_fetch_element (const gchar    *str,
+                                        FetchElement   *element);
 static MsgInfo *imap_parse_envelope    (SockInfo       *sock,
                                         gchar          *line_str);
 
 static MsgInfo *imap_parse_envelope    (SockInfo       *sock,
                                         gchar          *line_str);
 
@@ -125,16 +138,22 @@ static gint imap_cmd_logout       (SockInfo       *sock);
 static gint imap_cmd_noop      (SockInfo       *sock);
 static gint imap_cmd_namespace (SockInfo       *sock,
                                 gchar         **ns_str);
 static gint imap_cmd_noop      (SockInfo       *sock);
 static gint imap_cmd_namespace (SockInfo       *sock,
                                 gchar         **ns_str);
+static gint imap_cmd_list      (SockInfo       *sock,
+                                const gchar    *ref,
+                                const gchar    *mailbox,
+                                GPtrArray      *argbuf);
 static gint imap_cmd_select    (SockInfo       *sock,
                                 const gchar    *folder,
                                 gint           *exists,
                                 gint           *recent,
                                 gint           *unseen,
                                 guint32        *uid_validity);
 static gint imap_cmd_select    (SockInfo       *sock,
                                 const gchar    *folder,
                                 gint           *exists,
                                 gint           *recent,
                                 gint           *unseen,
                                 guint32        *uid_validity);
+#if 0
 static gint imap_cmd_status    (SockInfo       *sock,
                                 const gchar    *folder,
                                 const gchar    *status,
                                 gint           *value);
 static gint imap_cmd_status    (SockInfo       *sock,
                                 const gchar    *folder,
                                 const gchar    *status,
                                 gint           *value);
+#endif
 static gint imap_cmd_create    (SockInfo       *sock,
                                 const gchar    *folder);
 static gint imap_cmd_delete    (SockInfo       *sock,
 static gint imap_cmd_create    (SockInfo       *sock,
                                 const gchar    *folder);
 static gint imap_cmd_delete    (SockInfo       *sock,
@@ -218,6 +237,19 @@ static IMAPSession *imap_session_get(Folder *folder)
        return IMAP_SESSION(rfolder->session);
 }
 
        return IMAP_SESSION(rfolder->session);
 }
 
+static gchar *imap_query_password(const gchar *server, const gchar *user)
+{
+       gchar *message;
+       gchar *pass;
+
+       message = g_strdup_printf(_("Input password for %s on %s:"),
+                                 user, server);
+       pass = input_dialog_with_invisible(_("Input password"), message, NULL);
+       g_free(message);
+
+       return pass;
+}
+
 Session *imap_session_new(const gchar *server, gushort port,
                          const gchar *user, const gchar *pass)
 {
 Session *imap_session_new(const gchar *server, gushort port,
                          const gchar *user, const gchar *pass)
 {
@@ -226,6 +258,16 @@ Session *imap_session_new(const gchar *server, gushort port,
        SockInfo *imap_sock;
 
        g_return_val_if_fail(server != NULL, NULL);
        SockInfo *imap_sock;
 
        g_return_val_if_fail(server != NULL, NULL);
+       g_return_val_if_fail(user != NULL, NULL);
+
+       if (!pass) {
+               gchar *tmp_pass;
+               tmp_pass = imap_query_password(server, user);
+               if (!tmp_pass)
+                       return NULL;
+               Xstrdup_a(pass, tmp_pass, {g_free(tmp_pass); return NULL;});
+               g_free(tmp_pass);
+       }
 
        log_message(_("creating IMAP4 connection to %s:%d ...\n"),
                    server, port);
 
        log_message(_("creating IMAP4 connection to %s:%d ...\n"),
                    server, port);
@@ -678,9 +720,10 @@ gint imap_create_tree(Folder *folder)
 
                        Xstrdup_a(name, namespace->name, return -1);
                        strtailchomp(name, namespace->separator);
 
                        Xstrdup_a(name, namespace->name, return -1);
                        strtailchomp(name, namespace->separator);
-                       trash_path = g_strdup_printf
-                               ("%s%c%s",
-                                name, namespace->separator, "trash");
+                       subst_char(name, namespace->separator,
+                                  G_DIR_SEPARATOR);
+                       trash_path = g_strconcat(name, G_DIR_SEPARATOR_S,
+                                                "trash", NULL);
                }
        } else
                trash_path = g_strdup("trash");
                }
        } else
                trash_path = g_strdup("trash");
@@ -735,9 +778,32 @@ FolderItem *imap_create_folder(Folder *folder, FolderItem *parent,
        }
 
        if (strcmp(name, "INBOX") != 0) {
        }
 
        if (strcmp(name, "INBOX") != 0) {
-               ok = imap_cmd_status(SESSION(session)->sock, imappath,
-                                    "MESSAGES", NULL);
+               GPtrArray *argbuf;
+               gint i;
+               gboolean exist = FALSE;
+
+               argbuf = g_ptr_array_new();
+               ok = imap_cmd_list(SESSION(session)->sock, NULL, imappath,
+                                  argbuf);
+               statusbar_pop_all();
                if (ok != IMAP_SUCCESS) {
                if (ok != IMAP_SUCCESS) {
+                       log_warning(_("can't create mailbox: LIST failed\n"));
+                       g_free(dirpath);
+                       g_ptr_array_free(argbuf, TRUE);
+                       return NULL;
+               }
+
+               for (i = 0; i < argbuf->len; i++) {
+                       gchar *str;
+                       str = g_ptr_array_index(argbuf, i);
+                       if (!strncmp(str, "LIST ", 5)) {
+                               exist = TRUE;
+                               break;
+                       }
+               }
+               g_ptr_array_free(argbuf, TRUE);
+
+               if (!exist) {
                        ok = imap_cmd_create(SESSION(session)->sock, imappath);
                        statusbar_pop_all();
                        if (ok != IMAP_SUCCESS) {
                        ok = imap_cmd_create(SESSION(session)->sock, imappath);
                        statusbar_pop_all();
                        if (ok != IMAP_SUCCESS) {
@@ -746,7 +812,6 @@ FolderItem *imap_create_folder(Folder *folder, FolderItem *parent,
                                return NULL;
                        }
                }
                                return NULL;
                        }
                }
-               statusbar_pop_all();
        }
 
        new_item = folder_item_new(new_name, dirpath);
        }
 
        new_item = folder_item_new(new_name, dirpath);
@@ -814,6 +879,7 @@ static GSList *imap_get_uncached_messages(IMAPSession *session,
                        return newlist;
                }
                strretchomp(buf);
                        return newlist;
                }
                strretchomp(buf);
+               log_print("IMAP4< %s\n", buf);
                if (buf[0] != '*' || buf[1] != ' ') break;
 
                msginfo = imap_parse_envelope(SESSION(session)->sock, buf);
                if (buf[0] != '*' || buf[1] != ' ') break;
 
                msginfo = imap_parse_envelope(SESSION(session)->sock, buf);
@@ -1124,30 +1190,22 @@ static gchar *imap_parse_address(SockInfo *sock, gchar *start,
 
 static MsgFlags imap_parse_flags(const gchar *flag_str)  
 {
 
 static MsgFlags imap_parse_flags(const gchar *flag_str)  
 {
-       gchar buf[32];
-       const gchar *cur_pos = flag_str;
-       const gchar *last_pos;
+       const gchar *p = flag_str;
        MsgFlags flags;
 
        flags = 0;
        MSG_SET_FLAGS(flags, MSG_UNREAD|MSG_IMAP);
 
        MsgFlags flags;
 
        flags = 0;
        MSG_SET_FLAGS(flags, MSG_UNREAD|MSG_IMAP);
 
-       while (cur_pos != NULL) {
-               cur_pos = strchr(cur_pos, '\\');
-               if (cur_pos == NULL) break;
-
-               last_pos = cur_pos + 1;
-               cur_pos = strchr_cpy(last_pos, ' ', buf, sizeof(buf));
-               if (cur_pos == NULL)
-                       strncpy2(buf, last_pos, sizeof(buf));
+       while ((p = strchr(p, '\\')) != NULL) {
+               p++;
 
 
-               if (g_strcasecmp(buf, "Recent") == 0) {
+               if (g_strncasecmp(p, "Recent", 6) == 0) {
                        MSG_SET_FLAGS(flags, MSG_NEW|MSG_UNREAD);
                        MSG_SET_FLAGS(flags, MSG_NEW|MSG_UNREAD);
-               } else if (g_strcasecmp(buf, "Seen") == 0) {
+               } else if (g_strncasecmp(p, "Seen", 4) == 0) {
                        MSG_UNSET_FLAGS(flags, MSG_NEW|MSG_UNREAD);
                        MSG_UNSET_FLAGS(flags, MSG_NEW|MSG_UNREAD);
-               } else if (g_strcasecmp(buf, "Deleted") == 0) {
+               } else if (g_strncasecmp(p, "Deleted", 7) == 0) {
                        MSG_SET_FLAGS(flags, MSG_DELETED);
                        MSG_SET_FLAGS(flags, MSG_DELETED);
-               } else if (g_strcasecmp(buf, "Flagged") == 0) {
+               } else if (g_strncasecmp(p, "Flagged", 7) == 0) {
                        MSG_SET_FLAGS(flags, MSG_MARKED);
                }
        }
                        MSG_SET_FLAGS(flags, MSG_MARKED);
                }
        }
@@ -1155,6 +1213,50 @@ static MsgFlags imap_parse_flags(const gchar *flag_str)
        return flags;
 }
 
        return flags;
 }
 
+static gchar *imap_parse_fetch_element(const gchar *str, FetchElement *element)
+{
+       const gchar *name;
+       const gchar *name_end;
+       const gchar *value;
+       const gchar *value_end;
+       gint in_brace = 0;
+       gboolean in_quote = FALSE;
+
+       name = str;
+       while (*name == ' ') name++;
+       name_end = name;
+       while (*name_end != '\0' && *name_end != ' ' && *name_end != ')')
+               name_end++;
+       g_return_val_if_fail(name != name_end, NULL);
+       g_return_val_if_fail(*name_end != '\0', NULL);
+       g_return_val_if_fail(*name_end != ')', NULL);
+
+       value = name_end;
+       while (*value == ' ') value++;
+       value_end = value;
+       while (*value_end != '\0') {
+               if (*value_end == ' ' && in_brace == 0)
+                       break;
+               else if (*value_end == '(' && !in_quote)
+                       in_brace++;
+               else if (*value_end == ')' && !in_quote) {
+                       if (in_brace > 0)
+                               in_brace--;
+                       else
+                               break;
+               } else if (*value_end == '"')
+                       in_quote ^= TRUE;
+
+               value_end++;
+       }
+       g_return_val_if_fail(value != value_end, NULL);
+
+       element->name = g_strndup(name, name_end - name);
+       element->value = g_strndup(value, value_end - value);
+
+       return (gchar *)value_end;
+}
+
 static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
 {
        MsgInfo *msginfo;
 static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
 {
        MsgInfo *msginfo;
@@ -1162,10 +1264,10 @@ static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
        gchar tmp[IMAPBUFSIZE];
        gchar *cur_pos;
        gint msgnum;
        gchar tmp[IMAPBUFSIZE];
        gchar *cur_pos;
        gint msgnum;
-       guint32 uid;
-       size_t size;
+       guint32 uid = 0;
+       size_t size = 0;
        gchar *date = NULL;
        gchar *date = NULL;
-       time_t date_t;
+       time_t date_t = 0;
        gchar *subject = NULL;
        gchar *tmp_from;
        gchar *tmp_fromname;
        gchar *subject = NULL;
        gchar *tmp_from;
        gchar *tmp_fromname;
@@ -1175,9 +1277,9 @@ static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
        gchar *to = NULL;
        gchar *inreplyto = NULL;
        gchar *msgid = NULL;
        gchar *to = NULL;
        gchar *inreplyto = NULL;
        gchar *msgid = NULL;
-       MsgFlags flags;
-
-       log_print("IMAP4< %s\n", line_str);
+       MsgFlags flags = 0;
+       gint n_element = 0;
+       FetchElement element = {NULL, NULL};
 
        g_return_val_if_fail(line_str != NULL, NULL);
        g_return_val_if_fail(line_str[0] == '*' && line_str[1] == ' ', NULL);
 
        g_return_val_if_fail(line_str != NULL, NULL);
        g_return_val_if_fail(line_str[0] == '*' && line_str[1] == ' ', NULL);
@@ -1199,86 +1301,101 @@ static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
        g_return_val_if_fail(*cur_pos == '(', NULL);
        cur_pos++;
 
        g_return_val_if_fail(*cur_pos == '(', NULL);
        cur_pos++;
 
-       PARSE_ONE_ELEMENT(' ');
-       g_return_val_if_fail(!strcmp(buf, "UID"), NULL);
-       PARSE_ONE_ELEMENT(' ');
-       uid = strtoul(buf, NULL, 10);
-
-       PARSE_ONE_ELEMENT(' ');
-       g_return_val_if_fail(!strcmp(buf, "FLAGS"), NULL);
-       PARSE_ONE_ELEMENT(')');
-       g_return_val_if_fail(*buf == '(', NULL);
-       flags = imap_parse_flags(buf + 1);
-
-       g_return_val_if_fail(*cur_pos == ' ', NULL);
-       cur_pos++;
-
-       PARSE_ONE_ELEMENT(' ');
-       g_return_val_if_fail(!strcmp(buf, "RFC822.SIZE"), NULL);
-       PARSE_ONE_ELEMENT(' ');
-       size = atoi(buf);
-
-       PARSE_ONE_ELEMENT(' ');
-       g_return_val_if_fail(!strcmp(buf, "ENVELOPE"), NULL);
-
-       g_return_val_if_fail(*cur_pos == '(', NULL);
-       cur_pos = imap_parse_atom(sock, cur_pos + 1, buf, line_str);
-       Xstrdup_a(date, buf, return NULL);
-       date_t = procheader_date_parse(NULL, date, 0);
-
-       cur_pos = imap_parse_atom(sock, cur_pos, buf, line_str);
-       if (buf[0] != '\0') {
-               conv_unmime_header(tmp, sizeof(tmp), buf, NULL);
-               Xstrdup_a(subject, tmp, return NULL);
-       }
+       while (n_element < 4) {
+               cur_pos = imap_parse_fetch_element(cur_pos, &element);
+               g_return_val_if_fail(cur_pos != NULL, NULL);
+
+               if (!strcmp(element.name, "UID")) {
+                       uid = strtoul(element.value, NULL, 10);
+               } else if (!strcmp(element.name, "FLAGS")) {
+                       flags = imap_parse_flags(element.value);
+               } else if (!strcmp(element.name, "RFC822.SIZE")) {
+                       size = atoi(element.value);
+               } else if (!strcmp(element.name, "ENVELOPE")) {
+                       gchar *p;
+
+                       Xstrdup_a(p, element.value,
+                                 {g_free(element.name); g_free(element.value);
+                                  return NULL;});
+                       g_free(element.name);
+                       g_free(element.value);
+                       element.name = element.value = NULL;
+
+                       g_return_val_if_fail(*p == '(', NULL);
+                       p = imap_parse_atom(sock, p + 1, buf, NULL);
+                       Xstrdup_a(date, buf, return NULL);
+                       date_t = procheader_date_parse(NULL, date, 0);
+
+                       p = imap_parse_atom(sock, p, buf, NULL);
+                       if (buf[0] != '\0') {
+                               conv_unmime_header(tmp, sizeof(tmp), buf, NULL);
+                               Xstrdup_a(subject, tmp, return NULL);
+                       }
 
 
-       g_return_val_if_fail(*cur_pos == ' ', NULL);
-       cur_pos = imap_parse_address(sock, cur_pos + 1,
-                                    &tmp_from, &tmp_fromname, line_str);
-       Xstrdup_a(from, tmp_from,
-                 {g_free(tmp_from); g_free(tmp_fromname); return NULL;});
-       Xstrdup_a(fromname, tmp_fromname,
-                 {g_free(tmp_from); g_free(tmp_fromname); return NULL;});
-       g_free(tmp_from);
-       g_free(tmp_fromname);
+                       g_return_val_if_fail(*p == ' ', NULL);
+                       p = imap_parse_address(sock, p + 1,
+                                              &tmp_from, &tmp_fromname,
+                                              line_str);
+                       Xstrdup_a(from, tmp_from,
+                                 {g_free(tmp_from); g_free(tmp_fromname);
+                                  return NULL;});
+                       Xstrdup_a(fromname, tmp_fromname,
+                                 {g_free(tmp_from); g_free(tmp_fromname);
+                                  return NULL;});
+                       g_free(tmp_from);
+                       g_free(tmp_fromname);
 
 #define SKIP_ONE_ELEMENT() \
 { \
 
 #define SKIP_ONE_ELEMENT() \
 { \
-       g_return_val_if_fail(*cur_pos == ' ', NULL); \
-       cur_pos = imap_parse_address(sock, cur_pos + 1, \
-                                    NULL, NULL, line_str); \
+       g_return_val_if_fail(*p == ' ', NULL); \
+       p = imap_parse_address(sock, p + 1, NULL, NULL, NULL); \
 }
 
 }
 
-       /* skip sender and reply-to */
-       SKIP_ONE_ELEMENT();
-       SKIP_ONE_ELEMENT();
+                       /* skip sender and reply-to */
+                       SKIP_ONE_ELEMENT();
+                       SKIP_ONE_ELEMENT();
 
 
-       g_return_val_if_fail(*cur_pos == ' ', NULL);
-       cur_pos = imap_parse_address(sock, cur_pos + 1, &tmp_to, NULL, line_str);
-       Xstrdup_a(to, tmp_to, {g_free(tmp_to); return NULL;});
-       g_free(tmp_to);
+                       g_return_val_if_fail(*p == ' ', NULL);
+                       p = imap_parse_address(sock, p + 1, &tmp_to, NULL,
+                                              NULL);
+                       Xstrdup_a(to, tmp_to, {g_free(tmp_to); return NULL;});
+                       g_free(tmp_to);
 
 
-       /* skip Cc and Bcc */
-       SKIP_ONE_ELEMENT();
-       SKIP_ONE_ELEMENT();
+                       /* skip Cc and Bcc */
+                       SKIP_ONE_ELEMENT();
+                       SKIP_ONE_ELEMENT();
 
 #undef SKIP_ONE_ELEMENT
 
 
 #undef SKIP_ONE_ELEMENT
 
-       g_return_val_if_fail(*cur_pos == ' ', NULL);
-       cur_pos = imap_parse_atom(sock, cur_pos, buf, line_str);
-       if (buf[0] != '\0') {
-               eliminate_parenthesis(buf, '(', ')');
-               extract_parenthesis(buf, '<', '>');
-               remove_space(buf);
-               Xstrdup_a(inreplyto, buf, return NULL);
-       }
+                       g_return_val_if_fail(*p == ' ', NULL);
+                       p = imap_parse_atom(sock, p, buf, NULL);
+                       if (buf[0] != '\0') {
+                               eliminate_parenthesis(buf, '(', ')');
+                               extract_parenthesis(buf, '<', '>');
+                               remove_space(buf);
+                               Xstrdup_a(inreplyto, buf, return NULL);
+                       }
+
+                       g_return_val_if_fail(*p == ' ', NULL);
+                       p = imap_parse_atom(sock, p, buf, NULL);
+                       if (buf[0] != '\0') {
+                               extract_parenthesis(buf, '<', '>');
+                               remove_space(buf);
+                               Xstrdup_a(msgid, buf, return NULL);
+                       }
 
 
-       g_return_val_if_fail(*cur_pos == ' ', NULL);
-       cur_pos = imap_parse_atom(sock, cur_pos, buf, line_str);
-       if (buf[0] != '\0') {
-               extract_parenthesis(buf, '<', '>');
-               remove_space(buf);
-               Xstrdup_a(msgid, buf, return NULL);
+                       g_return_val_if_fail(*p == ')', NULL);
+               } else {
+                       g_warning("invalid element: %s\n", buf);
+                       g_free(element.name);
+                       g_free(element.value);
+                       break;
+               }
+
+               g_free(element.name);
+               g_free(element.value);
+               if (*cur_pos == '\0' || *cur_pos == ')') break;
+               n_element++;
        }
 
        msginfo = g_new0(MsgInfo, 1);
        }
 
        msginfo = g_new0(MsgInfo, 1);
@@ -1463,6 +1580,33 @@ catch:
 }
 
 #undef THROW
 }
 
 #undef THROW
+
+static gint imap_cmd_list(SockInfo *sock, const gchar *ref,
+                         const gchar *mailbox, GPtrArray *argbuf)
+{
+       gchar *new_ref;
+       gchar *new_mailbox;
+
+       if (!ref) ref = "\"\"";
+       if (!mailbox) mailbox = "\"\"";
+
+       if (*ref != '"' && strchr(ref, ' ') != NULL)
+               new_ref = g_strdup_printf("\"%s\"", ref);
+       else
+               new_ref = g_strdup(ref);
+       if (*mailbox != '"' && strchr(mailbox, ' ') != NULL)
+               new_mailbox = g_strdup_printf("\"%s\"", mailbox);
+       else
+               new_mailbox = g_strdup(mailbox);
+
+       imap_cmd_gen_send(sock, "LIST %s %s", new_ref, new_mailbox);
+
+       g_free(new_ref);
+       g_free(new_mailbox);
+
+       return imap_cmd_ok(sock, argbuf);
+}
+
 #define THROW goto catch
 
 static gint imap_cmd_select(SockInfo *sock, const gchar *folder,
 #define THROW goto catch
 
 static gint imap_cmd_select(SockInfo *sock, const gchar *folder,
@@ -1523,6 +1667,7 @@ catch:
        return ok;
 }
 
        return ok;
 }
 
+#if 0
 static gint imap_cmd_status(SockInfo *sock, const gchar *folder,
                            const gchar *status, gint *value)
 {
 static gint imap_cmd_status(SockInfo *sock, const gchar *folder,
                            const gchar *status, gint *value)
 {
@@ -1557,6 +1702,7 @@ catch:
 
        return ok;
 }
 
        return ok;
 }
+#endif
 
 #undef THROW
 
 
 #undef THROW
 
@@ -1710,7 +1856,7 @@ static gint imap_cmd_ok(SockInfo *sock, GPtrArray *argbuf)
               == IMAP_SUCCESS) {
                if (buf[0] == '*' && buf[1] == ' ') {
                        if (argbuf)
               == IMAP_SUCCESS) {
                if (buf[0] == '*' && buf[1] == ' ') {
                        if (argbuf)
-                               g_ptr_array_add(argbuf, g_strdup(&buf[2]));
+                               g_ptr_array_add(argbuf, g_strdup(buf + 2));
                        continue;
                }
 
                        continue;
                }
 
index e7ab3ff..798b28a 100644 (file)
@@ -196,6 +196,13 @@ int main(int argc, char *argv[])
        MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
        MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
 
        MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
        MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
 
+       if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log")) {
+               if (rename(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log",
+                          RC_DIR G_DIR_SEPARATOR_S "sylpheed.log.bak") < 0)
+                       FILE_OP_ERROR("sylpheed.log", "rename");
+       }
+       set_log_file(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log");
+
        if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "assortrc") &&
            !is_file_exist(RC_DIR G_DIR_SEPARATOR_S "filterrc")) {
                if (rename(RC_DIR G_DIR_SEPARATOR_S "assortrc",
        if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "assortrc") &&
            !is_file_exist(RC_DIR G_DIR_SEPARATOR_S "filterrc")) {
                if (rename(RC_DIR G_DIR_SEPARATOR_S "assortrc",
@@ -369,6 +376,8 @@ void app_will_exit(GtkWidget *widget, gpointer data)
        /* delete temporary files */
        remove_all_files(get_mime_tmp_dir());
 
        /* delete temporary files */
        remove_all_files(get_mime_tmp_dir());
 
+       close_log_file();
+
        /* delete unix domain socket */
        gdk_input_remove(lock_socket_tag);
        fd_close(lock_socket);
        /* delete unix domain socket */
        gdk_input_remove(lock_socket_tag);
        fd_close(lock_socket);
index 30fece0..972113e 100644 (file)
@@ -1969,6 +1969,24 @@ void get_rfc822_date(gchar *buf, gint len)
                   day, dd, mon, yyyy, hh, mm, ss, tzoffset(&t));
 }
 
                   day, dd, mon, yyyy, hh, mm, ss, tzoffset(&t));
 }
 
+static FILE *log_fp = NULL;
+
+void set_log_file(const gchar *filename)
+{
+       if (log_fp) return;
+       log_fp = fopen(filename, "w");
+       if (!log_fp)
+               FILE_OP_ERROR(filename, "fopen");
+}
+
+void close_log_file(void)
+{
+       if (log_fp) {
+               fclose(log_fp);
+               log_fp = NULL;
+       }
+}
+
 void debug_print(const gchar *format, ...)
 {
        va_list args;
 void debug_print(const gchar *format, ...)
 {
        va_list args;
@@ -1994,6 +2012,10 @@ void log_print(const gchar *format, ...)
 
        if (debug_mode) fputs(buf, stdout);
        log_window_append(buf, LOG_NORMAL);
 
        if (debug_mode) fputs(buf, stdout);
        log_window_append(buf, LOG_NORMAL);
+       if (log_fp) {
+               fputs(buf, log_fp);
+               fflush(log_fp);
+       }
        statusbar_puts_all(buf);
 }
 
        statusbar_puts_all(buf);
 }
 
@@ -2008,6 +2030,11 @@ void log_message(const gchar *format, ...)
 
        if (debug_mode) g_message("%s", buf);
        log_window_append(buf, LOG_MSG);
 
        if (debug_mode) g_message("%s", buf);
        log_window_append(buf, LOG_MSG);
+       if (log_fp) {
+               fputs("message: ", log_fp);
+               fputs(buf, log_fp);
+               fflush(log_fp);
+       }
 }
 
 void log_warning(const gchar *format, ...)
 }
 
 void log_warning(const gchar *format, ...)
@@ -2021,6 +2048,11 @@ void log_warning(const gchar *format, ...)
 
        g_warning("%s", buf);
        log_window_append(buf, LOG_WARN);
 
        g_warning("%s", buf);
        log_window_append(buf, LOG_WARN);
+       if (log_fp) {
+               fputs("*** warning: ", log_fp);
+               fputs(buf, log_fp);
+               fflush(log_fp);
+       }
 }
 
 void log_error(const gchar *format, ...)
 }
 
 void log_error(const gchar *format, ...)
index c895fc7..9a64cf6 100644 (file)
@@ -292,10 +292,12 @@ void get_rfc822_date              (gchar          *buf,
                                 gint            len);
 
 /* logging */
                                 gint            len);
 
 /* logging */
-void debug_print(const gchar *format, ...) G_GNUC_PRINTF(1, 2);
-void log_print (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
-void log_message(const gchar *format, ...) G_GNUC_PRINTF(1, 2);
-void log_warning(const gchar *format, ...) G_GNUC_PRINTF(1, 2);
-void log_error (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
+void set_log_file      (const gchar *filename);
+void close_log_file    (void);
+void debug_print       (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
+void log_print         (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
+void log_message       (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
+void log_warning       (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
+void log_error         (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
 
 #endif /* __UTILS_H__ */
 
 #endif /* __UTILS_H__ */