more sync with sylpheed 0.5.0pre3
authorPaul Mangan <paul@claws-mail.org>
Wed, 27 Jun 2001 08:07:04 +0000 (08:07 +0000)
committerPaul Mangan <paul@claws-mail.org>
Wed, 27 Jun 2001 08:07:04 +0000 (08:07 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
src/imap.c
src/prefs_account.c
src/prefs_account.h
src/socket.c
src/socket.h

index 2cadad8..40c6dc0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,16 @@
        * src/imap.c: imap_parse_envelope(): fixed a bug that didn't
          parse the FETCH response that continues to the next line.
          imap_parse_fetch_element(): removed.
+         imap_parse_atom(), imap_parse_one_address(), imap_parse_address(),
+         imap_parse_envelope(), imap_get_uncached_messages(): use GString
+         and sock_getline() to parse the FETCH response.
+         imap_remove_all_msg(): fixed a bug that didn't delete messages
+         correctly.
+         imap_parse_address(): fixed a bug that didn't concaternate
+         addresses correctly, using GString.
+       * src/socket.[ch]: sock_getline(), fd_getline(): new. They read
+         the whole line and return the newly allocated string.
+       * src/prefs_account.[ch]: added `IMAP server directory' entry.
 
 2001-06-25
 
index 5861897..989b764 100644 (file)
@@ -1,3 +1,7 @@
+2001-06-27 [paul]
+
+        * more sync with sylpheed 0.5.0pre3
+
 2001-06-26 [paul]
 
         0.5.0claws3
index ab40209..9a9f81b 100644 (file)
@@ -3,6 +3,16 @@
        * src/imap.c: imap_parse_envelope(): ¼¡¤Î¹Ô¤Ë³¤¯ FETCH ±þÅú¤ò
          ²òÀϤǤ­¤Ê¤«¤Ã¤¿¥Ð¥°¤ò½¤Àµ¡£
          imap_parse_fetch_element(): ºï½ü¡£
+         imap_parse_atom(), imap_parse_one_address(), imap_parse_address(),
+         imap_parse_envelope(), imap_get_uncached_messages(): FETCH ±þÅú
+         ¤ò²òÀϤ¹¤ë¤¿¤á¤Ë GString ¤È sock_getline() ¤ò»ÈÍѤ¹¤ë¤è¤¦¤Ë¤·¤¿¡£
+         imap_remove_all_msg(): ¥á¥Ã¥»¡¼¥¸¤òÀµ¤·¤¯ºï½ü¤·¤Æ¤¤¤Ê¤«¤Ã¤¿¥Ð¥°¤ò
+         ½¤Àµ¡£
+         imap_parse_address(): ¥¢¥É¥ì¥¹¤òÀµ¤·¤¯·ë¹ç¤·¤Æ¤¤¤Ê¤«¤Ã¤¿¥Ð¥°¤ò
+         GString ¤ò»ÈÍѤ·¤Æ½¤Àµ¡£
+       * src/socket.[ch]: sock_getline(), fd_getline(): ¿·µ¬¡£¹ÔÁ´ÂΤò
+         Æɤ߹þ¤ß¡¢¿·µ¬¤Ë¥¢¥í¥±¡¼¥È¤µ¤ì¤¿Ê¸»úÎó¤òÊÖ¤¹¡£
+       * src/prefs_account.[ch]: ¡ÖIMAP¥µ¡¼¥Ð¥Ç¥£¥ì¥¯¥È¥ê¡×¥¨¥ó¥È¥ê¤òÄɲá£
 
 2001-06-25
 
index db5a5a8..42e5ae9 100644 (file)
@@ -105,20 +105,21 @@ static IMAPNameSpace *imap_find_namespace (IMAPFolder     *folder,
 static gchar *imap_parse_atom          (SockInfo       *sock,
                                         gchar          *src,
                                         gchar          *dest,
-                                        gchar          *orig_buf);
+                                        gint            dest_len,
+                                        GString        *str);
 static gchar *imap_parse_one_address   (SockInfo       *sock,
                                         gchar          *start,
                                         gchar          *out_from_str,
                                         gchar          *out_fromname_str,
-                                        gchar          *orig_buf);
+                                        GString        *str);
 static gchar *imap_parse_address       (SockInfo       *sock,
                                         gchar          *start,
                                         gchar         **out_from_str,
                                         gchar         **out_fromname_str,
-                                        gchar          *orig_buf);
+                                        GString        *str);
 static MsgFlags imap_parse_flags       (const gchar    *flag_str);
 static MsgInfo *imap_parse_envelope    (SockInfo       *sock,
-                                        gchar          *line_str);
+                                        GString        *line_str);
 
 /* low-level IMAP4rev1 commands */
 static gint imap_cmd_login     (SockInfo       *sock,
@@ -657,8 +658,9 @@ gint imap_remove_all_msg(Folder *folder, FolderItem *item)
        if (exists == 0)
                return IMAP_SUCCESS;
 
-       ok = imap_set_message_flags(session, 1, exists,
-                                   IMAP_FLAG_DELETED, TRUE);
+       imap_cmd_gen_send(SESSION(session)->sock,
+                         "STORE 1:%d +FLAGS (\\Deleted)", exists);
+       ok = imap_cmd_ok(SESSION(session)->sock, NULL);
        statusbar_pop_all();
        if (ok != IMAP_SUCCESS) {
                log_warning(_("can't set deleted flags: 1:%d\n"), exists);
@@ -846,9 +848,10 @@ static GSList *imap_get_uncached_messages(IMAPSession *session,
                                          FolderItem *item,
                                          guint32 first_uid, guint32 last_uid)
 {
-       gchar buf[IMAPBUFSIZE];
+       gchar *tmp;
        GSList *newlist = NULL;
        GSList *llast = NULL;
+       GString *str;
        MsgInfo *msginfo;
 
        g_return_val_if_fail(session != NULL, NULL);
@@ -863,18 +866,26 @@ static GSList *imap_get_uncached_messages(IMAPSession *session,
                return NULL;
        }
 
+       str = g_string_new(NULL);
+
        for (;;) {
-               if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) {
+               if ((tmp = sock_getline(SESSION(session)->sock)) == NULL) {
                        log_warning(_("error occurred while getting envelope.\n"));
+                       g_string_free(str, TRUE);
                        return newlist;
                }
-               strretchomp(buf);
-               log_print("IMAP4< %s\n", buf);
-               if (buf[0] != '*' || buf[1] != ' ') break;
+               strretchomp(tmp);
+               log_print("IMAP4< %s\n", tmp);
+               if (tmp[0] != '*' || tmp[1] != ' ') {
+                       g_free(tmp);
+                       break;
+               }
+               g_string_assign(str, tmp);
+               g_free(tmp);
 
-               msginfo = imap_parse_envelope(SESSION(session)->sock, buf);
+               msginfo = imap_parse_envelope(SESSION(session)->sock, str);
                if (!msginfo) {
-                       log_warning(_("can't parse envelope: %s\n"), buf);
+                       log_warning(_("can't parse envelope: %s\n"), str->str);
                        continue;
                }
 
@@ -888,6 +899,8 @@ static GSList *imap_get_uncached_messages(IMAPSession *session,
                }
        }
 
+       g_string_free(str, TRUE);
+
        return newlist;
 }
 
@@ -1064,11 +1077,13 @@ static IMAPNameSpace *imap_find_namespace(IMAPFolder *folder,
        return namespace;
 }
 
-static gchar *imap_parse_atom(SockInfo *sock, gchar *src, gchar *dest,
-                             gchar *orig_buf)
+static gchar *imap_parse_atom(SockInfo *sock, gchar *src,
+                             gchar *dest, gint dest_len, GString *str)
 {
        gchar *cur_pos = src;
 
+       g_return_val_if_fail(str != NULL, cur_pos);
+
        while (*cur_pos == ' ') cur_pos++;
 
        if (!strncmp(cur_pos, "NIL", 3)) {
@@ -1077,24 +1092,26 @@ static gchar *imap_parse_atom(SockInfo *sock, gchar *src, gchar *dest,
        } else if (*cur_pos == '\"') {
                gchar *p;
 
-               p = strchr_cpy(cur_pos + 1, '\"', dest, IMAPBUFSIZE);
+               p = strchr_cpy(cur_pos + 1, '\"', dest, dest_len);
                cur_pos = p ? p : cur_pos + 2;
        } else if (*cur_pos == '{') {
                gchar buf[32];
                gint len;
+               gchar *nextline;
 
                cur_pos = strchr_cpy(cur_pos + 1, '}', buf, sizeof(buf));
                len = atoi(buf);
 
-               g_return_val_if_fail(orig_buf != NULL, cur_pos);
-
-               if (sock_gets(sock, orig_buf, IMAPBUFSIZE) < 0)
+               if ((nextline = sock_getline(sock)) == NULL)
                        return cur_pos;
-               strretchomp(orig_buf);
-               log_print("IMAP4< %s\n", orig_buf);
-               memcpy(dest, orig_buf, len);
-               dest[len] = '\0';
-               cur_pos = orig_buf + len;
+               strretchomp(nextline);
+               log_print("IMAP4< %s\n", nextline);
+               g_string_assign(str, nextline);
+
+               len = MIN(len, strlen(nextline));
+               memcpy(dest, nextline, MIN(len, dest_len - 1));
+               dest[MIN(len, dest_len - 1)] = '\0';
+               cur_pos = str->str + len;
        }
 
        return cur_pos;
@@ -1103,22 +1120,22 @@ static gchar *imap_parse_atom(SockInfo *sock, gchar *src, gchar *dest,
 static gchar *imap_parse_one_address(SockInfo *sock, gchar *start,
                                     gchar *out_from_str,
                                     gchar *out_fromname_str,
-                                    gchar *orig_buf)
+                                    GString *str)
 {
        gchar buf[IMAPBUFSIZE];
        gchar *userid;
        gchar *domain;
        gchar *cur_pos = start;
 
-       cur_pos = imap_parse_atom(sock, cur_pos, buf, orig_buf);
+       cur_pos = imap_parse_atom(sock, cur_pos, buf, sizeof(buf), str);
        conv_unmime_header(out_fromname_str, IMAPBUFSIZE, buf, NULL);
 
-       cur_pos = imap_parse_atom(sock, cur_pos, buf, orig_buf);
+       cur_pos = imap_parse_atom(sock, cur_pos, buf, sizeof(buf), str);
 
-       cur_pos = imap_parse_atom(sock, cur_pos, buf, orig_buf);
+       cur_pos = imap_parse_atom(sock, cur_pos, buf, sizeof(buf), str);
        Xstrdup_a(userid, buf, return cur_pos + 1);
 
-       cur_pos = imap_parse_atom(sock, cur_pos, buf, orig_buf);
+       cur_pos = imap_parse_atom(sock, cur_pos, buf, sizeof(buf), str);
        Xstrdup_a(domain, buf, return cur_pos + 1);
 
        if (out_fromname_str[0] != '\0') {
@@ -1131,8 +1148,7 @@ static gchar *imap_parse_one_address(SockInfo *sock, gchar *start,
        }
 
        while (*cur_pos == ' ') cur_pos++;
-
-       g_return_val_if_fail(*cur_pos == ')', cur_pos + 1);
+       g_return_val_if_fail(*cur_pos == ')', NULL);
 
        return cur_pos + 1;
 }
@@ -1140,12 +1156,12 @@ static gchar *imap_parse_one_address(SockInfo *sock, gchar *start,
 static gchar *imap_parse_address(SockInfo *sock, gchar *start,
                                 gchar **out_from_str,
                                 gchar **out_fromname_str,
-                                gchar *orig_buf)
+                                GString *str)
 {
        gchar buf[IMAPBUFSIZE];
        gchar name_buf[IMAPBUFSIZE];
        gchar *cur_pos = start;
-       gboolean first = TRUE;
+       GString *addr_str;
 
        if (out_from_str)     *out_from_str     = NULL;
        if (out_fromname_str) *out_fromname_str = NULL;
@@ -1160,21 +1176,29 @@ static gchar *imap_parse_address(SockInfo *sock, gchar *start,
        g_return_val_if_fail(*cur_pos == '(', NULL);
        cur_pos++;
 
+       addr_str = g_string_new(NULL);
+
        for (;;) {
                gchar ch = *cur_pos++;
                if (ch == ')') break;
                if (ch == '(') {
-                       if (!first) strcat(buf, ", ");
-                       first = FALSE;
                        cur_pos = imap_parse_one_address
-                               (sock, cur_pos, buf, name_buf, orig_buf);
-                       if (!cur_pos) return NULL;
+                               (sock, cur_pos, buf, name_buf, str);
+                       if (!cur_pos) {
+                               g_string_free(addr_str, TRUE);
+                               return NULL;
+                       }
+                       if (addr_str->str[0] != '\0')
+                               g_string_append(addr_str, ", ");
+                       g_string_append(addr_str, buf);
                }
        }
 
-       if (out_from_str)     *out_from_str     = g_strdup(buf);
+       if (out_from_str)     *out_from_str     = g_strdup(addr_str->str);
        if (out_fromname_str) *out_fromname_str = g_strdup(name_buf);
 
+       g_string_free(addr_str, TRUE);
+
        return cur_pos;
 }
 
@@ -1203,7 +1227,7 @@ static MsgFlags imap_parse_flags(const gchar *flag_str)
        return flags;
 }
 
-static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
+static MsgInfo *imap_parse_envelope(SockInfo *sock, GString *line_str)
 {
        MsgInfo *msginfo;
        gchar buf[IMAPBUFSIZE];
@@ -1227,9 +1251,10 @@ static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
        gint n_element = 0;
 
        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->str[0] == '*' &&
+                            line_str->str[1] == ' ', NULL);
 
-       cur_pos = line_str + 2;
+       cur_pos = line_str->str + 2;
 
 #define PARSE_ONE_ELEMENT(ch) \
 { \
@@ -1265,12 +1290,12 @@ static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
                        cur_pos += 9;
                        g_return_val_if_fail(*cur_pos == '(', NULL);
                        cur_pos = imap_parse_atom
-                               (sock, cur_pos + 1, buf, line_str);
+                               (sock, cur_pos + 1, buf, sizeof(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);
+                               (sock, cur_pos, buf, sizeof(buf), line_str);
                        if (buf[0] != '\0') {
                                conv_unmime_header(tmp, sizeof(tmp), buf, NULL);
                                Xstrdup_a(subject, tmp, return NULL);
@@ -1313,7 +1338,8 @@ static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
 #undef SKIP_ONE_ELEMENT
 
                        g_return_val_if_fail(*cur_pos == ' ', NULL);
-                       cur_pos = imap_parse_atom(sock, cur_pos, buf, line_str);
+                       cur_pos = imap_parse_atom
+                               (sock, cur_pos, buf, sizeof(buf), line_str);
                        if (buf[0] != '\0') {
                                eliminate_parenthesis(buf, '(', ')');
                                extract_parenthesis(buf, '<', '>');
@@ -1322,7 +1348,8 @@ static MsgInfo *imap_parse_envelope(SockInfo *sock, gchar *line_str)
                        }
 
                        g_return_val_if_fail(*cur_pos == ' ', NULL);
-                       cur_pos = imap_parse_atom(sock, cur_pos, buf, line_str);
+                       cur_pos = imap_parse_atom
+                               (sock, cur_pos, buf, sizeof(buf), line_str);
                        if (buf[0] != '\0') {
                                extract_parenthesis(buf, '<', '>');
                                remove_space(buf);
index 1f9e7ce..4fcd609 100644 (file)
@@ -89,6 +89,9 @@ static struct Receive {
        GtkWidget *getall_chkbtn;
        GtkWidget *recvatgetall_chkbtn;
        GtkWidget *filter_on_recv_chkbtn;
+
+       GtkWidget *imap_frame;
+       GtkWidget *imapdir_entry;
 } receive;
 
 static struct Send {
@@ -216,6 +219,9 @@ static PrefParam param[] = {
         &receive.filter_on_recv_chkbtn,
         prefs_set_data_from_toggle, prefs_set_toggle},
 
+       {"imap_directory", NULL, &tmp_ac_prefs.imap_dir, P_STRING,
+        &receive.imapdir_entry, prefs_set_data_from_entry, prefs_set_entry},
+
        /* Send */
        {"add_date", "TRUE", &tmp_ac_prefs.add_date, P_BOOL,
         &send.date_chkbtn,
@@ -874,6 +880,10 @@ static void prefs_account_receive_create(void)
        GtkWidget *getall_chkbtn;
        GtkWidget *recvatgetall_chkbtn;
        GtkWidget *filter_on_recv_chkbtn;
+       GtkWidget *frame2;
+       GtkWidget *hbox1;
+       GtkWidget *imapdir_label;
+       GtkWidget *imapdir_entry;
 
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox1);
@@ -897,11 +907,33 @@ static void prefs_account_receive_create(void)
        PACK_CHECK_BUTTON (vbox2, filter_on_recv_chkbtn,
                           _("Filter messages on receiving"));
 
+       PACK_FRAME (vbox1, frame2, _("IMAP4"));
+
+       vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
+       gtk_widget_show (vbox2);
+       gtk_container_add (GTK_CONTAINER (frame2), vbox2);
+       gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
+
+       hbox1 = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (hbox1);
+       gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
+
+       imapdir_label = gtk_label_new (_("IMAP server directory"));
+       gtk_widget_show (imapdir_label);
+       gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
+
+       imapdir_entry = gtk_entry_new();
+       gtk_widget_show (imapdir_entry);
+       gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, TRUE, TRUE, 0);
+
        receive.pop3_frame            = frame1;
        receive.rmmail_chkbtn         = rmmail_chkbtn;
        receive.getall_chkbtn         = getall_chkbtn;
        receive.recvatgetall_chkbtn   = recvatgetall_chkbtn;
        receive.filter_on_recv_chkbtn = filter_on_recv_chkbtn;
+
+       receive.imap_frame    = frame2;
+       receive.imapdir_entry = imapdir_entry;
 }
 
 static void prefs_account_send_create(void)
@@ -1440,6 +1472,7 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                prefs_account_nntpauth_toggled
                        (GTK_TOGGLE_BUTTON(basic.nntpauth_chkbtn), NULL);
                gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
+               gtk_widget_set_sensitive(receive.imap_frame, FALSE);
                break;
        case A_LOCAL:
                gtk_widget_set_sensitive(basic.inbox_label, TRUE);
@@ -1483,6 +1516,7 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
                gtk_widget_set_sensitive(basic.pass_entry, TRUE);
                gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
+               gtk_widget_set_sensitive(receive.imap_frame, FALSE);
                prefs_account_mailcmd_toggled
                        (GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn), NULL);
                break;
@@ -1530,6 +1564,7 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
                gtk_widget_set_sensitive(basic.pass_entry, TRUE);
                gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
+               gtk_widget_set_sensitive(receive.imap_frame, TRUE);
                gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
                gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
                break;
@@ -1578,6 +1613,7 @@ static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
                gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
                gtk_widget_set_sensitive(basic.pass_entry, TRUE);
                gtk_widget_set_sensitive(receive.pop3_frame, TRUE);
+               gtk_widget_set_sensitive(receive.imap_frame, FALSE);
                gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
                gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
                break;
index 7254f48..c4627eb 100644 (file)
@@ -79,6 +79,8 @@ struct _PrefsAccount
        gboolean recv_at_getall;
        gboolean filter_on_recv;
 
+        gchar *imap_dir;
+
        /* Send */
        gboolean  add_date;
        gboolean  gen_msgid;
index 40710be..1d8f95e 100644 (file)
@@ -457,6 +457,35 @@ gint sock_gets(SockInfo *sock, gchar *buf, gint len)
        return fd_gets(sock->sock, buf, len);
 }
 
+gchar *fd_getline(gint fd)
+{
+       gchar buf[BUFFSIZE];
+       gchar *str = NULL;
+       gint len;
+       gulong size = 1;
+
+       while ((len = fd_gets(fd, buf, sizeof(buf))) > 0) {
+               size += len;
+               if (!str)
+                       str = g_strdup(buf);
+               else {
+                       str = g_realloc(str, size);
+                       strcat(str, buf);
+               }
+               if (buf[len - 1] == '\n')
+                       break;
+       }
+
+       return str;
+}
+
+gchar *sock_getline(SockInfo *sock)
+{
+       g_return_val_if_fail(sock != NULL, NULL);
+
+       return fd_getline(sock->sock);
+}
+
 gint sock_puts(SockInfo *sock, const gchar *buf)
 {
        gint ret;
@@ -500,9 +529,9 @@ gint fd_close(gint fd)
 }
 
 gint sock_gdk_input_add(SockInfo *sock,
-                        GdkInputCondition condition,
-                        GdkInputFunction function,
-                        gpointer data)
+                       GdkInputCondition condition,
+                       GdkInputFunction function,
+                       gpointer data)
 {
        g_return_val_if_fail(sock != NULL, -1);
 
index a1fe7fc..93eaa36 100644 (file)
@@ -77,6 +77,7 @@ gint sock_printf      (SockInfo *sock, const gchar *format, ...)
 gint sock_read         (SockInfo *sock, gchar *buf, gint len);
 gint sock_write                (SockInfo *sock, const gchar *buf, gint len);
 gint sock_gets         (SockInfo *sock, gchar *buf, gint len);
+gchar *sock_getline    (SockInfo *sock);
 gint sock_puts         (SockInfo *sock, const gchar *buf);
 gint sock_close                (SockInfo *sock);
 
@@ -95,6 +96,7 @@ gint fd_accept                (gint sock);
 gint fd_read           (gint sock, gchar *buf, gint len);
 gint fd_write          (gint sock, const gchar *buf, gint len);
 gint fd_gets           (gint sock, gchar *buf, gint len);
+gchar *fd_getline      (gint sock);
 gint fd_close          (gint sock);
 
 #endif /* __SOCKET_H__ */