send: fix draftfolder support; add testsuite
* examples/mta.c (mta_send): Don't print trailing spaces instead of empty lines. * mh/send.c: Redo draftfolder support. (read_mts_profile): If MTSTAILOR environment variable is set, it names the mtstailor file to use instead of the standard ones. * mh/tests/send.at: New file. * mh/tests/Makefile.am (TESTSUITE_AT): Add send.at * mh/tests/testsuite.at (MH_SETUP): Set MTSTAILOR. (MH_MTSTAILOR): New macro Include send.at
Showing
5 changed files
with
296 additions
and
60 deletions
... | @@ -348,7 +348,9 @@ mta_send (mu_message_t msg) | ... | @@ -348,7 +348,9 @@ mta_send (mu_message_t msg) |
348 | { | 348 | { |
349 | if (newline) | 349 | if (newline) |
350 | { | 350 | { |
351 | fprintf (diag, "%4lu: ", (unsigned long) line); | 351 | fprintf (diag, "%4lu:", (unsigned long) line); |
352 | if (buffer[i] != '\n') | ||
353 | fputc (' ', diag); | ||
352 | newline = 0; | 354 | newline = 0; |
353 | } | 355 | } |
354 | fputc (buffer[i], diag); | 356 | fputc (buffer[i], diag); |
... | @@ -837,4 +839,3 @@ mta_smtp (int argc, char **argv) | ... | @@ -837,4 +839,3 @@ mta_smtp (int argc, char **argv) |
837 | 839 | ||
838 | return 0; | 840 | return 0; |
839 | } | 841 | } |
840 | ... | ... |
... | @@ -101,7 +101,8 @@ struct mh_option mh_option[] = { | ... | @@ -101,7 +101,8 @@ struct mh_option mh_option[] = { |
101 | }; | 101 | }; |
102 | 102 | ||
103 | static int use_draft; /* Use the prepared draft */ | 103 | static int use_draft; /* Use the prepared draft */ |
104 | static const char *draft_folder; /* Use this draft folder */ | 104 | static const char *draftfolder; /* Use this draft folder */ |
105 | static char *draftmessage = "cur"; | ||
105 | static int reformat_recipients; /* --format option */ | 106 | static int reformat_recipients; /* --format option */ |
106 | static int forward_notice; /* Forward the failure notice to the sender, | 107 | static int forward_notice; /* Forward the failure notice to the sender, |
107 | --forward flag */ | 108 | --forward flag */ |
... | @@ -133,11 +134,6 @@ opt_handler (int key, char *arg, struct argp_state *state) | ... | @@ -133,11 +134,6 @@ opt_handler (int key, char *arg, struct argp_state *state) |
133 | 134 | ||
134 | switch (key) | 135 | switch (key) |
135 | { | 136 | { |
136 | case ARGP_KEY_INIT: | ||
137 | draft_folder = mh_global_profile_get ("Draft-Folder", | ||
138 | mu_folder_directory ()); | ||
139 | break; | ||
140 | |||
141 | case ARG_ALIAS: | 137 | case ARG_ALIAS: |
142 | mh_alias_read (arg, 1); | 138 | mh_alias_read (arg, 1); |
143 | break; | 139 | break; |
... | @@ -156,17 +152,15 @@ opt_handler (int key, char *arg, struct argp_state *state) | ... | @@ -156,17 +152,15 @@ opt_handler (int key, char *arg, struct argp_state *state) |
156 | break; | 152 | break; |
157 | 153 | ||
158 | case ARG_DRAFTFOLDER: | 154 | case ARG_DRAFTFOLDER: |
159 | draft_folder = arg; | 155 | draftfolder = arg; |
160 | break; | 156 | break; |
161 | 157 | ||
162 | case ARG_NODRAFTFOLDER: | 158 | case ARG_NODRAFTFOLDER: |
163 | draft_folder = NULL; | 159 | draftfolder = NULL; |
164 | break; | 160 | break; |
165 | 161 | ||
166 | case ARG_DRAFTMESSAGE: | 162 | case ARG_DRAFTMESSAGE: |
167 | if (!draft_folder) | 163 | draftmessage = arg; |
168 | draft_folder = mh_global_profile_get ("Draft-Folder", | ||
169 | mu_folder_directory ()); | ||
170 | break; | 164 | break; |
171 | 165 | ||
172 | case ARG_FILTER: | 166 | case ARG_FILTER: |
... | @@ -295,7 +289,7 @@ check_file (char *name) | ... | @@ -295,7 +289,7 @@ check_file (char *name) |
295 | { | 289 | { |
296 | struct list_elt *elt; | 290 | struct list_elt *elt; |
297 | mu_message_t msg; | 291 | mu_message_t msg; |
298 | char *file_name = mh_expand_name (draft_folder, name, 0); | 292 | char *file_name = mh_expand_name (draftfolder, name, 0); |
299 | 293 | ||
300 | msg = mh_file_to_message (NULL, file_name); | 294 | msg = mh_file_to_message (NULL, file_name); |
301 | if (!msg) | 295 | if (!msg) |
... | @@ -322,6 +316,12 @@ read_mts_profile () | ... | @@ -322,6 +316,12 @@ read_mts_profile () |
322 | const char *p; | 316 | const char *p; |
323 | char *hostname = NULL; | 317 | char *hostname = NULL; |
324 | int rc; | 318 | int rc; |
319 | |||
320 | name = getenv ("MTSTAILOR"); | ||
321 | if (name) | ||
322 | mts_profile = mh_read_property_file (name, 1); | ||
323 | else | ||
324 | { | ||
325 | mu_property_t local_profile; | 325 | mu_property_t local_profile; |
326 | 326 | ||
327 | name = mh_expand_name (MHLIBDIR, "mtstailor", 0); | 327 | name = mh_expand_name (MHLIBDIR, "mtstailor", 0); |
... | @@ -332,6 +332,7 @@ read_mts_profile () | ... | @@ -332,6 +332,7 @@ read_mts_profile () |
332 | 332 | ||
333 | mh_property_merge (mts_profile, local_profile); | 333 | mh_property_merge (mts_profile, local_profile); |
334 | mu_property_destroy (&local_profile); | 334 | mu_property_destroy (&local_profile); |
335 | } | ||
335 | 336 | ||
336 | rc = mu_property_aget_value (mts_profile, "localname", &hostname); | 337 | rc = mu_property_aget_value (mts_profile, "localname", &hostname); |
337 | if (rc == MU_ERR_NOENT) | 338 | if (rc == MU_ERR_NOENT) |
... | @@ -343,7 +344,7 @@ read_mts_profile () | ... | @@ -343,7 +344,7 @@ read_mts_profile () |
343 | exit (1); | 344 | exit (1); |
344 | } | 345 | } |
345 | } | 346 | } |
346 | else | 347 | else if (rc) |
347 | { | 348 | { |
348 | mu_diag_funcall (MU_DIAG_ERROR, "mu_profile_aget_value", "localname", rc); | 349 | mu_diag_funcall (MU_DIAG_ERROR, "mu_profile_aget_value", "localname", rc); |
349 | exit (1); | 350 | exit (1); |
... | @@ -738,42 +739,13 @@ _action_send (void *item, void *data) | ... | @@ -738,42 +739,13 @@ _action_send (void *item, void *data) |
738 | return 0; | 739 | return 0; |
739 | } | 740 | } |
740 | 741 | ||
741 | static int | ||
742 | do_send (int argc, char **argv) | ||
743 | { | ||
744 | int i, rc; | ||
745 | char *p; | ||
746 | |||
747 | /* Verify all arguments */ | ||
748 | for (i = 0; i < argc; i++) | ||
749 | if (check_file (argv[i])) | ||
750 | return 1; | ||
751 | |||
752 | /* Process the mtstailor file and detach from the console if | ||
753 | required */ | ||
754 | read_mts_profile (); | ||
755 | |||
756 | if (background && daemon (0, 0) < 0) | ||
757 | { | ||
758 | mu_error (_("cannot switch to background: %s"), mu_strerror (errno)); | ||
759 | return 1; | ||
760 | } | ||
761 | |||
762 | /* Prepend url specifier to the folder dir. We won't need this | ||
763 | when the default format becomes configurable */ | ||
764 | mu_asprintf (&p, "mh:%s", mu_folder_directory ()); | ||
765 | mu_set_folder_directory (p); | ||
766 | free (p); | ||
767 | |||
768 | /* Finally, do the work */ | ||
769 | rc = mu_list_do (mesg_list, _action_send, NULL); | ||
770 | return rc; | ||
771 | } | ||
772 | |||
773 | int | 742 | int |
774 | main (int argc, char **argv) | 743 | main (int argc, char **argv) |
775 | { | 744 | { |
745 | mu_mailbox_t mbox = NULL; | ||
776 | int index; | 746 | int index; |
747 | char *p; | ||
748 | int rc; | ||
777 | 749 | ||
778 | MU_APP_INIT_NLS (); | 750 | MU_APP_INIT_NLS (); |
779 | 751 | ||
... | @@ -786,28 +758,51 @@ main (int argc, char **argv) | ... | @@ -786,28 +758,51 @@ main (int argc, char **argv) |
786 | argc -= index; | 758 | argc -= index; |
787 | argv += index; | 759 | argv += index; |
788 | 760 | ||
789 | if (argc == 0) | 761 | if (draftfolder) |
790 | { | ||
791 | struct stat st; | ||
792 | static char *xargv[2]; | ||
793 | |||
794 | if (draft_folder) | ||
795 | { | 762 | { |
796 | mh_msgset_t msgset; | 763 | mh_msgset_t msgset; |
797 | mu_mailbox_t mbox; | ||
798 | mu_url_t url; | 764 | mu_url_t url; |
799 | const char *path; | 765 | const char *path; |
766 | size_t i; | ||
800 | 767 | ||
801 | mbox = mh_open_folder (draft_folder, 1); | 768 | mbox = mh_open_folder (draftfolder, 1); |
802 | mh_msgset_parse (mbox, &msgset, argc, argv, "cur"); | 769 | mh_msgset_parse (mbox, &msgset, argc, argv, draftmessage); |
803 | mu_mailbox_get_url (mbox, &url); | 770 | mu_mailbox_get_url (mbox, &url); |
804 | mu_url_sget_path (url, &path); | 771 | mu_url_sget_path (url, &path); |
805 | xargv[0] = mu_make_file_name (path, | 772 | if ((rc = mu_list_create (&mesg_list))) |
806 | mu_umaxtostr (0, msgset.list[0])); | 773 | { |
807 | mu_mailbox_destroy (&mbox); | 774 | mu_error (_("cannot create message list: %s"), mu_strerror (rc)); |
775 | exit (1); | ||
776 | } | ||
777 | for (i = 0; i < msgset.count; i++) | ||
778 | { | ||
779 | struct list_elt *elt; | ||
780 | size_t uid; | ||
781 | |||
782 | elt = xmalloc (sizeof *elt); | ||
783 | mu_mailbox_get_message (mbox, msgset.list[i], &elt->msg); | ||
784 | mu_message_get_uid (elt->msg, &uid); | ||
785 | elt->file_name = | ||
786 | mu_make_file_name (path, mu_umaxtostr (0, uid)); | ||
787 | rc = mu_list_append (mesg_list, elt); | ||
788 | if (rc) | ||
789 | { | ||
790 | mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", NULL, rc); | ||
791 | exit (1); | ||
792 | } | ||
793 | } | ||
794 | |||
808 | mh_msgset_free (&msgset); | 795 | mh_msgset_free (&msgset); |
809 | } | 796 | } |
810 | else | 797 | else |
798 | { | ||
799 | int i; | ||
800 | |||
801 | if (argc == 0) | ||
802 | { | ||
803 | char *xargv[2]; | ||
804 | struct stat st; | ||
805 | |||
811 | xargv[0] = mh_draft_name (); | 806 | xargv[0] = mh_draft_name (); |
812 | 807 | ||
813 | if (stat (xargv[0], &st)) | 808 | if (stat (xargv[0], &st)) |
... | @@ -822,6 +817,31 @@ main (int argc, char **argv) | ... | @@ -822,6 +817,31 @@ main (int argc, char **argv) |
822 | argv = xargv; | 817 | argv = xargv; |
823 | argc = 1; | 818 | argc = 1; |
824 | } | 819 | } |
820 | for (i = 0; i < argc; i++) | ||
821 | if (check_file (argv[i])) | ||
822 | return 1; | ||
823 | } | ||
825 | 824 | ||
826 | return do_send (argc, argv); | 825 | /* Process the mtstailor file and detach from the console if |
826 | required */ | ||
827 | read_mts_profile (); | ||
828 | |||
829 | if (background && daemon (0, 0) < 0) | ||
830 | { | ||
831 | mu_error (_("cannot switch to background: %s"), mu_strerror (errno)); | ||
832 | return 1; | ||
833 | } | ||
834 | |||
835 | /* Prepend url specifier to the folder dir. We won't need this | ||
836 | when the default format becomes configurable */ | ||
837 | mu_asprintf (&p, "mh:%s", mu_folder_directory ()); | ||
838 | mu_set_folder_directory (p); | ||
839 | free (p); | ||
840 | |||
841 | /* Finally, do the work */ | ||
842 | rc = mu_list_do (mesg_list, _action_send, NULL); | ||
843 | |||
844 | mu_mailbox_destroy (&mbox); | ||
845 | return !!rc; | ||
827 | } | 846 | } |
847 | ... | ... |
mh/tests/send.at
0 → 100644
1 | # This file is part of GNU Mailutils. -*- Autotest -*- | ||
2 | # Copyright (C) 2010 Free Software Foundation, Inc. | ||
3 | # | ||
4 | # GNU Mailutils is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 3, or (at | ||
7 | # your option) any later version. | ||
8 | # | ||
9 | # GNU Mailutils is distributed in the hope that it will be useful, but | ||
10 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | # General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | m4_pushdef([MH_KEYWORDS],[send]) | ||
18 | |||
19 | MH_CHECK([send file],[send00 send-file],[ | ||
20 | MH_MTSTAILOR() | ||
21 | AT_DATA([input], | ||
22 | [From: mhtester@example.net | ||
23 | To: gray@example.net | ||
24 | Subject: Send file test | ||
25 | ------ | ||
26 | Message body | ||
27 | ]) | ||
28 | send ./input || exit $? | ||
29 | sed 's/: Date: .*/: Date: now/' $MTA_DIAG | ||
30 | find . -name ,input | ||
31 | ], | ||
32 | [0], | ||
33 | [ENVELOPE FROM: mhtester@example.net | ||
34 | ENVELOPE TO: <gray@example.net> | ||
35 | 0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) | ||
36 | 1: Date: now | ||
37 | 2: From: mhtester@example.net | ||
38 | 3: To: <gray@example.net> | ||
39 | 4: Subject: Send file test | ||
40 | 5: | ||
41 | 6: Message body | ||
42 | END OF MESSAGE | ||
43 | ./,input | ||
44 | ]) | ||
45 | |||
46 | MH_CHECK([send files],[send01 send-files],[ | ||
47 | MH_MTSTAILOR() | ||
48 | AT_DATA([input.1], | ||
49 | [From: mhtester@example.net | ||
50 | To: gray@example.net | ||
51 | Subject: Send file test 1 | ||
52 | ------ | ||
53 | Message body 1 | ||
54 | ]) | ||
55 | |||
56 | AT_DATA([input.2], | ||
57 | [From: mhtester@example.net | ||
58 | To: gray@example.org | ||
59 | Subject: Send file test 2 | ||
60 | ------ | ||
61 | Message body 2 | ||
62 | ]) | ||
63 | |||
64 | MTA_APPEND=1 | ||
65 | export MTA_APPEND | ||
66 | |||
67 | send ./input.1 ./input.2 || exit $? | ||
68 | sed 's/: Date: .*/: Date: now/' $MTA_DIAG | ||
69 | find . -name ',input.[[12]]' | ||
70 | ], | ||
71 | [0], | ||
72 | [ENVELOPE FROM: mhtester@example.net | ||
73 | ENVELOPE TO: <gray@example.net> | ||
74 | 0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) | ||
75 | 1: Date: now | ||
76 | 2: From: mhtester@example.net | ||
77 | 3: To: <gray@example.net> | ||
78 | 4: Subject: Send file test 1 | ||
79 | 5: | ||
80 | 6: Message body 1 | ||
81 | END OF MESSAGE | ||
82 | ENVELOPE FROM: mhtester@example.net | ||
83 | ENVELOPE TO: <gray@example.org> | ||
84 | 0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) | ||
85 | 1: Date: now | ||
86 | 2: From: mhtester@example.net | ||
87 | 3: To: <gray@example.org> | ||
88 | 4: Subject: Send file test 2 | ||
89 | 5: | ||
90 | 6: Message body 2 | ||
91 | END OF MESSAGE | ||
92 | ./,input.1 | ||
93 | ./,input.2 | ||
94 | ]) | ||
95 | |||
96 | MH_CHECK([send -draft],[send02 send-draft],[ | ||
97 | MH_MTSTAILOR() | ||
98 | AT_DATA([Mail/draft], | ||
99 | [From: mhtester@example.net | ||
100 | To: gray@example.net | ||
101 | Subject: Send file test | ||
102 | ------ | ||
103 | Message body | ||
104 | ]) | ||
105 | send -draft || exit $? | ||
106 | sed 's/: Date: .*/: Date: now/' $MTA_DIAG | ||
107 | echo == Mail/,draft == | ||
108 | cat Mail/,draft | ||
109 | ], | ||
110 | [0], | ||
111 | [ENVELOPE FROM: mhtester@example.net | ||
112 | ENVELOPE TO: <gray@example.net> | ||
113 | 0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) | ||
114 | 1: Date: now | ||
115 | 2: From: mhtester@example.net | ||
116 | 3: To: <gray@example.net> | ||
117 | 4: Subject: Send file test | ||
118 | 5: | ||
119 | 6: Message body | ||
120 | END OF MESSAGE | ||
121 | == Mail/,draft == | ||
122 | From: mhtester@example.net | ||
123 | To: gray@example.net | ||
124 | Subject: Send file test | ||
125 | ------ | ||
126 | Message body | ||
127 | ]) | ||
128 | |||
129 | MH_CHECK([send -draftfolder], | ||
130 | [send03 send-draftfolder draftfolder draftmessage],[ | ||
131 | MH_MTSTAILOR() | ||
132 | mkdir Mail/drafts | ||
133 | AT_DATA([Mail/drafts/2], | ||
134 | [From: mhtester@example.net | ||
135 | To: gray@example.net | ||
136 | Subject: Draftfolder test | ||
137 | |||
138 | Message body | ||
139 | ]) | ||
140 | echo "cur: 2" > Mail/drafts/.mh_sequences | ||
141 | |||
142 | send -draftfolder +drafts || echo $? | ||
143 | sed 's/: Date: .*/: Date: now/' $MTA_DIAG | ||
144 | ], | ||
145 | [0], | ||
146 | [ENVELOPE FROM: mhtester@example.net | ||
147 | ENVELOPE TO: <gray@example.net> | ||
148 | 0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) | ||
149 | 1: Date: now | ||
150 | 2: From: mhtester@example.net | ||
151 | 3: To: <gray@example.net> | ||
152 | 4: Subject: Draftfolder test | ||
153 | 5: | ||
154 | 6: Message body | ||
155 | END OF MESSAGE | ||
156 | ]) | ||
157 | |||
158 | MH_CHECK([send -draftmessage], | ||
159 | [send04 send-draftmessage draftfolder draftmessage],[ | ||
160 | MH_MTSTAILOR() | ||
161 | mkdir Mail/drafts | ||
162 | AT_DATA([Mail/drafts/2], | ||
163 | [From: mhtester@example.net | ||
164 | To: gray@example.net | ||
165 | Subject: Draftfolder test | ||
166 | |||
167 | Message body | ||
168 | ]) | ||
169 | |||
170 | AT_DATA([Mail/drafts/5], | ||
171 | [From: mhtester@example.net | ||
172 | To: gray@example.org | ||
173 | Subject: Draftmessage test | ||
174 | |||
175 | Message body | ||
176 | ]) | ||
177 | echo "cur: 2" > Mail/drafts/.mh_sequences | ||
178 | |||
179 | send -draftfolder +drafts -draftmessage 5 || echo $? | ||
180 | sed 's/: Date: .*/: Date: now/' $MTA_DIAG | ||
181 | ], | ||
182 | [0], | ||
183 | [ENVELOPE FROM: mhtester@example.net | ||
184 | ENVELOPE TO: <gray@example.org> | ||
185 | 0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) | ||
186 | 1: Date: now | ||
187 | 2: From: mhtester@example.net | ||
188 | 3: To: <gray@example.org> | ||
189 | 4: Subject: Draftmessage test | ||
190 | 5: | ||
191 | 6: Message body | ||
192 | END OF MESSAGE | ||
193 | ]) | ||
194 | |||
195 | m4_popdef([MH_KEYWORDS]) | ||
196 | |||
197 | # End of send.at |
... | @@ -25,9 +25,25 @@ cat > $MH <<EOT | ... | @@ -25,9 +25,25 @@ cat > $MH <<EOT |
25 | Path: $curdir/Mail | 25 | Path: $curdir/Mail |
26 | mhetcdir: $abs_top_srcdir/mh/etc | 26 | mhetcdir: $abs_top_srcdir/mh/etc |
27 | EOT | 27 | EOT |
28 | MTSTAILOR=$curdir/mtstailor | ||
29 | export MTSTAILOR | ||
28 | exec <&- | 30 | exec <&- |
29 | ]) | 31 | ]) |
30 | 32 | ||
33 | m4_define([MH_MTSTAILOR],[ | ||
34 | cat > $MTSTAILOR <<EOT | ||
35 | localname: darkstar | ||
36 | localdomain: example.net | ||
37 | username: mhtester | ||
38 | url: sendmail://$abs_top_srcdir/examples/mta | ||
39 | EOT | ||
40 | |||
41 | MTA_DIAG=$curdir/mta.diag | ||
42 | export MTA_DIAG | ||
43 | MTA_DOMAIN=example.net | ||
44 | export MTA_DOMAIN | ||
45 | ]) | ||
46 | |||
31 | m4_define([MH_KEYWORDS]) | 47 | m4_define([MH_KEYWORDS]) |
32 | 48 | ||
33 | dnl -------------------------------------------------------------- | 49 | dnl -------------------------------------------------------------- |
... | @@ -64,3 +80,4 @@ m4_include([comp.at]) | ... | @@ -64,3 +80,4 @@ m4_include([comp.at]) |
64 | m4_include([forw.at]) | 80 | m4_include([forw.at]) |
65 | m4_include([repl.at]) | 81 | m4_include([repl.at]) |
66 | m4_include([mhn.at]) | 82 | m4_include([mhn.at]) |
83 | m4_include([send.at]) | ... | ... |
-
Please register or sign in to post a comment