@@ -19,12 +19,13 @@ struct mailinfo {
19
19
struct strbuf email ;
20
20
int keep_subject ;
21
21
int keep_non_patch_brackets_in_subject ;
22
+ int add_message_id ;
22
23
24
+ char * message_id ;
23
25
int patch_lines ;
24
26
int filter_stage ; /* still reading log or are we copying patch? */
25
27
int header_stage ; /* still checking in-body headers? */
26
28
};
27
- static char * message_id ;
28
29
29
30
static enum {
30
31
TE_DONTCARE , TE_QP , TE_BASE64
@@ -33,7 +34,6 @@ static enum {
33
34
static struct strbuf charset = STRBUF_INIT ;
34
35
static struct strbuf * * p_hdr_data , * * s_hdr_data ;
35
36
static int use_scissors ;
36
- static int add_message_id ;
37
37
static int use_inbody_headers = 1 ;
38
38
39
39
#define MAX_BOUNDARIES 5
@@ -216,10 +216,10 @@ static void handle_content_type(struct strbuf *line)
216
216
}
217
217
}
218
218
219
- static void handle_message_id (const struct strbuf * line )
219
+ static void handle_message_id (struct mailinfo * mi , const struct strbuf * line )
220
220
{
221
- if (add_message_id )
222
- message_id = strdup (line -> buf );
221
+ if (mi -> add_message_id )
222
+ mi -> message_id = strdup (line -> buf );
223
223
}
224
224
225
225
static void handle_content_transfer_encoding (const struct strbuf * line )
@@ -476,11 +476,13 @@ static void decode_header(struct strbuf *it)
476
476
strbuf_release (& piecebuf );
477
477
}
478
478
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 )
481
482
{
482
483
int i , ret = 0 , len ;
483
484
struct strbuf sb = STRBUF_INIT ;
485
+
484
486
/* search for the interesting parts */
485
487
for (i = 0 ; header [i ]; i ++ ) {
486
488
int len = strlen (header [i ]);
@@ -518,7 +520,7 @@ static int check_header(const struct strbuf *line,
518
520
len = strlen ("Message-Id: " );
519
521
strbuf_add (& sb , line -> buf + len , line -> len - len );
520
522
decode_header (& sb );
521
- handle_message_id (& sb );
523
+ handle_message_id (mi , & sb );
522
524
ret = 1 ;
523
525
goto check_header_out ;
524
526
}
@@ -662,7 +664,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
662
664
}
663
665
664
666
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 );
666
668
if (mi -> header_stage )
667
669
return 0 ;
668
670
} else
@@ -696,8 +698,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
696
698
}
697
699
698
700
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 );
701
703
fclose (cmitmsg );
702
704
cmitmsg = NULL ;
703
705
return 1 ;
@@ -840,7 +842,7 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
840
842
841
843
/* slurp in this section's info */
842
844
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 );
844
846
845
847
strbuf_release (& newline );
846
848
/* replenish line */
@@ -994,7 +996,7 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
994
996
995
997
/* process the email header */
996
998
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 );
998
1000
999
1001
handle_body (mi , & line );
1000
1002
fclose (patchfile );
@@ -1029,6 +1031,7 @@ static void clear_mailinfo(struct mailinfo *mi)
1029
1031
{
1030
1032
strbuf_release (& mi -> name );
1031
1033
strbuf_release (& mi -> email );
1034
+ free (mi -> message_id );
1032
1035
}
1033
1036
1034
1037
static const char mailinfo_usage [] =
@@ -1054,7 +1057,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1054
1057
else if (!strcmp (argv [1 ], "-b" ))
1055
1058
mi .keep_non_patch_brackets_in_subject = 1 ;
1056
1059
else if (!strcmp (argv [1 ], "-m" ) || !strcmp (argv [1 ], "--message-id" ))
1057
- add_message_id = 1 ;
1060
+ mi . add_message_id = 1 ;
1058
1061
else if (!strcmp (argv [1 ], "-u" ))
1059
1062
metainfo_charset = def_charset ;
1060
1063
else if (!strcmp (argv [1 ], "-n" ))
0 commit comments