summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 902f235)
raw | patch | inline | side by side (parent: 902f235)
author | Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp> | |
Fri, 12 Feb 2010 11:36:12 +0000 (20:36 +0900) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 12 Feb 2010 19:21:28 +0000 (11:21 -0800) |
When storing a message over IMAP (RFC 3501 6.3.11), the message should be
in the format of an RFC 2822 message; most notably, CRLF must be used as
a line terminator.
Convert "\n" line endings in the payload to CRLF before feeding it to
IMAP APPEND command.
Signed-off-by: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
in the format of an RFC 2822 message; most notably, CRLF must be used as
a line terminator.
Convert "\n" line endings in the payload to CRLF before feeding it to
IMAP APPEND command.
Signed-off-by: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
imap-send.c | patch | blob | history |
diff --git a/imap-send.c b/imap-send.c
index de8114bac010ef095cf9de17671566e248366dcb..3527b56d5d18988d7b84a8c498e1ca18aa806613 100644 (file)
--- a/imap-send.c
+++ b/imap-send.c
char *data;
int len;
unsigned char flags;
- unsigned int crlf:1;
};
static const char imap_send_usage[] = "git imap-send < <mbox>";
return d;
}
+static void lf_to_crlf(struct msg_data *msg)
+{
+ char *new;
+ int i, j, lfnum = 0;
+
+ if (msg->data[0] == '\n')
+ lfnum++;
+ for (i = 1; i < msg->len; i++) {
+ if (msg->data[i - 1] != '\r' && msg->data[i] == '\n')
+ lfnum++;
+ }
+
+ new = xmalloc(msg->len + lfnum);
+ if (msg->data[0] == '\n') {
+ new[0] = '\r';
+ new[1] = '\n';
+ i = 1;
+ j = 2;
+ } else {
+ new[0] = msg->data[0];
+ i = 1;
+ j = 1;
+ }
+ for ( ; i < msg->len; i++) {
+ if (msg->data[i] != '\n') {
+ new[j++] = msg->data[i];
+ continue;
+ }
+ if (msg->data[i - 1] != '\r')
+ new[j++] = '\r';
+ /* otherwise it already had CR before */
+ new[j++] = '\n';
+ }
+ msg->len += lfnum;
+ free(msg->data);
+ msg->data = new;
+}
+
static int imap_store_msg(struct store *gctx, struct msg_data *data)
{
struct imap_store *ctx = (struct imap_store *)gctx;
int ret, d;
char flagstr[128];
+ lf_to_crlf(data);
memset(&cb, 0, sizeof(cb));
cb.dlen = data->len;