]>
diplodocus.org Git - nmh/blob - uip/dist.c
3 * dist.c -- re-distribute a message
11 static struct swit switches
[] = {
17 { "draftfolder +folder", 0 },
19 { "draftmessage msg", 0 },
21 { "nodraftfolder", 0 },
23 { "editor editor", 0 },
27 { "form formfile", 0 },
33 { "whatnowproc program", 0 },
35 { "nowhatnowproc", 0 },
41 { "file file", -4 }, /* interface from msh */
45 static struct swit aqrnl
[] = {
53 { "refile +folder", 0 },
60 static struct swit aqrl
[] = {
64 { "refile +folder", 0 },
70 main (int argc
, char **argv
)
72 int anot
= 0, inplace
= 1, nedit
= 0;
73 int nwhat
= 0, i
, in
, isdf
= 0, out
;
74 char *cp
, *cwd
, *maildir
, *msgnam
, *dfolder
= NULL
;
75 char *dmsg
= NULL
, *ed
= NULL
, *file
= NULL
, *folder
= NULL
;
76 char *form
= NULL
, *msg
= NULL
, buf
[BUFSIZ
], drft
[BUFSIZ
];
77 char **argp
, **arguments
;
78 struct msgs
*mp
= NULL
;
82 setlocale(LC_ALL
, "");
84 invo_name
= r1bindex (argv
[0], '/');
86 /* read user profile/context */
89 arguments
= getarguments (invo_name
, argc
, argv
, 1);
92 while ((cp
= *argp
++)) {
94 switch (smatch (++cp
, switches
)) {
96 ambigsw (cp
, switches
);
99 adios (NULL
, "-%s unknown", cp
);
102 snprintf (buf
, sizeof(buf
), "%s [+folder] [msg] [switches]",
104 print_help (buf
, switches
, 1);
107 print_version(invo_name
);
118 if (!(ed
= *argp
++) || *ed
== '-')
119 adios (NULL
, "missing argument to %s", argp
[-2]);
127 if (!(whatnowproc
= *argp
++) || *whatnowproc
== '-')
128 adios (NULL
, "missing argument to %s", argp
[-2]);
137 adios (NULL
, "only one file at a time!");
138 if (!(cp
= *argp
++) || *cp
== '-')
139 adios (NULL
, "missing argument to %s", argp
[-2]);
140 file
= path (cp
, TFILE
);
143 if (!(form
= *argp
++) || *form
== '-')
144 adios (NULL
, "missing argument to %s", argp
[-2]);
156 adios (NULL
, "only one draft folder at a time!");
157 if (!(cp
= *argp
++) || *cp
== '-')
158 adios (NULL
, "missing argument to %s", argp
[-2]);
159 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
160 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
164 adios (NULL
, "only one draft message at a time!");
165 if (!(dmsg
= *argp
++) || *dmsg
== '-')
166 adios (NULL
, "missing argument to %s", argp
[-2]);
174 if (*cp
== '+' || *cp
== '@') {
176 adios (NULL
, "only one folder at a time!");
178 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
181 adios (NULL
, "only one message at a time!");
187 cwd
= getcpy (pwd ());
189 if (!context_find ("path"))
190 free (path ("./", TFOLDER
));
191 if (file
&& (msg
|| folder
))
192 adios (NULL
, "can't mix files and folders/msgs");
195 if ((in
= open (etcpath (form
), O_RDONLY
)) == NOTOK
)
196 adios (form
, "unable to open form file");
198 if ((in
= open (etcpath (distcomps
), O_RDONLY
)) == NOTOK
)
199 adios (distcomps
, "unable to open default components file");
204 strncpy (drft
, m_draft (dfolder
, dmsg
, NOUSE
, &isdf
), sizeof(drft
));
206 /* Check if draft already exists */
207 if (stat (drft
, &st
) != NOTOK
) {
208 printf ("Draft \"%s\" exists (%ld bytes).", drft
, (long) st
.st_size
);
209 for (i
= LISTDSW
; i
!= YESW
;) {
210 if (!(argp
= getans ("\nDisposition? ", isdf
? aqrnl
: aqrl
)))
212 switch (i
= smatch (*argp
, isdf
? aqrnl
: aqrl
)) {
221 showfile (++argp
, drft
);
224 if (refile (++argp
, drft
) == 0)
228 advise (NULL
, "say what?");
233 if ((out
= creat (drft
, m_gmprot ())) == NOTOK
)
234 adios (drft
, "unable to create");
236 cpydata (in
, out
, form
, drft
);
244 anot
= 0; /* don't want to annotate a file */
252 folder
= getfolder (1);
253 maildir
= m_maildir (folder
);
255 if (chdir (maildir
) == NOTOK
)
256 adios (maildir
, "unable to change directory to");
258 /* read folder and create message structure */
259 if (!(mp
= folder_read (folder
)))
260 adios (NULL
, "unable to read folder %s", folder
);
262 /* check for empty folder */
264 adios (NULL
, "no messages in %s", folder
);
266 /* parse the message range/sequence/name and set SELECTED */
267 if (!m_convert (mp
, msg
))
269 seq_setprev (mp
); /* set the previous-sequence */
272 adios (NULL
, "only one message at a time!");
275 msgnam
= file
? file
: getcpy (m_name (mp
->lowsel
));
276 if ((in
= open (msgnam
, O_RDONLY
)) == NOTOK
)
277 adios (msgnam
, "unable to open message");
280 context_replace (pfolder
, folder
);/* update current folder */
281 seq_setcur (mp
, mp
->lowsel
); /* update current message */
282 seq_save (mp
); /* synchronize sequences */
283 context_save (); /* save the context file */
288 what_now (ed
, nedit
, NOUSE
, drft
, msgnam
, 1, mp
,
289 anot
? "Resent" : NULL
, inplace
, cwd
);