From 928a2cc8708a85a7fbcceb4d77e163835b158934 Mon Sep 17 00:00:00 2001 From: hiro Date: Mon, 28 Nov 2005 05:43:35 +0000 Subject: reverted linebreak conversion. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@783 ee746299-78ed-0310-b773-934348b2243d --- ChangeLog | 6 ++++++ ChangeLog.ja | 6 ++++++ libsylph/pop.c | 10 +++++++-- libsylph/recv.c | 47 +++++++++++++++++++++++++++++++---------- src/compose.c | 65 ++++++++++++++++++++++++++++++--------------------------- 5 files changed, 90 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c9ca874..91b08ef3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-11-28 + + * libsylph/pop.c + libsylph/recv.c + src/compose.c: reverted linebreak conversion. + 2005-11-25 * src/compose.c: also canonicalize on redirect/queue. diff --git a/ChangeLog.ja b/ChangeLog.ja index 648ac5a6..7ea51743 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,3 +1,9 @@ +2005-11-28 + + * libsylph/pop.c + libsylph/recv.c + src/compose.c: 改行の変換を元に戻した。 + 2005-11-25 * src/compose.c: リダイレクト/キュー時も正規化するようにした。 diff --git a/libsylph/pop.c b/libsylph/pop.c index ec703191..b61eb377 100644 --- a/libsylph/pop.c +++ b/libsylph/pop.c @@ -549,9 +549,15 @@ static gint pop3_write_msg_to_file(const gchar *file, FILE *src_fp, guint len) gint len; len = strlen(buf); - if (len > 0) + if (len > 0) { last_ch = buf[len - 1]; - else + if (last_ch == '\n' && len > 1 && + buf[len - 2] == '\r') { + buf[len - 2] = '\n'; + buf[len - 1] = '\0'; + } else if (last_ch == '\r') + buf[len - 1] = '\0'; + } else last_ch = '\0'; if ((last_ch == '\0' || last_ch == '\n') && diff --git a/libsylph/recv.c b/libsylph/recv.c index 55890df5..47222709 100644 --- a/libsylph/recv.c +++ b/libsylph/recv.c @@ -166,6 +166,12 @@ gint recv_write(SockInfo *sock, FILE *fp) } p = buf; + + if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') { + buf[len - 2] = '\n'; + buf[len - 1] = '\0'; + } + if (buf[0] == '.' && buf[1] == '.') p++; else if (!strncmp(buf, ">From ", 6)) @@ -185,27 +191,46 @@ gint recv_write(SockInfo *sock, FILE *fp) gint recv_bytes_write(SockInfo *sock, glong size, FILE *fp) { - gchar buf[BUFFSIZE]; - glong count = 0; + gchar *buf; + gchar *prev, *cur; if (size == 0) return 0; - do { - gint read_count, to_read; + buf = recv_bytes(sock, size); + if (!buf) + return -2; - to_read = MIN(sizeof(buf), size - count); - read_count = sock_read(sock, buf, to_read); - if (read_count <= 0) - return -2; + /* +------------------+----------------+--------------------------+ * + * ^buf ^prev ^cur buf+size-1^ */ + + prev = buf; + while ((cur = memchr(prev, '\r', size - (prev - buf))) != NULL) { + if (cur == buf + size - 1) break; - if (fp && fwrite(buf, read_count, 1, fp) < 1) { + if (fp && (fwrite(prev, sizeof(gchar), cur - prev, fp) == EOF || + fwrite("\n", sizeof(gchar), 1, fp) == EOF)) { perror("fwrite"); g_warning(_("Can't write to file.\n")); fp = NULL; } - count += read_count; - } while (count < size); + + if (*(cur + 1) == '\n') + prev = cur + 2; + else + prev = cur + 1; + + if (prev - buf >= size) break; + } + + if (prev - buf < size && fp && + fwrite(buf, sizeof(gchar), size - (prev - buf), fp) == EOF) { + perror("fwrite"); + g_warning(_("Can't write to file.\n")); + fp = NULL; + } + + g_free(buf); if (!fp) return -1; diff --git a/src/compose.c b/src/compose.c index 1ecd8603..0e35f5ca 100644 --- a/src/compose.c +++ b/src/compose.c @@ -3013,14 +3013,19 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, return -1; } - if (canonicalize_file_replace(file) < 0) { - g_unlink(file); - return -1; - } - #if USE_GPGME - if (!rfc2015_is_available() || is_draft) + if (!rfc2015_is_available() || is_draft) { + uncanonicalize_file_replace(file); return 0; + } + + if ((compose->use_signing && !compose->account->clearsign) || + compose->use_encryption) { + if (canonicalize_file_replace(file) < 0) { + g_unlink(file); + return -1; + } + } if (compose->use_signing && !compose->account->clearsign) { GSList *key_list; @@ -3040,6 +3045,8 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, } #endif /* USE_GPGME */ + uncanonicalize_file_replace(file); + return 0; } @@ -3177,10 +3184,6 @@ static gint compose_redirect_write_to_file(Compose *compose, const gchar *file) g_unlink(file); return -1; } - if (canonicalize_file_replace(file) < 0) { - g_unlink(file); - return -1; - } return 0; error: @@ -3250,40 +3253,40 @@ static gint compose_queue(Compose *compose, const gchar *file) } /* queueing variables */ - fprintf(fp, "AF:\r\n"); - fprintf(fp, "NF:0\r\n"); - fprintf(fp, "PS:10\r\n"); - fprintf(fp, "SRH:1\r\n"); - fprintf(fp, "SFN:\r\n"); - fprintf(fp, "DSR:\r\n"); + fprintf(fp, "AF:\n"); + fprintf(fp, "NF:0\n"); + fprintf(fp, "PS:10\n"); + fprintf(fp, "SRH:1\n"); + fprintf(fp, "SFN:\n"); + fprintf(fp, "DSR:\n"); if (compose->msgid) - fprintf(fp, "MID:<%s>\r\n", compose->msgid); + fprintf(fp, "MID:<%s>\n", compose->msgid); else - fprintf(fp, "MID:\r\n"); - fprintf(fp, "CFG:\r\n"); - fprintf(fp, "PT:0\r\n"); - fprintf(fp, "S:%s\r\n", compose->account->address); - fprintf(fp, "RQ:\r\n"); + fprintf(fp, "MID:\n"); + fprintf(fp, "CFG:\n"); + fprintf(fp, "PT:0\n"); + fprintf(fp, "S:%s\n", compose->account->address); + fprintf(fp, "RQ:\n"); if (compose->account->smtp_server) - fprintf(fp, "SSV:%s\r\n", compose->account->smtp_server); + fprintf(fp, "SSV:%s\n", compose->account->smtp_server); else - fprintf(fp, "SSV:\r\n"); + fprintf(fp, "SSV:\n"); if (compose->account->nntp_server) - fprintf(fp, "NSV:%s\r\n", compose->account->nntp_server); + fprintf(fp, "NSV:%s\n", compose->account->nntp_server); else - fprintf(fp, "NSV:\r\n"); - fprintf(fp, "SSH:\r\n"); + fprintf(fp, "NSV:\n"); + fprintf(fp, "SSH:\n"); if (compose->to_list) { fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data); for (cur = compose->to_list->next; cur != NULL; cur = cur->next) fprintf(fp, ",<%s>", (gchar *)cur->data); - fprintf(fp, "\r\n"); + fprintf(fp, "\n"); } else - fprintf(fp, "R:\r\n"); + fprintf(fp, "R:\n"); /* Sylpheed account ID */ - fprintf(fp, "AID:%d\r\n", compose->account->account_id); - fprintf(fp, "\r\n"); + fprintf(fp, "AID:%d\n", compose->account->account_id); + fprintf(fp, "\n"); while (fgets(buf, sizeof(buf), src_fp) != NULL) { if (fputs(buf, fp) == EOF) { -- cgit v1.2.3