2 ** send.c -- send a composed message
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
15 static struct swit switches[] = {
17 { "alias aliasfile", 0 },
21 { "filter filterfile", 0 },
55 extern int debugsw; /* from sendsbr.c */
62 extern char *altmsg; /* .. */
63 extern char *annotext;
64 extern char *distfile;
68 main(int argc, char **argv)
70 int msgp = 0, distsw = 0, vecp = 1;
72 char *cp, *maildir = NULL;
73 char buf[BUFSIZ], **ap, **argp, **arguments;
74 char *msgs[MAXARGS], *vec[MAXARGS];
79 setlocale(LC_ALL, "");
81 invo_name = mhbasename(argv[0]);
83 /* read user profile/context */
86 arguments = getarguments(invo_name, argc, argv, 1);
89 vec[vecp++] = "-library";
90 vec[vecp++] = getcpy(toabsdir("+"));
92 while ((cp = *argp++)) {
94 switch (smatch(++cp, switches)) {
96 ambigsw(cp, switches);
99 adios(NULL, "-%s unknown\n", cp);
102 snprintf(buf, sizeof(buf),
103 "%s [file] [switches]",
105 print_help(buf, switches, 1);
108 print_version(invo_name);
142 debugsw++; /* fall */
154 if (!(cp = *argp++) || *cp == '-')
155 adios(NULL, "missing argument to %s",
167 ** check for "Aliasfile:" profile entry
169 if ((cp = context_find("Aliasfile"))) {
172 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap;
174 vec[vecp++] = "-alias";
180 msgs[msgp++] = seq_cur;
181 maildir = toabsdir(draftfolder);
183 if (chdir(maildir) == NOTOK)
184 adios(maildir, "unable to change directory to");
186 /* read folder and create message structure */
187 if (!(mp = folder_read(draftfolder)))
188 adios(NULL, "unable to read draft folder %s", draftfolder);
190 /* check for empty folder */
192 adios(NULL, "no messages in draft folder %s", draftfolder);
194 /* parse all the message ranges/sequences and set SELECTED */
195 for (msgnum = 0; msgnum < msgp; msgnum++)
196 if (!m_convert(mp, msgs[msgnum]))
198 seq_setprev(mp); /* set the previous-sequence */
200 for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
201 if (is_selected(mp, msgnum)) {
202 msgs[msgp++] = getcpy(m_name(msgnum));
203 unset_exists(mp, msgnum);
207 mp->msgflags |= SEQMOD;
210 if (!(cp = getenv("SIGNATURE")) || !*cp)
211 if ((cp = context_find("signature")) && *cp)
212 m_putenv("SIGNATURE", cp);
214 for (msgnum = 0; msgnum < msgp; msgnum++)
215 if (stat(msgs[msgnum], &st) == NOTOK)
216 adios(msgs[msgnum], "unable to stat draft file");
218 if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
220 if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
222 if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
223 altmsg = NULL; /* used by dist interface - see below */
225 if ((cp = getenv("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) {
226 vec[vecp++] = "-dist";
227 distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
228 if (link(altmsg, distfile) == NOTOK) {
231 && errno != EISREMOTE
232 #endif /* EISREMOTE */
234 adios(distfile, "unable to link %s to",
237 distfile = getcpy(m_mktemp2(NULL, invo_name,
243 if ((in = open(altmsg, O_RDONLY)) == NOTOK)
244 adios(altmsg, "unable to open");
246 if ((out = creat(distfile,
247 (int) st.st_mode & 0777))
249 adios(distfile, "unable to write");
250 cpydata(in, out, altmsg, distfile);
259 if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
268 vec[0] = mhbasename(postproc);
271 for (msgnum = 0; msgnum < msgp; msgnum++) {
272 switch (sendsbr(vec, vecp, msgs[msgnum], &st, 1)) {
282 context_save(); /* save the context file */