]>
diplodocus.org Git - nmh/blob - uip/send.c
3 * send.c -- send a composed message
15 # define SASLminc(a) (a)
16 #else /* CYRUS_SASL */
17 # define SASLminc(a) 0
18 #endif /* CYRUS_SASL */
20 static struct swit switches
[] = {
22 { "alias aliasfile", 0 },
28 { "draftfolder +folder", 6 },
30 { "draftmessage msg", 6 },
32 { "nodraftfolder", 0 },
34 { "filter filterfile", 0 },
58 { "split seconds", 0 },
72 { "width columns", 0 },
78 { "dashstuffing", -12 },
79 #define NBITSTUFFSW 29
80 { "nodashstuffing", -14 },
90 { "client host", -6 },
92 { "server host", -6 },
96 { "sasl", SASLminc(-4) },
98 { "saslmech", SASLminc(-5) },
100 { "user", SASLminc(-4) },
104 static struct swit anyl
[] = {
114 extern int debugsw
; /* from sendsbr.c */
122 extern char *altmsg
; /* .. */
123 extern char *annotext
;
124 extern char *distfile
;
129 main (int argc
, char **argv
)
131 int msgp
= 0, distsw
= 0, vecp
= 1;
132 int isdf
= 0, mime
= 0;
134 char *cp
, *dfolder
= NULL
, *maildir
= NULL
;
135 char buf
[BUFSIZ
], **ap
, **argp
, **arguments
;
136 char *msgs
[MAXARGS
], *vec
[MAXARGS
];
144 setlocale(LC_ALL
, "");
146 invo_name
= r1bindex (argv
[0], '/');
148 /* read user profile/context */
151 arguments
= getarguments (invo_name
, argc
, argv
, 1);
154 vec
[vecp
++] = "-library";
155 vec
[vecp
++] = getcpy (m_maildir (""));
157 while ((cp
= *argp
++)) {
159 switch (smatch (++cp
, switches
)) {
161 ambigsw (cp
, switches
);
164 adios (NULL
, "-%s unknown\n", cp
);
167 snprintf (buf
, sizeof(buf
), "%s [file] [switches]", invo_name
);
168 print_help (buf
, switches
, 1);
171 print_version(invo_name
);
175 msgs
[msgp
++] = draft
;
180 adios (NULL
, "only one draft folder at a time!");
181 if (!(cp
= *argp
++) || *cp
== '-')
182 adios (NULL
, "missing argument to %s", argp
[-2]);
183 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
184 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
187 if (!(cp
= *argp
++) || *cp
== '-')
188 adios (NULL
, "missing argument to %s", argp
[-2]);
204 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1)
205 adios (NULL
, "missing argument to %s", argp
[-2]);
241 debugsw
++; /* fall */
268 if (!(cp
= *argp
++) || *cp
== '-')
269 adios (NULL
, "missing argument to %s", argp
[-2]);
279 * check for "Aliasfile:" profile entry
281 if ((cp
= context_find ("Aliasfile"))) {
284 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++) {
285 vec
[vecp
++] = "-alias";
290 if (dfolder
== NULL
) {
293 if ((cp
= getenv ("mhdraft")) && *cp
) {
298 msgs
[msgp
++] = getcpy (m_draft (NULL
, NULL
, 1, &isdf
));
299 if (stat (msgs
[0], &st
) == NOTOK
)
300 adios (msgs
[0], "unable to stat draft file");
301 cp
= concat ("Use \"", msgs
[0], "\"? ", NULL
);
302 for (status
= LISTDSW
; status
!= YESW
;) {
303 if (!(argp
= getans (cp
, anyl
)))
305 switch (status
= smatch (*argp
, anyl
)) {
311 showfile (++argp
, msgs
[0]);
314 advise (NULL
, "say what?");
319 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
320 msgs
[msgnum
] = getcpy (m_maildir (msgs
[msgnum
]));
323 if (!context_find ("path"))
324 free (path ("./", TFOLDER
));
327 msgs
[msgp
++] = "cur";
328 maildir
= m_maildir (dfolder
);
330 if (chdir (maildir
) == NOTOK
)
331 adios (maildir
, "unable to change directory to");
333 /* read folder and create message structure */
334 if (!(mp
= folder_read (dfolder
)))
335 adios (NULL
, "unable to read folder %s", dfolder
);
337 /* check for empty folder */
339 adios (NULL
, "no messages in %s", dfolder
);
341 /* parse all the message ranges/sequences and set SELECTED */
342 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
343 if (!m_convert (mp
, msgs
[msgnum
]))
345 seq_setprev (mp
); /* set the previous-sequence */
347 for (msgp
= 0, msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
348 if (is_selected (mp
, msgnum
)) {
349 msgs
[msgp
++] = getcpy (m_name (msgnum
));
350 unset_exists (mp
, msgnum
);
354 mp
->msgflags
|= SEQMOD
;
362 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
363 if ((cp
= context_find ("signature")) && *cp
)
364 m_putenv ("SIGNATURE", cp
);
367 snprintf (buf
, sizeof(buf
), "%s/.signature", mypath
);
368 if ((fp
= fopen (buf
, "r")) != NULL
369 && fgets (buf
, sizeof buf
, fp
) != NULL
) {
371 if (cp
= strchr (buf
, '\n'))
373 m_putenv ("SIGNATURE", buf
);
378 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
379 if (stat (msgs
[msgnum
], &st
) == NOTOK
)
380 adios (msgs
[msgnum
], "unable to stat draft file");
382 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
384 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
386 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
387 altmsg
= NULL
; /* used by dist interface - see below */
389 if ((cp
= getenv ("mhdist"))
391 && (distsw
= atoi (cp
))
393 vec
[vecp
++] = "-dist";
394 distfile
= getcpy (m_scratch (altmsg
, invo_name
));
395 if (link (altmsg
, distfile
) == NOTOK
) {
398 && errno
!= EISREMOTE
399 #endif /* EISREMOTE */
401 adios (distfile
, "unable to link %s to", altmsg
);
403 distfile
= getcpy (m_tmpfil (invo_name
));
408 if ((in
= open (altmsg
, O_RDONLY
)) == NOTOK
)
409 adios (altmsg
, "unable to open");
411 if ((out
= creat (distfile
, (int) st
.st_mode
& 0777)) == NOTOK
)
412 adios (distfile
, "unable to write");
413 cpydata (in
, out
, altmsg
, distfile
);
422 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
431 vec
[0] = r1bindex (postproc
, '/');
434 for (msgnum
= 0; msgnum
< msgp
; msgnum
++) {
435 switch (sendsbr (vec
, vecp
, msgs
[msgnum
], &st
, 1)) {
445 context_save (); /* save the context file */
446 return done (status
);