# [PATCH] git-imap-send bugfix: Allow lines starting with "From " in body

3 messages from 2010-03-21 to 2010-03-22. Participants: Ramkumar Ramachandra, Junio C Hamano.
Thread: https://gitlist.dev/t/23125

## Ramkumar Ramachandra, 2010-03-21 18:47

Subject: [PATCH] git-imap-send bugfix: Allow lines starting with "From " in body
Message-ID: <f3271551003211147x538d7682wc67dcc4f914ed97c@mail.gmail.com>
URL: https://gitlist.dev/e/f3271551003211147x538d7682wc67dcc4f914ed97c%40mail.gmail.com

```
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 Documentation/git-imap-send.txt |    5 -----
 imap-send.c                     |    8 +++++++-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-imap-send.txt b/Documentation/git-imap-send.txt
index 6cafbe2..ed9d3ce 100644
--- a/Documentation/git-imap-send.txt
+++ b/Documentation/git-imap-send.txt
@@ -123,11 +123,6 @@ users may wish to visit this web page for more information:
   http://kb.mozillazine.org/Plain_text_e-mail_-_Thunderbird#Completely_plain_email


-BUGS
-----
-Doesn't handle lines starting with "From " in the message body.
-
-
 Author
 ------
 Derived from isync 1.0.1 by Mike McCormack.
diff --git a/imap-send.c b/imap-send.c
index aeb2985..3163bb9 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1431,8 +1431,14 @@ static int count_messages(struct msg_data *msg)

 	while (1) {
 		if (!prefixcmp(p, "From ")) {
+			p = strstr(p+5, "\nFrom: ");
+			if (!p) break;
+			p = strstr(p+7, "\nDate: ");
+			if (!p) break;
+			p = strstr(p+7, "\nSubject: ");
+			if (!p) break;
 			count++;
-			p += 5;
+			p += 10;
 		}
 		p = strstr(p+5, "\nFrom ");
 		if (!p)
-- 
1.7.0

```

## Junio C Hamano, 2010-03-21 22:05

Subject: Re: [PATCH] git-imap-send bugfix: Allow lines starting with "From " in body
Message-ID: <7vwrx5gwjz.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwrx5gwjz.fsf%40alter.siamese.dyndns.org
In-Reply-To: <f3271551003211147x538d7682wc67dcc4f914ed97c@mail.gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:

> diff --git a/imap-send.c b/imap-send.c
> index aeb2985..3163bb9 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -1431,8 +1431,14 @@ static int count_messages(struct msg_data *msg)
>
>  	while (1) {
>  		if (!prefixcmp(p, "From ")) {
> +			p = strstr(p+5, "\nFrom: ");
> +			if (!p) break;
> +			p = strstr(p+7, "\nDate: ");
> +			if (!p) break;
> +			p = strstr(p+7, "\nSubject: ");
> +			if (!p) break;
>  			count++;
> -			p += 5;
> +			p += 10;

The last "increment by 10" is logically tied to the last string being
checked happens to be "\nSubject: ", so I would prefer to have the
"increment count" be done after that.  That way you will keep logically
close things physically close together.

As "git help imap-send" clearly says that this command is intended to be
used on output from format-patch (but it actually does not say "and
nothing else", which it should for your patch to make sense), I think the
code is allowed to assume _some_ fixed order of the header fields.  It
would break people's existing abuse to use imap-send to stuff random
pieces of messages in mbox to their IMAP server, though.

But does format-patch _always_ start each message with these and only with
these fields in this order?  Where would Message-Id:, References:, and Cc:
come when the user told format-patch to add them?

```

## Ramkumar Ramachandra, 2010-03-22 02:37

Subject: Re: [PATCH] git-imap-send bugfix: Allow lines starting with "From " in body
Message-ID: <f3271551003211937p37d37816wacfe67faacb09add@mail.gmail.com>
URL: https://gitlist.dev/e/f3271551003211937p37d37816wacfe67faacb09add%40mail.gmail.com
In-Reply-To: <7vwrx5gwjz.fsf@alter.siamese.dyndns.org>

```
[Culling mike@codeweavers.com from CC]

> As "git help imap-send" clearly says that this command is intended to be
> used on output from format-patch (but it actually does not say "and
> nothing else", which it should for your patch to make sense), I think the
> code is allowed to assume _some_ fixed order of the header fields.  It
> would break people's existing abuse to use imap-send to stuff random
> pieces of messages in mbox to their IMAP server, though.

Yes, it would. Don't you think the bug it fixes justifies the break?
Perhaps we should mention in the documentation that it accepts
mailboxes where emails must have those three mandatory fields in that
order?

> But does format-patch _always_ start each message with these and only with
> these fields in this order?  Where would Message-Id:, References:, and Cc:
> come when the user told format-patch to add them?

Yes. From, Date, and Subject are the minimum set of fields for any
general patch produced by git-format-patch, and they always appear in
that order. For example, see this header:

From 20f0cf89fb9508f9e5197a3cf47a872053d4941d Mon Sep 17 00:00:00 2001
Message-Id: <20f0cf89fb9508f9e5197a3cf47a872053d4941d.1269224757.git.artagnon@gmail.com>
In-Reply-To: <42ef3f8cebd4d34e24b1544036cd48f56110c2d4.1269224756.git.artagnon@gmail.com>
References: <13132>
	<42ef3f8cebd4d34e24b1544036cd48f56110c2d4.1269224756.git.artagnon@gmail.com>
From: Ramkumar Ramachandra <artagnon@gmail.com>
Date: Sun, 21 Mar 2010 23:58:25 +0530
Subject: [PATCH 2/2] git-imap-send bugfix: Allow lines starting with
"From " in body
Cc: gitster@pobox.com

Thanks,
Ramkumar

```
