2727#include "notes-utils.h"
2828#include "rerere.h"
2929#include "prompt.h"
30+ #include "mailinfo.h"
3031
3132/**
3233 * Returns 1 if the file is empty or does not exist, 0 otherwise.
@@ -1258,58 +1259,61 @@ static void am_append_signoff(struct am_state *state)
12581259static int parse_mail (struct am_state * state , const char * mail )
12591260{
12601261 FILE * fp ;
1261- struct child_process cp = CHILD_PROCESS_INIT ;
12621262 struct strbuf sb = STRBUF_INIT ;
12631263 struct strbuf msg = STRBUF_INIT ;
12641264 struct strbuf author_name = STRBUF_INIT ;
12651265 struct strbuf author_date = STRBUF_INIT ;
12661266 struct strbuf author_email = STRBUF_INIT ;
12671267 int ret = 0 ;
1268+ struct mailinfo mi ;
12681269
1269- cp .git_cmd = 1 ;
1270- cp .in = xopen (mail , O_RDONLY , 0 );
1271- cp .out = xopen (am_path (state , "info" ), O_WRONLY | O_CREAT , 0777 );
1270+ setup_mailinfo (& mi );
12721271
1273- argv_array_push (& cp .args , "mailinfo" );
1274- argv_array_push (& cp .args , state -> utf8 ? "-u" : "-n" );
1272+ if (state -> utf8 )
1273+ mi .metainfo_charset = get_commit_output_encoding ();
1274+ else
1275+ mi .metainfo_charset = NULL ;
12751276
12761277 switch (state -> keep ) {
12771278 case KEEP_FALSE :
12781279 break ;
12791280 case KEEP_TRUE :
1280- argv_array_push ( & cp . args , "-k" ) ;
1281+ mi . keep_subject = 1 ;
12811282 break ;
12821283 case KEEP_NON_PATCH :
1283- argv_array_push ( & cp . args , "-b" ) ;
1284+ mi . keep_non_patch_brackets_in_subject = 1 ;
12841285 break ;
12851286 default :
12861287 die ("BUG: invalid value for state->keep" );
12871288 }
12881289
12891290 if (state -> message_id )
1290- argv_array_push ( & cp . args , "-m" ) ;
1291+ mi . add_message_id = 1 ;
12911292
12921293 switch (state -> scissors ) {
12931294 case SCISSORS_UNSET :
12941295 break ;
12951296 case SCISSORS_FALSE :
1296- argv_array_push ( & cp . args , "--no-scissors" ) ;
1297+ mi . use_scissors = 0 ;
12971298 break ;
12981299 case SCISSORS_TRUE :
1299- argv_array_push ( & cp . args , "--scissors" ) ;
1300+ mi . use_scissors = 1 ;
13001301 break ;
13011302 default :
13021303 die ("BUG: invalid value for state->scissors" );
13031304 }
13041305
1305- argv_array_push (& cp .args , am_path (state , "msg" ));
1306- argv_array_push (& cp .args , am_path (state , "patch" ));
1307-
1308- if (run_command (& cp ) < 0 )
1306+ mi .input = fopen (mail , "r" );
1307+ if (!mi .input )
1308+ die ("could not open input" );
1309+ mi .output = fopen (am_path (state , "info" ), "w" );
1310+ if (!mi .output )
1311+ die ("could not open output 'info'" );
1312+ if (mailinfo (& mi , am_path (state , "msg" ), am_path (state , "patch" )))
13091313 die ("could not parse patch" );
13101314
1311- close ( cp . in );
1312- close ( cp . out );
1315+ fclose ( mi . input );
1316+ fclose ( mi . output );
13131317
13141318 /* Extract message and author information */
13151319 fp = xfopen (am_path (state , "info" ), "r" );
@@ -1341,8 +1345,7 @@ static int parse_mail(struct am_state *state, const char *mail)
13411345 }
13421346
13431347 strbuf_addstr (& msg , "\n\n" );
1344- if (strbuf_read_file (& msg , am_path (state , "msg" ), 0 ) < 0 )
1345- die_errno (_ ("could not read '%s'" ), am_path (state , "msg" ));
1348+ strbuf_addbuf (& msg , & mi .log_message );
13461349 stripspace (& msg , 0 );
13471350
13481351 if (state -> signoff )
@@ -1366,6 +1369,7 @@ static int parse_mail(struct am_state *state, const char *mail)
13661369 strbuf_release (& author_email );
13671370 strbuf_release (& author_name );
13681371 strbuf_release (& sb );
1372+ clear_mailinfo (& mi );
13691373 return ret ;
13701374}
13711375
0 commit comments