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 },
49 { "width columns", 0 },
57 extern int debugsw; /* from sendsbr.c */
64 extern char *altmsg; /* .. */
65 extern char *annotext;
66 extern char *distfile;
70 main(int argc, char **argv)
72 int msgp = 0, distsw = 0, vecp = 1;
74 char *cp, *maildir = NULL;
75 char buf[BUFSIZ], **ap, **argp, **arguments;
76 char *msgs[MAXARGS], *vec[MAXARGS];
81 setlocale(LC_ALL, "");
83 invo_name = mhbasename(argv[0]);
85 /* read user profile/context */
88 arguments = getarguments(invo_name, argc, argv, 1);
91 vec[vecp++] = "-library";
92 vec[vecp++] = getcpy(toabsdir("+"));
94 while ((cp = *argp++)) {
96 switch (smatch(++cp, switches)) {
98 ambigsw(cp, switches);
101 adios(NULL, "-%s unknown\n", cp);
104 snprintf(buf, sizeof(buf),
105 "%s [file] [switches]",
107 print_help(buf, switches, 1);
110 print_version(invo_name);
144 debugsw++; /* fall */
157 if (!(cp = *argp++) || *cp == '-')
158 adios(NULL, "missing argument to %s",
170 ** check for "Aliasfile:" profile entry
172 if ((cp = context_find("Aliasfile"))) {
175 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap;
177 vec[vecp++] = "-alias";
183 msgs[msgp++] = seq_cur;
184 maildir = toabsdir(draftfolder);
186 if (chdir(maildir) == NOTOK)
187 adios(maildir, "unable to change directory to");
189 /* read folder and create message structure */
190 if (!(mp = folder_read(draftfolder)))
191 adios(NULL, "unable to read draft folder %s", draftfolder);
193 /* check for empty folder */
195 adios(NULL, "no messages in draft folder %s", draftfolder);
197 /* parse all the message ranges/sequences and set SELECTED */
198 for (msgnum = 0; msgnum < msgp; msgnum++)
199 if (!m_convert(mp, msgs[msgnum]))
201 seq_setprev(mp); /* set the previous-sequence */
203 for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
204 if (is_selected(mp, msgnum)) {
205 msgs[msgp++] = getcpy(m_name(msgnum));
206 unset_exists(mp, msgnum);
210 mp->msgflags |= SEQMOD;
213 if (!(cp = getenv("SIGNATURE")) || !*cp)
214 if ((cp = context_find("signature")) && *cp)
215 m_putenv("SIGNATURE", cp);
217 for (msgnum = 0; msgnum < msgp; msgnum++)
218 if (stat(msgs[msgnum], &st) == NOTOK)
219 adios(msgs[msgnum], "unable to stat draft file");
221 if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0)
223 if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0))
225 if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0)
226 altmsg = NULL; /* used by dist interface - see below */
228 if ((cp = getenv("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) {
229 vec[vecp++] = "-dist";
230 distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL));
231 if (link(altmsg, distfile) == NOTOK) {
234 && errno != EISREMOTE
235 #endif /* EISREMOTE */
237 adios(distfile, "unable to link %s to",
240 distfile = getcpy(m_mktemp2(NULL, invo_name,
246 if ((in = open(altmsg, O_RDONLY)) == NOTOK)
247 adios(altmsg, "unable to open");
249 if ((out = creat(distfile,
250 (int) st.st_mode & 0777))
252 adios(distfile, "unable to write");
253 cpydata(in, out, altmsg, distfile);
262 if (altmsg == NULL || stat(altmsg, &st) == NOTOK) {
271 vec[0] = mhbasename(postproc);
274 for (msgnum = 0; msgnum < msgp; msgnum++) {
275 switch (sendsbr(vec, vecp, msgs[msgnum], &st, 1)) {
285 context_save(); /* save the context file */