71 |
{ 0 } |
{ 0 } |
72 |
}; |
}; |
73 |
|
|
|
static char *format_str = |
|
|
"To:\n" |
|
|
"cc:\n" |
|
|
"Subject:\n" |
|
|
"--------\n"; |
|
|
|
|
74 |
struct mh_whatnow_env wh_env = { 0 }; |
struct mh_whatnow_env wh_env = { 0 }; |
75 |
const char *formfile; |
const char *formfile; |
76 |
static int initial_edit = 1; |
static int initial_edit = 1; |
133 |
} |
} |
134 |
return 0; |
return 0; |
135 |
} |
} |
|
|
|
|
int |
|
|
check_draft_disposition (struct mh_whatnow_env *wh) |
|
|
{ |
|
|
struct stat st; |
|
|
int disp = DISP_REPLACE; |
|
|
|
|
|
/* First check if the draft exists */ |
|
|
if (stat (wh->draftfile, &st) == 0) |
|
|
{ |
|
|
if (use_draft) |
|
|
disp = DISP_USE; |
|
|
else |
|
|
{ |
|
|
printf (_("Draft \"%s\" exists (%lu bytes).\n"), |
|
|
wh->draftfile, (unsigned long) st.st_size); |
|
|
disp = mh_disposition (wh->draftfile); |
|
|
} |
|
|
} |
|
|
|
|
|
return disp; |
|
|
} |
|
136 |
|
|
137 |
int |
int |
138 |
copy_message (mailbox_t mbox, size_t n, const char *file) |
copy_message (mailbox_t mbox, size_t n, const char *file) |
205 |
if (!wh_env.draftfile) |
if (!wh_env.draftfile) |
206 |
wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0); |
wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0); |
207 |
|
|
208 |
switch (check_draft_disposition (&wh_env)) |
switch (check_draft_disposition (&wh_env, use_draft)) |
209 |
{ |
{ |
210 |
case DISP_QUIT: |
case DISP_QUIT: |
211 |
exit (0); |
exit (0); |
232 |
} |
} |
233 |
copy_message (mbox, msgset.list[0], wh_env.file); |
copy_message (mbox, msgset.list[0], wh_env.file); |
234 |
} |
} |
|
else if (formfile) |
|
|
{ |
|
|
if (mh_file_copy (formfile, wh_env.file) == 0) |
|
|
exit (1); |
|
|
} |
|
235 |
else |
else |
236 |
{ |
mh_comp_draft (formfile, "components", wh_env.file); |
|
int rc; |
|
|
stream_t stream; |
|
|
|
|
|
if ((rc = file_stream_create (&stream, |
|
|
wh_env.file, |
|
|
MU_STREAM_WRITE|MU_STREAM_CREAT)) != 0 |
|
|
|| (rc = stream_open (stream))) |
|
|
{ |
|
|
mh_error (_("cannot open output file \"%s\": %s"), |
|
|
wh_env.file, mu_strerror (rc)); |
|
|
exit (1); |
|
|
} |
|
|
|
|
|
rc = stream_sequential_write (stream, |
|
|
format_str, strlen (format_str)); |
|
|
stream_close (stream); |
|
|
stream_destroy (&stream, stream_get_owner (stream)); |
|
|
|
|
|
if (rc) |
|
|
{ |
|
|
mh_error (_("error writing to \"%s\": %s"), |
|
|
wh_env.file, mu_strerror (rc)); |
|
|
exit (1); |
|
|
} |
|
|
} |
|
237 |
} |
} |
238 |
|
|
239 |
/* Exit immediately if --build is given */ |
/* Exit immediately if --build is given */ |