]>
diplodocus.org Git - nmh/blob - uip/send.c
3 * send.c -- send a composed message
14 static struct swit switches
[] = {
16 { "alias aliasfile", 0 },
22 { "draftfolder +folder", 6 },
24 { "draftmessage msg", 6 },
26 { "nodraftfolder", 0 },
28 { "filter filterfile", 0 },
52 { "split seconds", 0 },
66 { "width columns", 0 },
72 { "dashstuffing", -12 },
73 #define NBITSTUFFSW 29
74 { "nodashstuffing", -14 },
84 { "client host", -6 },
86 { "server host", -6 },
92 static struct swit anyl
[] = {
102 extern int debugsw
; /* from sendsbr.c */
110 extern char *altmsg
; /* .. */
111 extern char *annotext
;
112 extern char *distfile
;
117 main (int argc
, char **argv
)
119 int msgp
= 0, distsw
= 0, vecp
= 1;
120 int isdf
= 0, mime
= 0;
122 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
123 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
;
124 char *msgs
[MAXARGS
], *vec
[MAXARGS
];
132 setlocale(LC_ALL
, "");
134 invo_name
= r1bindex (argv
[0], '/');
136 /* read user profile/context */
139 arguments
= getarguments (invo_name
, argc
, argv
, 1);
142 vec
[vecp
++] = "-library";
143 vec
[vecp
++] = getcpy (m_maildir (""));
145 while ((cp
= *argp
++)) {
147 switch (smatch (++cp
, switches
)) {
149 ambigsw (cp
, switches
);
152 adios (NULL
, "-%s unknown\n", cp
);
155 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
156 print_help (buf
, switches
, 1);
159 print_version(invo_name
);
163 msgs
[msgp
++] = draft
;
168 adios (NULL
, "only one draft folder at a time!");
169 if (!(cp
= *argp
++) || *cp
== '-')
170 adios (NULL
, "missing argument to %s", argp
[-2]);
171 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
172 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
175 if (!(cp
= *argp
++) || *cp
== '-')
176 adios (NULL
, "missing argument to %s", argp
[-2]);
192 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
193 adios (NULL
, "missing argument to %s", argp
[-2]);
229 debugsw
++; /* fall */
253 if (!(cp
= *argp
++) || *cp
== '-')
254 adios (NULL
, "missing argument to %s", argp
[-2]);
264 * check for "Aliasfile:" profile entry
266 if ((cp
= context_find ("Aliasfile"))) {
269 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
270 vec
[vecp
++] = "-alias";
275 if (dfolder
== NULL
) {
278 if ((cp
= getenv ("mhdraft")) && *cp
) {
283 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
284 if (stat (msgs
[0], &st
) == NOTOK
)
285 adios (msgs
[0], "unable to stat draft file");
286 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
287 for (status
= LISTDSW
; status
!= YESW
;) {
288 if (!(argp
= getans (cp
, anyl
)))
290 switch (status
= smatch (*argp
, anyl
)) {
296 showfile (++argp
, msgs
[0]);
299 advise (NULL
, "say what?");
304 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
305 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
308 if (!context_find ("path"))
309 free (path ("./", TFOLDER
));
312 msgs
[msgp
++] = "cur";
313 maildir
= m_maildir (dfolder
);
315 if (chdir (maildir
) == NOTOK
)
316 adios (maildir
, "unable to change directory to");
318 /* read folder and create message structure */
319 if (!(mp
= folder_read (dfolder
)))
320 adios (NULL
, "unable to read folder %s", dfolder
);
322 /* check for empty folder */
324 adios (NULL
, "no messages in %s", dfolder
);
326 /* parse all the message ranges/sequences and set SELECTED */
327 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
328 if (!m_convert (mp
, msgs
[msgnum
]))
330 seq_setprev (mp
); /* set the previous-sequence */
332 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
333 if (is_selected (mp
, msgnum
)) {
334 msgs
[msgp
++] = getcpy (m_name (msgnum
));
335 unset_exists (mp
, msgnum
);
339 mp
->msgflags
|= SEQMOD
;
347 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
348 if ((cp
= context_find ("signature")) && *cp
)
349 m_putenv ("SIGNATURE", cp
);
352 snprintf (buf
, sizeof(buf
), "%s/.signature", mypath
);
353 if ((fp
= fopen (buf
, "r")) != NULL
354 && fgets (buf
, sizeof buf
, fp
) != NULL
) {
356 if (cp
= strchr (buf
, '\n'))
358 m_putenv ("SIGNATURE", buf
);
363 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
364 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
365 adios (msgs
[msgnum
], "unable to stat draft file");
367 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
369 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
371 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
372 altmsg
= NULL
; /* used by dist interface - see below */
374 if ((cp
= getenv ("mhdist"))
376 && (distsw
= atoi (cp
))
378 vec
[vecp
++] = "-dist";
379 distfile
= getcpy (m_scratch (altmsg
, invo_name
));
380 if (link (altmsg
, distfile
) == NOTOK
) {
383 && errno
!= EISREMOTE
384 #endif /* EISREMOTE */
386 adios (distfile
, "unable to link %s to", altmsg
);
388 distfile
= getcpy (m_tmpfil (invo_name
));
393 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
394 adios (altmsg
, "unable to open");
396 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
397 adios (distfile
, "unable to write");
398 cpydata (in
, out
, altmsg
, distfile
);
407 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
416 vec
[0] = r1bindex (postproc
, '/');
419 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
420 switch (sendsbr (vec
, vecp
, msgs
[msgnum
], &st
, 1)) {
430 context_save (); /* save the context file */
431 return done (status
);