]>
diplodocus.org Git - nmh/blob - uip/send.c
22cdb10cf778bee0fc78f94679dcb020664ca3c6
3 * send.c -- send a composed message
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
17 # define SASLminc(a) (a)
18 #else /* CYRUS_SASL */
19 # define SASLminc(a) 0
20 #endif /* CYRUS_SASL */
23 # define TLSminc(a) (a)
24 #else /* TLS_SUPPORT */
26 #endif /* TLS_SUPPORT */
28 #define SEND_SWITCHES \
29 X("alias aliasfile", 0, ALIASW) \
30 X("debug", -5, DEBUGSW) \
31 X("draft", 0, DRAFTSW) \
32 X("draftfolder +folder", 6, DFOLDSW) \
33 X("draftmessage msg", 6, DMSGSW) \
34 X("nodraftfolder", 0, NDFLDSW) \
35 X("filter filterfile", 0, FILTSW) \
36 X("nofilter", 0, NFILTSW) \
37 X("format", 0, FRMTSW) \
38 X("noformat", 0, NFRMTSW) \
39 X("forward", 0, FORWSW) \
40 X("noforward", 0, NFORWSW) \
41 X("mime", 0, MIMESW) \
42 X("nomime", 0, NMIMESW) \
43 X("msgid", 0, MSGDSW) \
44 X("nomsgid", 0, NMSGDSW) \
45 X("push", 0, PUSHSW) \
46 X("nopush", 0, NPUSHSW) \
47 X("split seconds", 0, SPLITSW) \
48 X("unique", -6, UNIQSW) \
49 X("nounique", -8, NUNIQSW) \
50 X("verbose", 0, VERBSW) \
51 X("noverbose", 0, NVERBSW) \
52 X("watch", 0, WATCSW) \
53 X("nowatch", 0, NWATCSW) \
54 X("width columns", 0, WIDTHSW) \
55 X("version", 0, VERSIONSW) \
56 X("help", 0, HELPSW) \
57 X("dashstuffing", -12, BITSTUFFSW) \
58 X("nodashstuffing", -14, NBITSTUFFSW) \
59 X("client host", -6, CLIESW) \
60 X("server host", 6, SERVSW) \
61 X("snoop", 5, SNOOPSW) \
62 X("sasl", SASLminc(4), SASLSW) \
63 X("nosasl", SASLminc(-6), NOSASLSW) \
64 X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \
65 X("saslmech mechanism", SASLminc(-5), SASLMECHSW) \
66 X("oauth service", 0, OAUTHSW) \
67 X("user username", SASLminc(-4), USERSW) \
68 X("attach", -6, ATTACHSW) \
69 X("noattach", -8, NOATTACHSW) \
70 X("attachformat", 7, ATTACHFORMATSW) \
71 X("port server-port-name/number", 4, PORTSW) \
72 X("tls", TLSminc(-3), TLSSW) \
73 X("initialtls", TLSminc(-10), INITTLSSW) \
74 X("notls", TLSminc(-5), NTLSSW) \
75 X("sendmail program", 0, MTSSM) \
76 X("mts smtp|sendmail/smtp|sendmail/pipe", 2, MTSSW) \
77 X("messageid localname|random", 2, MESSAGEIDSW) \
79 #define X(sw, minchars, id) id,
80 DEFINE_SWITCH_ENUM(SEND
);
83 #define X(sw, minchars, id) { sw, minchars, id },
84 DEFINE_SWITCH_ARRAY(SEND
, switches
);
87 #define USE_SWITCHES \
90 X("list", 0, LISTDSW) \
92 #define X(sw, minchars, id) id,
93 DEFINE_SWITCH_ENUM(USE
);
96 #define X(sw, minchars, id) { sw, minchars, id },
97 DEFINE_SWITCH_ARRAY(USE
, anyl
);
100 extern int debugsw
; /* from sendsbr.c */
108 extern char *altmsg
; /* .. */
109 extern char *annotext
;
110 extern char *distfile
;
114 main (int argc
, char **argv
)
116 int msgp
= 0, distsw
= 0, vecp
;
117 int isdf
= 0, mime
= 0;
119 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
120 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
, *program
;
121 char *msgs
[MAXARGS
], **vec
;
122 const char *user
= NULL
, *oauth_svc
= NULL
;
127 if (nmh_init(argv
[0], 1)) { return 1; }
129 arguments
= getarguments (invo_name
, argc
, argv
, 1);
132 vec
= argsplit(postproc
, &program
, &vecp
);
134 vec
[vecp
++] = "-library";
135 vec
[vecp
++] = getcpy (m_maildir (""));
137 if ((cp
= context_find ("fileproc"))) {
138 vec
[vecp
++] = "-fileproc";
142 if ((cp
= context_find ("mhlproc"))) {
143 vec
[vecp
++] = "-mhlproc";
147 if ((cp
= context_find ("credentials"))) {
148 /* post doesn't read context so need to pass credentials. */
149 vec
[vecp
++] = "-credentials";
153 while ((cp
= *argp
++)) {
155 switch (smatch (++cp
, switches
)) {
157 ambigsw (cp
, switches
);
160 adios (NULL
, "-%s unknown\n", cp
);
163 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
164 print_help (buf
, switches
, 1);
167 print_version(invo_name
);
171 msgs
[msgp
++] = draft
;
176 adios (NULL
, "only one draft folder at a time!");
177 if (!(cp
= *argp
++) || *cp
== '-')
178 adios (NULL
, "missing argument to %s", argp
[-2]);
179 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
180 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
183 if (!(cp
= *argp
++) || *cp
== '-')
184 adios (NULL
, "missing argument to %s", argp
[-2]);
200 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
201 adios (NULL
, "missing argument to %s", argp
[-2]);
242 debugsw
++; /* fall */
262 if (!(cp
= *argp
++) || *cp
== '-')
263 adios (NULL
, "missing argument to %s", argp
[-2]);
266 NMH_UNUSED (oauth_svc
);
267 adios (NULL
, "not built with OAuth support");
273 if (!(cp
= *argp
++) || *cp
== '-')
274 adios (NULL
, "missing argument to %s", argp
[-2]);
291 if (!(cp
= *argp
++) || *cp
== '-')
292 adios (NULL
, "missing argument to %s", argp
[-2]);
297 advise(NULL
, "The -attach switch is deprecated");
300 advise(NULL
, "The -noattach switch is deprecated");
304 advise(NULL
, "The -attachformat switch is deprecated");
313 * check for "Aliasfile:" profile entry
315 if ((cp
= context_find ("Aliasfile"))) {
318 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
319 vec
[vecp
++] = "-alias";
324 if (dfolder
== NULL
) {
326 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
327 if (stat (msgs
[0], &st
) == NOTOK
)
328 adios (msgs
[0], "unable to stat draft file");
329 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
330 for (status
= LISTDSW
; status
!= YESW
;) {
331 if (!(argp
= getans (cp
, anyl
)))
333 switch (status
= smatch (*argp
, anyl
)) {
339 showfile (++argp
, msgs
[0]);
342 advise (NULL
, "say what?");
347 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
348 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
351 if (!context_find ("path"))
352 free (path ("./", TFOLDER
));
355 msgs
[msgp
++] = "cur";
356 maildir
= m_maildir (dfolder
);
358 if (chdir (maildir
) == NOTOK
)
359 adios (maildir
, "unable to change directory to");
361 /* read folder and create message structure */
362 if (!(mp
= folder_read (dfolder
, 1)))
363 adios (NULL
, "unable to read folder %s", dfolder
);
365 /* check for empty folder */
367 adios (NULL
, "no messages in %s", dfolder
);
369 /* parse all the message ranges/sequences and set SELECTED */
370 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
371 if (!m_convert (mp
, msgs
[msgnum
]))
373 seq_setprev (mp
); /* set the previous-sequence */
375 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
376 if (is_selected (mp
, msgnum
)) {
377 msgs
[msgp
++] = getcpy (m_name (msgnum
));
378 unset_exists (mp
, msgnum
);
382 mp
->msgflags
|= SEQMOD
;
390 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
391 if ((cp
= context_find ("signature")) && *cp
)
392 m_putenv ("SIGNATURE", cp
);
394 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
395 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
396 adios (msgs
[msgnum
], "unable to stat draft file");
398 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
400 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
402 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
403 altmsg
= NULL
; /* used by dist interface - see below */
405 if ((cp
= getenv ("mhdist"))
407 && (distsw
= atoi (cp
))
409 vec
[vecp
++] = "-dist";
410 if ((cp
= m_mktemp2(altmsg
, invo_name
, NULL
, NULL
)) == NULL
) {
411 adios(NULL
, "unable to create temporary file in %s",
414 distfile
= getcpy (cp
);
415 (void) m_unlink(distfile
);
416 if (link (altmsg
, distfile
) == NOTOK
) {
417 /* Cygwin with FAT32 filesystem produces EPERM. */
418 if (errno
!= EXDEV
&& errno
!= EPERM
420 && errno
!= EISREMOTE
421 #endif /* EISREMOTE */
423 adios (distfile
, "unable to link %s to", altmsg
);
425 if ((cp
= m_mktemp2(NULL
, invo_name
, NULL
, NULL
)) == NULL
) {
426 adios(NULL
, "unable to create temporary file in %s",
429 distfile
= getcpy (cp
);
434 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
435 adios (altmsg
, "unable to open");
437 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
438 adios (distfile
, "unable to write");
439 cpydata (in
, out
, altmsg
, distfile
);
449 if (oauth_svc
!= NULL
) {
451 adios (NULL
, "must specify -user with -oauth");
454 vec
[vecp
++] = "-oauth";
455 vec
[vecp
++] = mh_oauth_do_xoauth (user
, oauth_svc
,
456 snoop
? stderr
: NULL
);
458 #endif /* OAUTH_SUPPORT */
460 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
471 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
472 switch (sendsbr (vec
, vecp
, program
, msgs
[msgnum
], &st
, 1)) {
482 context_save (); /* save the context file */