@@ -15,6 +15,7 @@ static const char *metainfo_charset;
1515static struct strbuf line = STRBUF_INIT ;
1616static struct strbuf name = STRBUF_INIT ;
1717static struct strbuf email = STRBUF_INIT ;
18+ static char * message_id ;
1819
1920static enum {
2021 TE_DONTCARE , TE_QP , TE_BASE64
@@ -24,6 +25,7 @@ static struct strbuf charset = STRBUF_INIT;
2425static int patch_lines ;
2526static struct strbuf * * p_hdr_data , * * s_hdr_data ;
2627static int use_scissors ;
28+ static int add_message_id ;
2729static int use_inbody_headers = 1 ;
2830
2931#define MAX_HDR_PARSED 10
@@ -198,6 +200,12 @@ static void handle_content_type(struct strbuf *line)
198200 }
199201}
200202
203+ static void handle_message_id (const struct strbuf * line )
204+ {
205+ if (add_message_id )
206+ message_id = strdup (line -> buf );
207+ }
208+
201209static void handle_content_transfer_encoding (const struct strbuf * line )
202210{
203211 if (strcasestr (line -> buf , "base64" ))
@@ -342,6 +350,14 @@ static int check_header(const struct strbuf *line,
342350 ret = 1 ;
343351 goto check_header_out ;
344352 }
353+ if (cmp_header (line , "Message-Id" )) {
354+ len = strlen ("Message-Id: " );
355+ strbuf_add (& sb , line -> buf + len , line -> len - len );
356+ decode_header (& sb );
357+ handle_message_id (& sb );
358+ ret = 1 ;
359+ goto check_header_out ;
360+ }
345361
346362 /* for inbody stuff */
347363 if (starts_with (line -> buf , ">From" ) && isspace (line -> buf [5 ])) {
@@ -816,6 +832,8 @@ static int handle_commit_msg(struct strbuf *line)
816832 }
817833
818834 if (patchbreak (line )) {
835+ if (message_id )
836+ fprintf (cmitmsg , "Message-Id: %s\n" , message_id );
819837 fclose (cmitmsg );
820838 cmitmsg = NULL ;
821839 return 1 ;
@@ -1013,7 +1031,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)
10131031}
10141032
10151033static const char mailinfo_usage [] =
1016- "git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info" ;
1034+ "git mailinfo [-k|-b] [-m | --message-id] [- u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info" ;
10171035
10181036int cmd_mailinfo (int argc , const char * * argv , const char * prefix )
10191037{
@@ -1032,6 +1050,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10321050 keep_subject = 1 ;
10331051 else if (!strcmp (argv [1 ], "-b" ))
10341052 keep_non_patch_brackets_in_subject = 1 ;
1053+ else if (!strcmp (argv [1 ], "-m" ) || !strcmp (argv [1 ], "--message-id" ))
1054+ add_message_id = 1 ;
10351055 else if (!strcmp (argv [1 ], "-u" ))
10361056 metainfo_charset = def_charset ;
10371057 else if (!strcmp (argv [1 ], "-n" ))
0 commit comments