annotate uip/refile.c @ 4:6bc439d68ff9 utf-8-support

*** empty log message ***
author kono
date Wed, 20 Apr 2005 14:39:40 +0900
parents bce86c4163a3
children a6481689f99c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bce86c4163a3 Initial revision
kono
parents:
diff changeset
1 /* refile.c - file messages away */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
2 #ifndef lint
bce86c4163a3 Initial revision
kono
parents:
diff changeset
3 static char ident[] = "@(#)$Id$";
bce86c4163a3 Initial revision
kono
parents:
diff changeset
4 #endif /* lint */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
5
bce86c4163a3 Initial revision
kono
parents:
diff changeset
6 #include "../h/mh.h"
bce86c4163a3 Initial revision
kono
parents:
diff changeset
7 #include <errno.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
8 #include <stdio.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
9 #include <sys/types.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
10 #include <sys/stat.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
11 #ifdef LOCALE
bce86c4163a3 Initial revision
kono
parents:
diff changeset
12 #include <locale.h>
bce86c4163a3 Initial revision
kono
parents:
diff changeset
13 #endif
bce86c4163a3 Initial revision
kono
parents:
diff changeset
14
bce86c4163a3 Initial revision
kono
parents:
diff changeset
15 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
16
bce86c4163a3 Initial revision
kono
parents:
diff changeset
17 static struct swit switches[] = {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
18 #define DRAFTSW 0
bce86c4163a3 Initial revision
kono
parents:
diff changeset
19 "draft", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
20
bce86c4163a3 Initial revision
kono
parents:
diff changeset
21 #define LINKSW 1
bce86c4163a3 Initial revision
kono
parents:
diff changeset
22 "link", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
23 #define NLINKSW 2
bce86c4163a3 Initial revision
kono
parents:
diff changeset
24 "nolink", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
25
bce86c4163a3 Initial revision
kono
parents:
diff changeset
26 #define PRESSW 3
bce86c4163a3 Initial revision
kono
parents:
diff changeset
27 "preserve", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
28 #define NPRESSW 4
bce86c4163a3 Initial revision
kono
parents:
diff changeset
29 "nopreserve", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
30
bce86c4163a3 Initial revision
kono
parents:
diff changeset
31 #define SRCSW 5
bce86c4163a3 Initial revision
kono
parents:
diff changeset
32 "src +folder", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
33
bce86c4163a3 Initial revision
kono
parents:
diff changeset
34 #define FILESW 6
bce86c4163a3 Initial revision
kono
parents:
diff changeset
35 "file file", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
36
bce86c4163a3 Initial revision
kono
parents:
diff changeset
37 #define RPROCSW 7
bce86c4163a3 Initial revision
kono
parents:
diff changeset
38 "rmmproc program", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
39 #define NRPRCSW 8
bce86c4163a3 Initial revision
kono
parents:
diff changeset
40 "normmproc", 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
41
bce86c4163a3 Initial revision
kono
parents:
diff changeset
42 #define HELPSW 9
bce86c4163a3 Initial revision
kono
parents:
diff changeset
43 "help", 4,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
44
bce86c4163a3 Initial revision
kono
parents:
diff changeset
45 NULL, 0
bce86c4163a3 Initial revision
kono
parents:
diff changeset
46 };
bce86c4163a3 Initial revision
kono
parents:
diff changeset
47
bce86c4163a3 Initial revision
kono
parents:
diff changeset
48 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
49
bce86c4163a3 Initial revision
kono
parents:
diff changeset
50 extern int errno;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
51
bce86c4163a3 Initial revision
kono
parents:
diff changeset
52
bce86c4163a3 Initial revision
kono
parents:
diff changeset
53 static char maildir[BUFSIZ];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
54
bce86c4163a3 Initial revision
kono
parents:
diff changeset
55
bce86c4163a3 Initial revision
kono
parents:
diff changeset
56 struct st_fold {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
57 char *f_name;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
58 struct msgs *f_mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
59 };
bce86c4163a3 Initial revision
kono
parents:
diff changeset
60
bce86c4163a3 Initial revision
kono
parents:
diff changeset
61 static opnfolds(), clsfolds(), removeit();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
62 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
63
bce86c4163a3 Initial revision
kono
parents:
diff changeset
64 /* ARGSUSED */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
65
bce86c4163a3 Initial revision
kono
parents:
diff changeset
66 main (argc, argv)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
67 int argc;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
68 char **argv;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
69 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
70 int linkf = 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
71 prsrvf = 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
72 filep = 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
73 foldp = 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
74 msgp = 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
75 isdf = 0,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
76 i,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
77 msgnum;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
78 char *cp,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
79 *folder = NULL,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
80 buf[100],
bce86c4163a3 Initial revision
kono
parents:
diff changeset
81 **ap,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
82 **argp,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
83 *arguments[MAXARGS],
bce86c4163a3 Initial revision
kono
parents:
diff changeset
84 *filevec[NFOLDERS + 2],
bce86c4163a3 Initial revision
kono
parents:
diff changeset
85 **files = &filevec[1], /* leave room for removeit:vec[0] */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
86 *msgs[MAXARGS];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
87 struct st_fold folders[NFOLDERS + 1];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
88 struct msgs *mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
89
bce86c4163a3 Initial revision
kono
parents:
diff changeset
90 #ifdef LOCALE
bce86c4163a3 Initial revision
kono
parents:
diff changeset
91 setlocale(LC_ALL, "");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
92 #endif
bce86c4163a3 Initial revision
kono
parents:
diff changeset
93 #ifdef JAPAN
bce86c4163a3 Initial revision
kono
parents:
diff changeset
94 ml_init();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
95 #endif /* JAPAN */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
96 invo_name = r1bindex (argv[0], '/');
bce86c4163a3 Initial revision
kono
parents:
diff changeset
97 if ((cp = m_find (invo_name)) != NULL) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
98 ap = brkstring (cp = getcpy (cp), " ", "\n");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
99 ap = copyip (ap, arguments);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
100 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
101 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
102 ap = arguments;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
103 (void) copyip (argv + 1, ap);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
104 argp = arguments;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
105
bce86c4163a3 Initial revision
kono
parents:
diff changeset
106 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
107
bce86c4163a3 Initial revision
kono
parents:
diff changeset
108 while (cp = *argp++) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
109 if (*cp == '-')
bce86c4163a3 Initial revision
kono
parents:
diff changeset
110 switch (smatch (++cp, switches)) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
111 case AMBIGSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
112 ambigsw (cp, switches);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
113 done (1);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
114 case UNKWNSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
115 adios (NULLCP, "-%s unknown\n", cp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
116 case HELPSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
117 (void) sprintf (buf, "%s [msgs] [switches] +folder ...",
bce86c4163a3 Initial revision
kono
parents:
diff changeset
118 invo_name);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
119 help (buf, switches);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
120 done (1);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
121
bce86c4163a3 Initial revision
kono
parents:
diff changeset
122 case LINKSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
123 linkf++;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
124 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
125 case NLINKSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
126 linkf = 0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
127 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
128
bce86c4163a3 Initial revision
kono
parents:
diff changeset
129 case PRESSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
130 prsrvf++;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
131 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
132 case NPRESSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
133 prsrvf = 0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
134 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
135
bce86c4163a3 Initial revision
kono
parents:
diff changeset
136 case SRCSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
137 if (folder)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
138 adios (NULLCP, "only one source folder at a time!");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
139 if (!(cp = *argp++) || *cp == '-')
bce86c4163a3 Initial revision
kono
parents:
diff changeset
140 adios (NULLCP, "missing argument to %s", argp[-2]);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
141 folder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
142 *cp != '@' ? TFOLDER : TSUBCWF);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
143 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
144 case DRAFTSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
145 if (filep > NFOLDERS)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
146 adios (NULLCP, "only %d files allowed!", NFOLDERS);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
147 isdf = 0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
148 files[filep++] = getcpy (m_draft (NULLCP, NULLCP, 1, &isdf));
bce86c4163a3 Initial revision
kono
parents:
diff changeset
149 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
150 case FILESW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
151 if (filep > NFOLDERS)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
152 adios (NULLCP, "only %d files allowed!", NFOLDERS);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
153 if (!(cp = *argp++) || *cp == '-')
bce86c4163a3 Initial revision
kono
parents:
diff changeset
154 adios (NULLCP, "missing argument to %s", argp[-2]);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
155 files[filep++] = path (cp, TFILE);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
156 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
157
bce86c4163a3 Initial revision
kono
parents:
diff changeset
158 case RPROCSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
159 if (!(rmmproc = *argp++) || *rmmproc == '-')
bce86c4163a3 Initial revision
kono
parents:
diff changeset
160 adios (NULLCP, "missing argument to %s", argp[-2]);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
161 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
162 case NRPRCSW:
bce86c4163a3 Initial revision
kono
parents:
diff changeset
163 rmmproc = (char *)0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
164 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
165 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
166 if (*cp == '+' || *cp == '@') {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
167 if (foldp > NFOLDERS)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
168 adios (NULLCP, "only %d folders allowed!", NFOLDERS);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
169 folders[foldp++].f_name =
bce86c4163a3 Initial revision
kono
parents:
diff changeset
170 path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
171 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
172 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
173 msgs[msgp++] = cp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
174 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
175
bce86c4163a3 Initial revision
kono
parents:
diff changeset
176 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
177
bce86c4163a3 Initial revision
kono
parents:
diff changeset
178 if (!m_find ("path"))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
179 free (path ("./", TFOLDER));
bce86c4163a3 Initial revision
kono
parents:
diff changeset
180 if (foldp == 0)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
181 adios (NULLCP, "no folder specified");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
182
bce86c4163a3 Initial revision
kono
parents:
diff changeset
183 #ifdef WHATNOW
bce86c4163a3 Initial revision
kono
parents:
diff changeset
184 if (!msgp && !foldp && !filep && (cp = getenv ("mhdraft")) && *cp)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
185 files[filep++] = cp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
186 #endif /* WHATNOW */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
187
bce86c4163a3 Initial revision
kono
parents:
diff changeset
188 if (filep > 0) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
189 if (folder || msgp)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
190 adios (NULLCP, "use -file or some messages, not both");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
191 opnfolds (folders, foldp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
192 for (i = 0; i < filep; i++)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
193 if (m_file (files[i], folders, foldp, prsrvf))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
194 done (1);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
195 if (!linkf)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
196 removeit (NULLMP, filep, filevec);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
197 done (0);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
198 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
199
bce86c4163a3 Initial revision
kono
parents:
diff changeset
200 if (!msgp)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
201 msgs[msgp++] = "cur";
bce86c4163a3 Initial revision
kono
parents:
diff changeset
202 if (!folder)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
203 folder = m_getfolder ();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
204 (void) strcpy (maildir, m_maildir (folder));
bce86c4163a3 Initial revision
kono
parents:
diff changeset
205
bce86c4163a3 Initial revision
kono
parents:
diff changeset
206 if (chdir (maildir) == NOTOK)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
207 adios (maildir, "unable to change directory to");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
208 if (!(mp = m_gmsg (folder)))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
209 adios (NULLCP, "unable to read folder %s", folder);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
210 if (mp -> hghmsg == 0)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
211 adios (NULLCP, "no messages in %s", folder);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
212
bce86c4163a3 Initial revision
kono
parents:
diff changeset
213 for (msgnum = 0; msgnum < msgp; msgnum++)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
214 if (!m_convert (mp, msgs[msgnum]))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
215 done (1);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
216 m_setseq (mp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
217
bce86c4163a3 Initial revision
kono
parents:
diff changeset
218 opnfolds (folders, foldp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
219 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
220 if (mp -> msgstats[msgnum] & SELECTED) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
221 cp = getcpy (m_name (msgnum));
bce86c4163a3 Initial revision
kono
parents:
diff changeset
222 if (m_file (cp, folders, foldp, prsrvf))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
223 done (1);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
224 free (cp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
225 if (!linkf) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
226 #ifdef notdef
bce86c4163a3 Initial revision
kono
parents:
diff changeset
227 mp -> msgstats[msgnum] |= DELETED;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
228 #endif /* notdef */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
229 mp -> msgstats[msgnum] &= ~EXISTS;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
230 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
231 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
232 if (!linkf)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
233 mp -> msgflags |= SEQMOD;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
234 clsfolds (folders, foldp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
235
bce86c4163a3 Initial revision
kono
parents:
diff changeset
236 m_replace (pfolder, folder);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
237 if (mp -> hghsel != mp -> curmsg
bce86c4163a3 Initial revision
kono
parents:
diff changeset
238 && (mp -> numsel != mp -> nummsg || linkf))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
239 m_setcur (mp, mp -> hghsel);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
240 m_sync (mp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
241 m_update ();
bce86c4163a3 Initial revision
kono
parents:
diff changeset
242
bce86c4163a3 Initial revision
kono
parents:
diff changeset
243 if (!linkf)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
244 removeit (mp, filep, filevec);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
245
bce86c4163a3 Initial revision
kono
parents:
diff changeset
246 done (0);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
247 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
248
bce86c4163a3 Initial revision
kono
parents:
diff changeset
249 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
250
bce86c4163a3 Initial revision
kono
parents:
diff changeset
251 static opnfolds (folders, nfolders)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
252 register struct st_fold *folders;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
253 int nfolders;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
254 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
255 register char *cp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
256 char nmaildir[BUFSIZ];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
257 register struct st_fold *fp,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
258 *ep;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
259 register struct msgs *mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
260 struct stat st;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
261
bce86c4163a3 Initial revision
kono
parents:
diff changeset
262 for (ep = (fp = folders) + nfolders; fp < ep; fp++) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
263 (void) chdir (m_maildir (""));
bce86c4163a3 Initial revision
kono
parents:
diff changeset
264 (void) strcpy (nmaildir, m_maildir (fp -> f_name));
bce86c4163a3 Initial revision
kono
parents:
diff changeset
265
bce86c4163a3 Initial revision
kono
parents:
diff changeset
266 if (stat (nmaildir, &st) == NOTOK) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
267 if (errno != ENOENT)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
268 adios (nmaildir, "error on folder");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
269 cp = concat ("Create folder \"", nmaildir, "\"? ", NULLCP);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
270 if (!getanswer (cp))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
271 done (1);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
272 free (cp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
273 if (!makedir (nmaildir))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
274 adios (NULLCP, "unable to create folder %s", nmaildir);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
275 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
276
bce86c4163a3 Initial revision
kono
parents:
diff changeset
277 if (chdir (nmaildir) == NOTOK)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
278 adios (nmaildir, "unable to change directory to");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
279 if (!(mp = m_gmsg (fp -> f_name)))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
280 adios (NULLCP, "unable to read folder %s", fp -> f_name);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
281 mp -> curmsg = 0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
282
bce86c4163a3 Initial revision
kono
parents:
diff changeset
283 fp -> f_mp = mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
284
bce86c4163a3 Initial revision
kono
parents:
diff changeset
285 (void) chdir (maildir);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
286 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
287 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
288
bce86c4163a3 Initial revision
kono
parents:
diff changeset
289 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
290
bce86c4163a3 Initial revision
kono
parents:
diff changeset
291 static clsfolds (folders, nfolders)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
292 register struct st_fold *folders;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
293 int nfolders;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
294 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
295 register struct st_fold *fp,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
296 *ep;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
297 register struct msgs *mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
298
bce86c4163a3 Initial revision
kono
parents:
diff changeset
299 for (ep = (fp = folders) + nfolders; fp < ep; fp++) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
300 mp = fp -> f_mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
301 m_setseq (mp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
302 m_sync (mp);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
303 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
304 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
305
bce86c4163a3 Initial revision
kono
parents:
diff changeset
306 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
307
bce86c4163a3 Initial revision
kono
parents:
diff changeset
308 static removeit (mp, filep, files)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
309 register struct msgs *mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
310 register int filep;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
311 register char **files;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
312 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
313 register int i,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
314 vecp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
315 register char *cp,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
316 **vec;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
317
bce86c4163a3 Initial revision
kono
parents:
diff changeset
318 if (rmmproc) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
319 if (filep > 0) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
320 vec = files++; /* filevec[1] */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
321 files[filep] = NULL;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
322 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
323 else {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
324 if (mp -> numsel > MAXARGS - 2)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
325 adios (NULLCP, "more than %d messages for %s exec",
bce86c4163a3 Initial revision
kono
parents:
diff changeset
326 MAXARGS - 2, rmmproc);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
327 vec = (char **) calloc ((unsigned) (mp -> numsel + 2), sizeof *vec);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
328 if (vec == NULL)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
329 adios (NULLCP, "unable to allocate exec vector");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
330 vecp = 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
331 for (i = mp -> lowsel; i <= mp -> hghsel; i++)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
332 if (mp -> msgstats[i] & SELECTED)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
333 vec[vecp++] = getcpy (m_name (i));
bce86c4163a3 Initial revision
kono
parents:
diff changeset
334 vec[vecp] = NULL;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
335 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
336
bce86c4163a3 Initial revision
kono
parents:
diff changeset
337 (void) fflush (stdout);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
338 vec[0] = r1bindex (rmmproc, '/');
bce86c4163a3 Initial revision
kono
parents:
diff changeset
339 execvp (rmmproc, vec);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
340 adios (rmmproc, "unable to exec");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
341 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
342
bce86c4163a3 Initial revision
kono
parents:
diff changeset
343 if (filep > 0) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
344 files++; /* filevec[1] */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
345 for (i = 0; i < filep; i++)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
346 if (unlink (files[i]) == NOTOK)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
347 admonish (files[i], "unable to unlink");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
348 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
349 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
350 for (i = mp -> lowsel; i <= mp -> hghsel; i++)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
351 if (mp -> msgstats[i] & SELECTED)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
352 if (unlink (cp = m_name (i)) == NOTOK)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
353 admonish (cp, "unable to unlink");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
354 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
355
bce86c4163a3 Initial revision
kono
parents:
diff changeset
356 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
357
bce86c4163a3 Initial revision
kono
parents:
diff changeset
358 m_file (msg, folders, nfolders, prsrvf)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
359 register char *msg;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
360 struct st_fold *folders;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
361 int nfolders,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
362 prsrvf;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
363 {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
364 int in,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
365 out,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
366 linkerr,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
367 msgnum;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
368 register char *nmsg;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
369 char newmsg[BUFSIZ];
bce86c4163a3 Initial revision
kono
parents:
diff changeset
370 register struct st_fold *fp,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
371 *ep;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
372 register struct msgs *mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
373 struct stat st,
bce86c4163a3 Initial revision
kono
parents:
diff changeset
374 s1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
375
bce86c4163a3 Initial revision
kono
parents:
diff changeset
376 for (ep = (fp = folders) + nfolders; fp < ep; fp++) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
377 mp = fp -> f_mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
378 if (prsrvf && (msgnum = m_atoi (nmsg = msg)) > 0) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
379 if (msgnum >= mp -> hghoff)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
380 if (mp = m_remsg (mp, 0, msgnum + MAXFOLDER))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
381 fp -> f_mp = mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
382 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
383 adios (NULLCP, "unable to allocate folder storage");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
384 if (!(mp -> msgstats[msgnum] & EXISTS)) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
385 mp -> msgstats[msgnum] |= EXISTS;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
386 #ifdef notdef
bce86c4163a3 Initial revision
kono
parents:
diff changeset
387 mp -> msgstats[msgnum] &= ~DELETED;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
388 #endif /* notdef */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
389 mp -> nummsg++;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
390 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
391 mp -> msgstats[msgnum] |= SELECTED;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
392 if (msgnum > mp -> hghmsg)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
393 mp -> hghmsg = msgnum;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
394 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
395 else {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
396 if (mp -> hghmsg >= mp -> hghoff)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
397 if (mp = m_remsg (mp, 0, mp -> hghoff + MAXFOLDER))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
398 fp -> f_mp = mp;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
399 else
bce86c4163a3 Initial revision
kono
parents:
diff changeset
400 adios (NULLCP, "unable to allocate folder storage");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
401
bce86c4163a3 Initial revision
kono
parents:
diff changeset
402 nmsg = m_name (msgnum = ++mp -> hghmsg);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
403 mp -> nummsg++;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
404 mp -> msgstats[msgnum] |= EXISTS | SELECTED;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
405 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
406 if (mp -> lowmsg == 0)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
407 mp -> lowmsg = msgnum;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
408 if (mp -> lowsel == 0 || msgnum < mp -> lowsel)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
409 mp -> lowsel = msgnum;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
410 if (msgnum > mp -> hghsel)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
411 mp -> hghsel = msgnum;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
412
bce86c4163a3 Initial revision
kono
parents:
diff changeset
413 /* */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
414
bce86c4163a3 Initial revision
kono
parents:
diff changeset
415 (void) sprintf (newmsg, "%s/%s", mp -> foldpath, nmsg);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
416 if (link (msg, newmsg) == NOTOK) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
417 #ifndef EISREMOTE
bce86c4163a3 Initial revision
kono
parents:
diff changeset
418 linkerr = errno;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
419 #else /* EISREMOTE */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
420 if ((linkerr = errno) == EISREMOTE)
bce86c4163a3 Initial revision
kono
parents:
diff changeset
421 linkerr = EXDEV;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
422 #endif /* EISREMOTE */
bce86c4163a3 Initial revision
kono
parents:
diff changeset
423 if (linkerr == EEXIST
bce86c4163a3 Initial revision
kono
parents:
diff changeset
424 || (linkerr == EXDEV && stat (newmsg, &st) != NOTOK)) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
425 if (linkerr != EEXIST
bce86c4163a3 Initial revision
kono
parents:
diff changeset
426 || stat (msg, &s1) == NOTOK
bce86c4163a3 Initial revision
kono
parents:
diff changeset
427 || stat (newmsg, &st) == NOTOK
bce86c4163a3 Initial revision
kono
parents:
diff changeset
428 || s1.st_ino != st.st_ino) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
429 advise (NULLCP, "message %s:%s already exists",
bce86c4163a3 Initial revision
kono
parents:
diff changeset
430 fp -> f_name, newmsg);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
431 return 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
432 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
433 continue;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
434 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
435 if (linkerr == EXDEV) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
436 if ((in = open (msg, 0)) == NOTOK) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
437 advise (msg, "unable to open message %s");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
438 return 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
439 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
440 (void) fstat (in, &st);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
441 if ((out = creat (newmsg, (int) st.st_mode & 0777))
bce86c4163a3 Initial revision
kono
parents:
diff changeset
442 == NOTOK) {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
443 advise (newmsg, "unable to create");
bce86c4163a3 Initial revision
kono
parents:
diff changeset
444 (void) close (in);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
445 return 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
446 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
447 cpydata (in, out, msg, newmsg);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
448 (void) close (in);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
449 (void) close (out);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
450 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
451 else {
bce86c4163a3 Initial revision
kono
parents:
diff changeset
452 advise (newmsg, "error linking %s to", msg);
bce86c4163a3 Initial revision
kono
parents:
diff changeset
453 return 1;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
454 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
455 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
456 }
bce86c4163a3 Initial revision
kono
parents:
diff changeset
457
bce86c4163a3 Initial revision
kono
parents:
diff changeset
458 return 0;
bce86c4163a3 Initial revision
kono
parents:
diff changeset
459 }