]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/dist.c
1 /* dist.c - re-distribute a message */
3 static char ident
[] = "@(#)$Id: dist.c,v 1.5 1992/12/15 00:20:22 jromine Exp $";
16 static struct swit switches
[] = {
23 "draftfolder +folder", 0,
25 "draftmessage msg", 0,
43 "whatnowproc program", 0,
51 "file file", -4, /* interface from msh */
58 static struct swit aqrnl
[] = {
74 static struct swit aqrl
[] = {
115 struct msgs
*mp
= NULL
;
119 setlocale(LC_ALL
, "");
121 invo_name
= r1bindex (argv
[0], '/');
122 if ((cp
= m_find (invo_name
)) != NULL
) {
123 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
124 ap
= copyip (ap
, arguments
);
128 (void) copyip (argv
+ 1, ap
);
133 while (cp
= *argp
++) {
135 switch (smatch (++cp
, switches
)) {
137 ambigsw (cp
, switches
);
140 adios (NULLCP
, "-%s unknown", cp
);
142 (void) sprintf (buf
, "%s [+folder] [msg] [switches]",
144 help (buf
, switches
);
155 if (!(ed
= *argp
++) || *ed
== '-')
156 adios (NULLCP
, "missing argument to %s", argp
[-2]);
164 if (!(whatnowproc
= *argp
++) || *whatnowproc
== '-')
165 adios (NULLCP
, "missing argument to %s", argp
[-2]);
174 adios (NULLCP
, "only one file at a time!");
175 if (!(cp
= *argp
++) || *cp
== '-')
176 adios (NULLCP
, "missing argument to %s", argp
[-2]);
177 file
= path (cp
, TFILE
);
180 if (!(form
= *argp
++) || *form
== '-')
181 adios (NULLCP
, "missing argument to %s", argp
[-2]);
193 adios (NULLCP
, "only one draft folder at a time!");
194 if (!(cp
= *argp
++) || *cp
== '-')
195 adios (NULLCP
, "missing argument to %s", argp
[-2]);
196 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
197 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
201 adios (NULLCP
, "only one draft message at a time!");
202 if (!(dmsg
= *argp
++) || *dmsg
== '-')
203 adios (NULLCP
, "missing argument to %s", argp
[-2]);
210 if (*cp
== '+' || *cp
== '@') {
212 adios (NULLCP
, "only one folder at a time!");
214 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
218 adios (NULLCP
, "only one message at a time!");
225 cwd
= getcpy (pwd ());
227 if (!m_find ("path"))
228 free (path ("./", TFOLDER
));
229 if (file
&& (msg
|| folder
))
230 adios (NULLCP
, "can't mix files and folders/msgs");
233 if ((in
= open (libpath (form
), 0)) == NOTOK
)
234 adios (form
, "unable to open form file");
237 if ((in
= open (libpath (distcomps
), 0)) == NOTOK
)
238 adios (distcomps
, "unable to open default components file");
243 (void) strcpy (drft
, m_draft (dfolder
, dmsg
, NOUSE
, &isdf
));
244 if (stat (drft
, &st
) != NOTOK
) {
245 printf ("Draft \"%s\" exists (%ld bytes).", drft
, st
.st_size
);
246 for (i
= LISTDSW
; i
!= YESW
;) {
247 if (!(argp
= getans ("\nDisposition? ", isdf
? aqrnl
: aqrl
)))
249 switch (i
= smatch (*argp
, isdf
? aqrnl
: aqrl
)) {
258 (void) showfile (++argp
, drft
);
261 if (refile (++argp
, drft
) == 0)
265 advise (NULLCP
, "say what?");
270 if ((out
= creat (drft
, m_gmprot ())) == NOTOK
)
271 adios (drft
, "unable to create");
273 cpydata (in
, out
, form
, drft
);
287 folder
= m_getfolder ();
288 maildir
= m_maildir (folder
);
290 if (chdir (maildir
) == NOTOK
)
291 adios (maildir
, "unable to change directory to");
292 if (!(mp
= m_gmsg (folder
)))
293 adios (NULLCP
, "unable to read folder %s", folder
);
294 if (mp
-> hghmsg
== 0)
295 adios (NULLCP
, "no messages in %s", folder
);
297 if (!m_convert (mp
, msg
))
301 if (mp
-> numsel
> 1)
302 adios (NULLCP
, "only one message at a time!");
305 if ((in
= open (msgnam
= file
? file
: getcpy (m_name (mp
-> lowsel
)), 0))
307 adios (msgnam
, "unable to open message");
310 m_replace (pfolder
, folder
);
311 if (mp
-> lowsel
!= mp
-> curmsg
)
312 m_setcur (mp
, mp
-> lowsel
);
319 (void) what_now (ed
, nedit
, NOUSE
, drft
, msgnam
, 1, mp
,
320 anot
? "Resent" : NULLCP
, inplace
, cwd
);