]>
diplodocus.org Git - nmh/blob - uip/send.c
3 * send.c -- send a composed message
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
19 # define SASLminc(a) (a)
20 #else /* CYRUS_SASL */
21 # define SASLminc(a) 0
22 #endif /* CYRUS_SASL */
24 static struct swit switches
[] = {
26 { "alias aliasfile", 0 },
32 { "draftfolder +folder", 6 },
34 { "draftmessage msg", 6 },
36 { "nodraftfolder", 0 },
38 { "filter filterfile", 0 },
62 { "split seconds", 0 },
76 { "width columns", 0 },
82 { "dashstuffing", -12 },
83 #define NBITSTUFFSW 29
84 { "nodashstuffing", -14 },
94 { "client host", -6 },
96 { "server host", -6 },
100 { "sasl", SASLminc(-4) },
101 #define SASLMECHSW 38
102 { "saslmech", SASLminc(-5) },
104 { "user", SASLminc(-4) },
110 static struct swit anyl
[] = {
120 extern int debugsw
; /* from sendsbr.c */
128 extern char *altmsg
; /* .. */
129 extern char *annotext
;
130 extern char *distfile
;
135 main (int argc
, char **argv
)
137 int msgp
= 0, distsw
= 0, vecp
= 1;
138 int isdf
= 0, mime
= 0;
140 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
141 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
;
142 char *msgs
[MAXARGS
], *vec
[MAXARGS
];
145 char *attach
= (char *)0; /* header field name for attachments */
151 setlocale(LC_ALL
, "");
153 invo_name
= r1bindex (argv
[0], '/');
155 /* read user profile/context */
158 arguments
= getarguments (invo_name
, argc
, argv
, 1);
161 vec
[vecp
++] = "-library";
162 vec
[vecp
++] = getcpy (m_maildir (""));
164 while ((cp
= *argp
++)) {
166 switch (smatch (++cp
, switches
)) {
168 ambigsw (cp
, switches
);
171 adios (NULL
, "-%s unknown\n", cp
);
174 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
175 print_help (buf
, switches
, 1);
178 print_version(invo_name
);
182 msgs
[msgp
++] = draft
;
187 adios (NULL
, "only one draft folder at a time!");
188 if (!(cp
= *argp
++) || *cp
== '-')
189 adios (NULL
, "missing argument to %s", argp
[-2]);
190 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
191 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
194 if (!(cp
= *argp
++) || *cp
== '-')
195 adios (NULL
, "missing argument to %s", argp
[-2]);
211 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
212 adios (NULL
, "missing argument to %s", argp
[-2]);
248 debugsw
++; /* fall */
275 if (!(cp
= *argp
++) || *cp
== '-')
276 adios (NULL
, "missing argument to %s", argp
[-2]);
281 if (!(attach
= *argp
++) || *attach
== '-')
282 adios (NULL
, "missing argument to %s", argp
[-2]);
291 * check for "Aliasfile:" profile entry
293 if ((cp
= context_find ("Aliasfile"))) {
296 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
297 vec
[vecp
++] = "-alias";
302 if (dfolder
== NULL
) {
305 if ((cp
= getenv ("mhdraft")) && *cp
) {
310 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
311 if (stat (msgs
[0], &st
) == NOTOK
)
312 adios (msgs
[0], "unable to stat draft file");
313 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
314 for (status
= LISTDSW
; status
!= YESW
;) {
315 if (!(argp
= getans (cp
, anyl
)))
317 switch (status
= smatch (*argp
, anyl
)) {
323 showfile (++argp
, msgs
[0]);
326 advise (NULL
, "say what?");
331 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
332 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
335 if (!context_find ("path"))
336 free (path ("./", TFOLDER
));
339 msgs
[msgp
++] = "cur";
340 maildir
= m_maildir (dfolder
);
342 if (chdir (maildir
) == NOTOK
)
343 adios (maildir
, "unable to change directory to");
345 /* read folder and create message structure */
346 if (!(mp
= folder_read (dfolder
)))
347 adios (NULL
, "unable to read folder %s", dfolder
);
349 /* check for empty folder */
351 adios (NULL
, "no messages in %s", dfolder
);
353 /* parse all the message ranges/sequences and set SELECTED */
354 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
355 if (!m_convert (mp
, msgs
[msgnum
]))
357 seq_setprev (mp
); /* set the previous-sequence */
359 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
360 if (is_selected (mp
, msgnum
)) {
361 msgs
[msgp
++] = getcpy (m_name (msgnum
));
362 unset_exists (mp
, msgnum
);
366 mp
->msgflags
|= SEQMOD
;
374 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
375 if ((cp
= context_find ("signature")) && *cp
)
376 m_putenv ("SIGNATURE", cp
);
379 snprintf (buf
, sizeof(buf
), "%s/.signature", mypath
);
380 if ((fp
= fopen (buf
, "r")) != NULL
381 && fgets (buf
, sizeof buf
, fp
) != NULL
) {
383 if (cp
= strchr (buf
, '\n'))
385 m_putenv ("SIGNATURE", buf
);
390 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
391 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
392 adios (msgs
[msgnum
], "unable to stat draft file");
394 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
396 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
398 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
399 altmsg
= NULL
; /* used by dist interface - see below */
401 if ((cp
= getenv ("mhdist"))
403 && (distsw
= atoi (cp
))
405 vec
[vecp
++] = "-dist";
406 distfile
= getcpy (m_scratch (altmsg
, invo_name
));
407 if (link (altmsg
, distfile
) == NOTOK
) {
410 && errno
!= EISREMOTE
411 #endif /* EISREMOTE */
413 adios (distfile
, "unable to link %s to", altmsg
);
415 distfile
= getcpy (m_tmpfil (invo_name
));
420 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
421 adios (altmsg
, "unable to open");
423 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
424 adios (distfile
, "unable to write");
425 cpydata (in
, out
, altmsg
, distfile
);
434 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
443 vec
[0] = r1bindex (postproc
, '/');
446 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
447 switch (sendsbr (vec
, vecp
, msgs
[msgnum
], &st
, 1, attach
)) {
457 context_save (); /* save the context file */
458 return done (status
);