@@ -19,12 +19,13 @@ struct mailinfo {
1919 struct strbuf email ;
2020 int keep_subject ;
2121 int keep_non_patch_brackets_in_subject ;
22+ int add_message_id ;
2223
24+ char * message_id ;
2325 int patch_lines ;
2426 int filter_stage ; /* still reading log or are we copying patch? */
2527 int header_stage ; /* still checking in-body headers? */
2628};
27- static char * message_id ;
2829
2930static enum {
3031 TE_DONTCARE , TE_QP , TE_BASE64
@@ -33,7 +34,6 @@ static enum {
3334static struct strbuf charset = STRBUF_INIT ;
3435static struct strbuf * * p_hdr_data , * * s_hdr_data ;
3536static int use_scissors ;
36- static int add_message_id ;
3737static int use_inbody_headers = 1 ;
3838
3939#define MAX_BOUNDARIES 5
@@ -216,10 +216,10 @@ static void handle_content_type(struct strbuf *line)
216216 }
217217}
218218
219- static void handle_message_id (const struct strbuf * line )
219+ static void handle_message_id (struct mailinfo * mi , const struct strbuf * line )
220220{
221- if (add_message_id )
222- message_id = strdup (line -> buf );
221+ if (mi -> add_message_id )
222+ mi -> message_id = strdup (line -> buf );
223223}
224224
225225static void handle_content_transfer_encoding (const struct strbuf * line )
@@ -476,11 +476,13 @@ static void decode_header(struct strbuf *it)
476476 strbuf_release (& piecebuf );
477477}
478478
479- static int check_header (const struct strbuf * line ,
480- struct strbuf * hdr_data [], int overwrite )
479+ static int check_header (struct mailinfo * mi ,
480+ const struct strbuf * line ,
481+ struct strbuf * hdr_data [], int overwrite )
481482{
482483 int i , ret = 0 , len ;
483484 struct strbuf sb = STRBUF_INIT ;
485+
484486 /* search for the interesting parts */
485487 for (i = 0 ; header [i ]; i ++ ) {
486488 int len = strlen (header [i ]);
@@ -518,7 +520,7 @@ static int check_header(const struct strbuf *line,
518520 len = strlen ("Message-Id: " );
519521 strbuf_add (& sb , line -> buf + len , line -> len - len );
520522 decode_header (& sb );
521- handle_message_id (& sb );
523+ handle_message_id (mi , & sb );
522524 ret = 1 ;
523525 goto check_header_out ;
524526 }
@@ -662,7 +664,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
662664 }
663665
664666 if (use_inbody_headers && mi -> header_stage ) {
665- mi -> header_stage = check_header (line , s_hdr_data , 0 );
667+ mi -> header_stage = check_header (mi , line , s_hdr_data , 0 );
666668 if (mi -> header_stage )
667669 return 0 ;
668670 } else
@@ -696,8 +698,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
696698 }
697699
698700 if (patchbreak (line )) {
699- if (message_id )
700- fprintf (cmitmsg , "Message-Id: %s\n" , message_id );
701+ if (mi -> message_id )
702+ fprintf (cmitmsg , "Message-Id: %s\n" , mi -> message_id );
701703 fclose (cmitmsg );
702704 cmitmsg = NULL ;
703705 return 1 ;
@@ -840,7 +842,7 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
840842
841843 /* slurp in this section's info */
842844 while (read_one_header_line (line , mi -> input ))
843- check_header (line , p_hdr_data , 0 );
845+ check_header (mi , line , p_hdr_data , 0 );
844846
845847 strbuf_release (& newline );
846848 /* replenish line */
@@ -994,7 +996,7 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
994996
995997 /* process the email header */
996998 while (read_one_header_line (& line , mi -> input ))
997- check_header (& line , p_hdr_data , 1 );
999+ check_header (mi , & line , p_hdr_data , 1 );
9981000
9991001 handle_body (mi , & line );
10001002 fclose (patchfile );
@@ -1029,6 +1031,7 @@ static void clear_mailinfo(struct mailinfo *mi)
10291031{
10301032 strbuf_release (& mi -> name );
10311033 strbuf_release (& mi -> email );
1034+ free (mi -> message_id );
10321035}
10331036
10341037static const char mailinfo_usage [] =
@@ -1054,7 +1057,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10541057 else if (!strcmp (argv [1 ], "-b" ))
10551058 mi .keep_non_patch_brackets_in_subject = 1 ;
10561059 else if (!strcmp (argv [1 ], "-m" ) || !strcmp (argv [1 ], "--message-id" ))
1057- add_message_id = 1 ;
1060+ mi . add_message_id = 1 ;
10581061 else if (!strcmp (argv [1 ], "-u" ))
10591062 metainfo_charset = def_charset ;
10601063 else if (!strcmp (argv [1 ], "-n" ))
0 commit comments