summaryrefslogtreecommitdiff
path: root/mh/comp.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-11-22 16:49:51 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-11-22 16:49:51 +0200
commite34d8c168f9031dbfc2441006e0eb24182ef4389 (patch)
tree29f1c1493d550aa21845899c3b9c1828ea7187ec /mh/comp.c
parente6927c46013d391242d76b63cdb7b044d9ba8065 (diff)
downloadmailutils-e34d8c168f9031dbfc2441006e0eb24182ef4389.tar.gz
mailutils-e34d8c168f9031dbfc2441006e0eb24182ef4389.tar.bz2
mh: fix msgset parser and some more comp compatibility issues; provide testsuite for comp.
* mh/Makefile.am (bin_PROGRAMS): Add mhseq. * mh/comp.c (main): Rewrite to fix compatibility issues. * mh/mh.h (MH_MSGSET_UID): New define. (mh_msgset_t) <flags,size>: New members. * mh/mh_init.c (mh_draft_message): Bugfix: convert msgset to UIDs. * mh/mh_msgset.c: Rewrite from scratch. * mh/tests/comp.at: New file. * mh/tests/mhseq.at: New file. * mh/tests/Makefile.am (TESTSUITE_AT): Add comp.at, mhseq.at. * mh/tests/testsuite.at: Include comp.at and mhseq.at. * libmailutils/property/mhprop.c (_mh_prop_read_stream): Minor fix. Do remove empty lines. * mh/mh_whatnow.c (_whatnow): Detect EOF. (call_send): Quit after successful send.
Diffstat (limited to 'mh/comp.c')
-rw-r--r--mh/comp.c95
1 files changed, 59 insertions, 36 deletions
diff --git a/mh/comp.c b/mh/comp.c
index b882326ca..964baf463 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -80,6 +80,7 @@ static int build_only = 0; /* --build flag */
static int use_draft = 0; /* --use flag */
static char *draftmessage = "new";
static const char *draftfolder = NULL;
+static int folder_set; /* Folder is set on the command line */
static error_t
opt_handler (int key, char *arg, struct argp_state *state)
@@ -87,8 +88,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
switch (key)
{
case ARGP_KEY_INIT:
- draftfolder = mh_global_profile_get ("Draft-Folder",
- mu_folder_directory ());
+ draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
break;
@@ -106,6 +106,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
case ARG_FOLDER:
mh_set_current_folder (arg);
+ folder_set = 1;
break;
case ARG_FORM:
@@ -126,7 +127,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_FILE:
- wh_env.draftfile = mh_expand_name (NULL, arg, 0);
+ wh_env.file = mh_expand_name (NULL, arg, 0);
break;
case ARG_NODRAFTFOLDER:
@@ -197,7 +198,7 @@ main (int argc, char **argv)
mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
- if (wh_env.draftfile)
+ if (wh_env.file)
{
if (build_only)
{
@@ -205,68 +206,90 @@ main (int argc, char **argv)
exit (1);
}
}
+ else if (folder_set)
+ {
+ wh_env.file = mh_expand_name (NULL, "draft", 0);
+ }
else
{
if (build_only || !draftfolder)
- wh_env.file = mh_expand_name (NULL, "draft", 0);
+ {
+ switch (argc - index)
+ {
+ case 0:
+ wh_env.file = mh_expand_name (NULL, "draft", 0);
+ break;
+
+ case 1:
+ wh_env.file = mh_expand_name (NULL, argv[index], 0);
+ break;
+
+ default:
+ mu_error (_("only one message at a time!"));
+ return 1;
+ }
+ }
else if (draftfolder)
{
/* Comp accepts a `file', and it will, if given
`-draftfolder +folder' treat this arguments as `msg'. */
- if (index < argc)
+ if (use_draft || index < argc)
{
mh_msgset_t msgset;
mu_mailbox_t mbox;
mbox = mh_open_folder (draftfolder, 1);
- mh_msgset_parse (mbox, &msgset, argc - index, argv + index,
- "new");
+ mh_msgset_parse (mbox, &msgset,
+ argc - index, argv + index,
+ use_draft ? "cur" : "new");
mu_mailbox_destroy (&mbox);
if (msgset.count != 1)
{
mu_error (_("only one message at a time!"));
return 1;
}
+ mh_msgset_uids (mbox, &msgset);
draftmessage = mu_umaxtostr (0, msgset.list[0]);
mh_msgset_free (&msgset);
- index = argc;
}
if (mh_draft_message (draftfolder, draftmessage,
&wh_env.file))
return 1;
}
- wh_env.draftfile = wh_env.file;
}
-
- switch (check_draft_disposition (&wh_env, use_draft))
- {
- case DISP_QUIT:
- exit (0);
+ wh_env.draftfile = wh_env.file;
- case DISP_USE:
- break;
-
- case DISP_REPLACE:
- unlink (wh_env.draftfile);
-
- if (index < argc)
+ if (folder_set && index < argc)
+ {
+ mh_msgset_t msgset;
+ mu_mailbox_t mbox;
+
+ mbox = mh_open_folder (mh_current_folder (), 0);
+ mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
+ if (msgset.count != 1)
{
- mh_msgset_t msgset;
- mu_mailbox_t mbox;
+ mu_error (_("only one message at a time!"));
+ return 1;
+ }
+ unlink (wh_env.file);
+ copy_message (mbox, msgset.list[0], wh_env.file);
+ mu_mailbox_destroy (&mbox);
+ mh_msgset_free (&msgset);
+ }
+ else
+ {
+ switch (check_draft_disposition (&wh_env, use_draft))
+ {
+ case DISP_QUIT:
+ exit (0);
+
+ case DISP_USE:
+ break;
- mbox = mh_open_folder (mh_current_folder (), 0);
- mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
- if (msgset.count != 1)
- {
- mu_error (_("only one message at a time!"));
- return 1;
- }
- copy_message (mbox, msgset.list[0], wh_env.file);
- mu_mailbox_destroy (&mbox);
- mh_msgset_free (&msgset);
+ case DISP_REPLACE:
+ unlink (wh_env.draftfile);
+ mh_comp_draft (formfile, "components", wh_env.file);
}
- else
- mh_comp_draft (formfile, "components", wh_env.file);
}
/* Exit immediately if --build is given */

Return to:

Send suggestions and report system problems to the System administrator.