]>
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 },
100 { "sasl", SASLminc(4) },
101 #define SASLMECHSW 38
102 { "saslmech mechanism", SASLminc(-5) },
104 { "user username", SASLminc(-4) },
107 #define ATTACHFORMATSW 41
108 { "attachformat", 7 },
110 { "port server-port-name/number" , 4 },
114 static struct swit anyl
[] = {
124 extern int debugsw
; /* from sendsbr.c */
132 extern char *altmsg
; /* .. */
133 extern char *annotext
;
134 extern char *distfile
;
138 main (int argc
, char **argv
)
140 int msgp
= 0, distsw
= 0, vecp
= 1;
141 int isdf
= 0, mime
= 0;
143 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
144 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
;
145 char *msgs
[MAXARGS
], *vec
[MAXARGS
];
148 char *attach
= (char *)0; /* header field name for attachments */
149 int attachformat
= 0; /* mhbuild format specifier for attachments */
155 setlocale(LC_ALL
, "");
157 invo_name
= r1bindex (argv
[0], '/');
159 /* read user profile/context */
162 arguments
= getarguments (invo_name
, argc
, argv
, 1);
165 vec
[vecp
++] = "-library";
166 vec
[vecp
++] = getcpy (m_maildir (""));
168 while ((cp
= *argp
++)) {
170 switch (smatch (++cp
, switches
)) {
172 ambigsw (cp
, switches
);
175 adios (NULL
, "-%s unknown\n", cp
);
178 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
179 print_help (buf
, switches
, 1);
182 print_version(invo_name
);
186 msgs
[msgp
++] = draft
;
191 adios (NULL
, "only one draft folder at a time!");
192 if (!(cp
= *argp
++) || *cp
== '-')
193 adios (NULL
, "missing argument to %s", argp
[-2]);
194 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
195 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
198 if (!(cp
= *argp
++) || *cp
== '-')
199 adios (NULL
, "missing argument to %s", argp
[-2]);
215 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
216 adios (NULL
, "missing argument to %s", argp
[-2]);
252 debugsw
++; /* fall */
280 if (!(cp
= *argp
++) || *cp
== '-')
281 adios (NULL
, "missing argument to %s", argp
[-2]);
286 if (!(attach
= *argp
++) || *attach
== '-')
287 adios (NULL
, "missing argument to %s", argp
[-2]);
291 if (! *argp
|| **argp
== '-')
292 adios (NULL
, "missing argument to %s", argp
[-1]);
294 attachformat
= atoi (*argp
);
295 if (attachformat
< 0 ||
296 attachformat
> ATTACHFORMATS
- 1) {
297 advise (NULL
, "unsupported attachformat %d",
311 * check for "Aliasfile:" profile entry
313 if ((cp
= context_find ("Aliasfile"))) {
316 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
317 vec
[vecp
++] = "-alias";
322 if (dfolder
== NULL
) {
325 if ((cp
= getenv ("mhdraft")) && *cp
) {
330 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
331 if (stat (msgs
[0], &st
) == NOTOK
)
332 adios (msgs
[0], "unable to stat draft file");
333 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
334 for (status
= LISTDSW
; status
!= YESW
;) {
335 if (!(argp
= getans (cp
, anyl
)))
337 switch (status
= smatch (*argp
, anyl
)) {
343 showfile (++argp
, msgs
[0]);
346 advise (NULL
, "say what?");
351 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
352 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
355 if (!context_find ("path"))
356 free (path ("./", TFOLDER
));
359 msgs
[msgp
++] = "cur";
360 maildir
= m_maildir (dfolder
);
362 if (chdir (maildir
) == NOTOK
)
363 adios (maildir
, "unable to change directory to");
365 /* read folder and create message structure */
366 if (!(mp
= folder_read (dfolder
)))
367 adios (NULL
, "unable to read folder %s", dfolder
);
369 /* check for empty folder */
371 adios (NULL
, "no messages in %s", dfolder
);
373 /* parse all the message ranges/sequences and set SELECTED */
374 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
375 if (!m_convert (mp
, msgs
[msgnum
]))
377 seq_setprev (mp
); /* set the previous-sequence */
379 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
380 if (is_selected (mp
, msgnum
)) {
381 msgs
[msgp
++] = getcpy (m_name (msgnum
));
382 unset_exists (mp
, msgnum
);
386 mp
->msgflags
|= SEQMOD
;
394 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
395 if ((cp
= context_find ("signature")) && *cp
)
396 m_putenv ("SIGNATURE", cp
);
399 snprintf (buf
, sizeof(buf
), "%s/.signature", mypath
);
400 if ((fp
= fopen (buf
, "r")) != NULL
401 && fgets (buf
, sizeof buf
, fp
) != NULL
) {
403 if (cp
= strchr (buf
, '\n'))
405 m_putenv ("SIGNATURE", buf
);
410 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
411 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
412 adios (msgs
[msgnum
], "unable to stat draft file");
414 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
416 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
418 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
419 altmsg
= NULL
; /* used by dist interface - see below */
421 if ((cp
= getenv ("mhdist"))
423 && (distsw
= atoi (cp
))
425 vec
[vecp
++] = "-dist";
426 distfile
= getcpy (m_scratch (altmsg
, invo_name
));
427 if (link (altmsg
, distfile
) == NOTOK
) {
430 && errno
!= EISREMOTE
431 #endif /* EISREMOTE */
433 adios (distfile
, "unable to link %s to", altmsg
);
435 distfile
= getcpy (m_tmpfil (invo_name
));
440 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
441 adios (altmsg
, "unable to open");
443 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
444 adios (distfile
, "unable to write");
445 cpydata (in
, out
, altmsg
, distfile
);
454 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
463 vec
[0] = r1bindex (postproc
, '/');
466 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
467 switch (sendsbr (vec
, vecp
, msgs
[msgnum
], &st
, 1, attach
,
478 context_save (); /* save the context file */