]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/send.c
1 /* send.c - send a composed message */
3 static char ident
[] = "@(#)$Id: send.c,v 1.14 1995/12/06 21:04:47 jromine Exp $";
10 #include <sys/types.h>
19 #define TMAminc(a) (a)
25 #define MIMEminc(a) (a)
30 static struct swit switches
[] = {
41 "draftfolder +folder", 6,
43 "draftmessage msg", 6,
48 "encrypt", TMAminc (-7),
50 "noencrypt", TMAminc (-9),
53 "filter filterfile", 0,
70 "nomime", MIMEminc(-6),
83 "split seconds", MIMEminc(-5),
126 "record program", -6,
133 static struct swit anyl
[] = {
146 extern int debugsw
; /* from sendsbr.c */
155 extern char *altmsg
; /* .. */
156 extern char *annotext
;
157 extern char *distfile
;
192 setlocale(LC_ALL
, "");
194 invo_name
= r1bindex (argv
[0], '/');
195 if ((cp
= m_find (invo_name
)) != NULL
) {
196 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
197 ap
= copyip (ap
, arguments
);
201 (void) copyip (argv
+ 1, ap
);
204 vec
[vecp
++] = "-library";
205 vec
[vecp
++] = getcpy (m_maildir (""));
209 while (cp
= *argp
++) {
211 switch (smatch (++cp
, switches
)) {
213 ambigsw (cp
, switches
);
216 adios (NULLCP
, "-%s unknown\n", cp
);
218 (void) sprintf (buf
, "%s [file] [switches]", invo_name
);
219 help (buf
, switches
);
220 done (1); /* thanks, phyl */
223 msgs
[msgp
++] = draft
;
228 adios (NULLCP
, "only one draft folder at a time!");
229 if (!(cp
= *argp
++) || *cp
== '-')
230 adios (NULLCP
, "missing argument to %s", argp
[-2]);
231 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
232 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
235 if (!(cp
= *argp
++) || *cp
== '-')
236 adios (NULLCP
, "missing argument to %s", argp
[-2]);
252 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
253 adios (NULLCP
, "missing argument to %s", argp
[-2]);
293 debugsw
++; /* fall */
320 if (!(cp
= *argp
++) || *cp
== '-')
321 adios (NULLCP
, "missing argument to %s", argp
[-2]);
328 if (cp
= m_find ("Aliasfile")) { /* allow Aliasfile: profile entry */
331 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
332 vec
[vecp
++] = "-alias";
339 if (dfolder
== NULL
) {
342 if ((cp
= getenv ("mhdraft")) && *cp
) {
347 msgs
[msgp
++] = getcpy (m_draft (NULLCP
, NULLCP
, 1, &isdf
));
348 if (stat (msgs
[0], &st
) == NOTOK
)
349 adios (msgs
[0], "unable to stat draft file");
350 cp
= concat ("Use \"", msgs
[0], "\"? ", NULLCP
);
351 for (status
= LISTDSW
; status
!= YESW
;) {
352 if (!(argp
= getans (cp
, anyl
)))
354 switch (status
= smatch (*argp
, anyl
)) {
360 (void) showfile (++argp
, msgs
[0]);
363 advise (NULLCP
, "say what?");
369 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
370 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
373 if (!m_find ("path"))
374 free (path ("./", TFOLDER
));
377 msgs
[msgp
++] = "cur";
378 maildir
= m_maildir (dfolder
);
380 if (chdir (maildir
) == NOTOK
)
381 adios (maildir
, "unable to change directory to");
382 if (!(mp
= m_gmsg (dfolder
)))
383 adios (NULLCP
, "unable to read folder %s", dfolder
);
384 if (mp
-> hghmsg
== 0)
385 adios (NULLCP
, "no messages in %s", dfolder
);
387 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
388 if (!m_convert (mp
, msgs
[msgnum
]))
392 for (msgp
= 0, msgnum
= mp
-> lowsel
; msgnum
<= mp
-> hghsel
; msgnum
++)
393 if (mp
-> msgstats
[msgnum
] & SELECTED
) {
394 msgs
[msgp
++] = getcpy (m_name (msgnum
));
396 mp
-> msgstats
[msgnum
] |= DELETED
;
398 mp
-> msgstats
[msgnum
] &= ~EXISTS
;
400 mp
-> msgflags
|= SEQMOD
;
411 if ((cp
= getenv ("KDS")) == NULL
|| *cp
== 0)
412 if ((cp
= m_find ("kdsproc")) && *cp
)
413 (void) m_putenv ("KDS", cp
);
414 if ((cp
= getenv ("TMADB")) == NULL
|| *cp
== 0)
415 if ((cp
= m_find ("tmadb")) && *cp
)
416 (void) m_putenv ("TMADB", m_maildir (cp
));
419 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
420 if ((cp
= m_find ("signature")) && *cp
)
421 (void) m_putenv ("SIGNATURE", cp
);
424 (void) sprintf (buf
, "%s/.signature", mypath
);
425 if ((fp
= fopen (buf
, "r")) != NULL
426 && fgets (buf
, sizeof buf
, fp
) != NULL
) {
428 if (cp
= index (buf
, '\n'))
430 (void) m_putenv ("SIGNATURE", buf
);
435 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
436 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
437 adios (msgs
[msgnum
], "unable to stat draft file");
439 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
441 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
443 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
444 altmsg
= NULL
; /* used by dist interface - see below */
446 if ((cp
= getenv ("mhdist"))
448 && (distsw
= atoi (cp
))
450 vec
[vecp
++] = "-dist";
451 distfile
= getcpy (m_scratch (altmsg
, invo_name
));
452 if (link (altmsg
, distfile
) == NOTOK
) {
455 && errno
!= EISREMOTE
456 #endif /* EISREMOTE */
458 adios (distfile
, "unable to link %s to", altmsg
);
460 distfile
= getcpy (m_tmpfil (invo_name
));
465 if ((in
= open (altmsg
, 0)) == NOTOK
)
466 adios (altmsg
, "unable to open");
467 (void) fstat(in
, &st
);
468 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
469 adios (distfile
, "unable to write");
470 cpydata (in
, out
, altmsg
, distfile
);
479 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
)
480 st
.st_mtime
= 0, st
.st_dev
= 0, st
.st_ino
= 0;
485 vec
[0] = r1bindex (postproc
, '/');
488 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
489 switch (sendsbr (vec
, vecp
, msgs
[msgnum
], &st
)) {