On 01/12/2017 01:20 AM, Matthew Wilcox wrote:
From: Matthew Wilcox <mawil...@microsoft.com>

Extend the --scissors mechanism to strip off the preamble created by
forwarding a patch.  There are a couple of extra headers ("Sent" and
"To") added by forwarding, but other than that, the --scissors option
will now remove patches forwarded from Microsoft Outlook to a Linux
email account.

Signed-off-by: Matthew Wilcox <mawil...@microsoft.com>

Also add a test showing the kind of message that the current code doesn't handle, and that this commit addresses.

---
 mailinfo.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mailinfo.c b/mailinfo.c
index 2059704a8..fc1275532 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -332,7 +332,7 @@ static void cleanup_subject(struct mailinfo *mi, struct 
strbuf *subject)

 #define MAX_HDR_PARSED 10
 static const char *header[MAX_HDR_PARSED] = {
-       "From","Subject","Date",
+       "From","Subject","Date","Sent","To",

Are these extra headers used in both the "real" e-mail headers and the in-body headers, or only one of them? (If the latter, they should probably be handled only in the relevant function - my previous patches to this file were in that direction too, if I remember correctly.) Also, I suspect that these will have to be handled differently to the other 3, but that will be clearer when you add the test with an example message.

 };

 static inline int cmp_header(const struct strbuf *line, const char *hdr)
@@ -685,6 +685,13 @@ static int is_scissors_line(const char *line)
                        c++;
                        continue;
                }
+               if (!memcmp(c, "Original Message", 16)) {

1) You can use starts_with or skip_prefix.
2) This seems vulnerable to false positives. If "Original Message" always follows a certain kind of line, it might be better to check for that. (Again, it will be clearer when we have an example message.)

+                       in_perforation = 1;
+                       perforation += 16;
+                       scissors += 16;
+                       c += 15;

Why 15? Also, can skip_prefix avoid these magic numbers?

+                       continue;
+               }
                in_perforation = 0;
        }


Reply via email to