0
|
1 /* mark.c - mark messages */
|
|
2 #ifndef lint
|
12
|
3 static char ident[] = "@(#)$Id: mark.c,v 1.1.1.1 2005/04/18 14:46:07 kono Exp $";
|
0
|
4 #endif /* lint */
|
|
5
|
|
6 #include "../h/mh.h"
|
|
7 #include <stdio.h>
|
|
8 #ifdef LOCALE
|
|
9 #include <locale.h>
|
|
10 #endif
|
|
11
|
|
12 /* */
|
|
13
|
|
14 static struct swit switches[] = {
|
|
15 #define ADDSW 0
|
|
16 "add", 0,
|
|
17 #define DELSW 1
|
|
18 "delete", 0,
|
|
19 #define LSTSW 2
|
|
20 "list", 0,
|
|
21
|
|
22 #define SEQSW 3
|
|
23 "sequence name", 0,
|
|
24
|
|
25 #define PUBLSW 4
|
|
26 "public", 0,
|
|
27 #define NPUBLSW 5
|
|
28 "nopublic", 0,
|
|
29
|
|
30 #define ZEROSW 6
|
|
31 "zero", 0,
|
|
32 #define NZEROSW 7
|
|
33 "nozero", 0,
|
|
34
|
|
35 #define HELPSW 8
|
|
36 "help", 4,
|
|
37
|
|
38 #define DEBUGSW 9
|
|
39 "debug", -5,
|
|
40
|
|
41 NULL, 0
|
|
42 };
|
|
43
|
|
44 /* */
|
|
45
|
|
46 /* ARGSUSED */
|
|
47
|
|
48 main (argc, argv)
|
|
49 int argc;
|
|
50 char **argv;
|
|
51 {
|
|
52 int addsw = 0,
|
|
53 deletesw = 0,
|
|
54 debugsw = 0,
|
|
55 listsw = 0,
|
|
56 publicsw = -1,
|
|
57 zerosw = 0,
|
|
58 seqp = 0,
|
|
59 msgp = 0,
|
|
60 i,
|
|
61 msgnum;
|
|
62 char *cp,
|
|
63 *maildir,
|
|
64 *folder = NULL,
|
|
65 buf[100],
|
|
66 **ap,
|
|
67 **argp,
|
|
68 *arguments[MAXARGS],
|
|
69 *seqs[NATTRS + 1],
|
|
70 *msgs[MAXARGS];
|
|
71 struct msgs *mp;
|
|
72
|
|
73 #ifdef LOCALE
|
|
74 setlocale(LC_ALL, "");
|
|
75 #endif
|
|
76 #ifdef JAPAN
|
|
77 ml_init();
|
|
78 #endif /* JAPAN */
|
|
79 invo_name = r1bindex (argv[0], '/');
|
|
80 if ((cp = m_find (invo_name)) != NULL) {
|
|
81 ap = brkstring (cp = getcpy (cp), " ", "\n");
|
|
82 ap = copyip (ap, arguments);
|
|
83 }
|
|
84 else
|
|
85 ap = arguments;
|
|
86 (void) copyip (argv + 1, ap);
|
|
87 argp = arguments;
|
|
88
|
|
89 /* */
|
|
90
|
|
91 while (cp = *argp++) {
|
|
92 if (*cp == '-')
|
|
93 switch (smatch (++cp, switches)) {
|
|
94 case AMBIGSW:
|
|
95 ambigsw (cp, switches);
|
|
96 done (1);
|
|
97 case UNKWNSW:
|
|
98 adios (NULLCP, "-%s unknown\n", cp);
|
|
99 case HELPSW:
|
|
100 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
|
|
101 invo_name);
|
|
102 help (buf, switches);
|
|
103 done (1);
|
|
104
|
|
105 case ADDSW:
|
|
106 addsw++;
|
|
107 deletesw = listsw = 0;
|
|
108 continue;
|
|
109 case DELSW:
|
|
110 deletesw++;
|
|
111 addsw = listsw = 0;
|
|
112 continue;
|
|
113 case LSTSW:
|
|
114 listsw++;
|
|
115 addsw = deletesw = 0;
|
|
116 continue;
|
|
117
|
|
118 case SEQSW:
|
|
119 if (!(cp = *argp++) || *cp == '-')
|
|
120 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
121 if (seqp < NATTRS)
|
|
122 seqs[seqp++] = cp;
|
|
123 else
|
|
124 adios (NULLCP, "only %d sequences allowed!", NATTRS);
|
|
125 continue;
|
|
126
|
|
127 case PUBLSW:
|
|
128 publicsw = 1;
|
|
129 continue;
|
|
130 case NPUBLSW:
|
|
131 publicsw = 0;
|
|
132 continue;
|
|
133
|
|
134 case DEBUGSW:
|
|
135 debugsw++;
|
|
136 continue;
|
|
137
|
|
138 case ZEROSW:
|
|
139 zerosw++;
|
|
140 continue;
|
|
141 case NZEROSW:
|
|
142 zerosw = 0;
|
|
143 continue;
|
|
144 }
|
|
145 if (*cp == '+' || *cp == '@') {
|
|
146 if (folder)
|
|
147 adios (NULLCP, "only one folder at a time!");
|
|
148 else
|
|
149 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
|
|
150 }
|
|
151 else
|
|
152 msgs[msgp++] = cp;
|
|
153 }
|
|
154
|
|
155 /* */
|
|
156
|
|
157 if (!addsw && !deletesw && !listsw)
|
|
158 if (seqp)
|
|
159 addsw++;
|
|
160 else
|
|
161 listsw++;
|
|
162
|
|
163 if (!m_find ("path"))
|
|
164 free (path ("./", TFOLDER));
|
|
165 if (!msgp)
|
|
166 msgs[msgp++] = listsw ? "all" :"cur";
|
|
167 if (!folder)
|
|
168 folder = m_getfolder ();
|
|
169 maildir = m_maildir (folder);
|
|
170
|
|
171 if (chdir (maildir) == NOTOK)
|
|
172 adios (maildir, "unable to change directory to");
|
|
173 if (!(mp = m_gmsg (folder)))
|
|
174 adios (NULLCP, "unable to read folder %s", folder);
|
|
175 if (mp -> hghmsg == 0)
|
|
176 adios (NULLCP, "no messages in %s", folder);
|
|
177
|
|
178 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
179 if (!m_convert (mp, msgs[msgnum]))
|
|
180 done (1);
|
|
181
|
|
182 if (publicsw == -1)
|
|
183 publicsw = mp -> msgflags & READONLY ? 0 : 1;
|
|
184 if (publicsw && (mp -> msgflags & READONLY))
|
|
185 adios (NULLCP, "folder %s is read-only, so -public not allowed",
|
|
186 folder);
|
|
187
|
|
188 /* */
|
|
189
|
|
190 if (debugsw) {
|
|
191 printf ("invo_name=%s mypath=%s defpath=%s\n",
|
|
192 invo_name, mypath, defpath);
|
|
193 printf ("ctxpath=%s context flags=%s\n",
|
|
194 ctxpath, sprintb (buf, (unsigned) ctxflags, DBITS));
|
|
195 printf ("foldpath=%s flags=%s\n",
|
|
196 mp -> foldpath,
|
|
197 sprintb (buf, (unsigned) mp -> msgflags, FBITS));
|
|
198 printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n",
|
|
199 mp -> lowmsg, mp -> hghmsg, mp -> nummsg, mp -> curmsg);
|
|
200 printf ("lowsel=%d hghsel=%d numsel=%d\n",
|
|
201 mp -> lowsel, mp -> hghsel, mp -> numsel);
|
|
202 #ifndef MTR
|
|
203 printf ("lowoff=%d hghoff=%d\n",
|
|
204 mp -> lowoff, mp -> hghoff);
|
|
205 #else /* MTR */
|
|
206 printf ("lowoff=%d hghoff=%d msgbase=0x%x msgstats=0x%x\n",
|
|
207 mp -> lowoff, mp -> hghoff, mp -> msgbase, mp -> msgstats);
|
|
208 #endif /* MTR */
|
|
209 }
|
|
210
|
|
211 if (seqp == 0 && (addsw || deletesw))
|
|
212 adios (NULLCP, "-%s requires at least one -sequence argument",
|
|
213 addsw ? "add" : "delete");
|
|
214 seqs[seqp] = NULL;
|
|
215
|
|
216 if (addsw)
|
|
217 for (seqp = 0; seqs[seqp]; seqp++) {
|
|
218 if (zerosw && !m_seqnew (mp, seqs[seqp], publicsw))
|
|
219 done (1);
|
|
220 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
|
|
221 if (mp -> msgstats[msgnum] & SELECTED)
|
|
222 if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
|
|
223 done (1);
|
|
224 }
|
|
225
|
|
226 if (deletesw)
|
|
227 for (seqp = 0; seqs[seqp]; seqp++) {
|
|
228 if (zerosw)
|
|
229 for (msgnum = mp -> lowmsg; msgnum <= mp -> hghmsg; msgnum++)
|
|
230 if (mp -> msgstats[msgnum] & EXISTS)
|
|
231 if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
|
|
232 done (1);
|
|
233 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
|
|
234 if (mp -> msgstats[msgnum] & SELECTED)
|
|
235 if (!m_seqdel (mp, seqs[seqp], msgnum))
|
|
236 done (1);
|
|
237 }
|
|
238
|
|
239 if (listsw) {
|
|
240 int bits = FFATTRSLOT;
|
|
241
|
|
242 #define empty(s) ((s) ? (s) : "")
|
|
243 if (seqp == 0)
|
|
244 for (i = 0; mp -> msgattrs[i]; i++)
|
|
245 printf ("%s%s: %s\n", mp -> msgattrs[i],
|
|
246 mp -> attrstats & (1 << (bits + i))
|
|
247 ? " (private)" : "",
|
|
248 empty(m_seq (mp, mp -> msgattrs[i])));
|
|
249 else
|
|
250 for (seqp = 0; seqs[seqp]; seqp++)
|
|
251 printf ("%s: %s\n", seqs[seqp], empty(m_seq (mp, seqs[seqp])));
|
|
252 #undef empty
|
|
253
|
|
254 if (debugsw)
|
|
255 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
|
|
256 if (mp -> msgstats[msgnum] & SELECTED)
|
|
257 printf ("%*d: %s\n", DMAXFOLDER, msgnum,
|
|
258 sprintb (buf, (unsigned) mp -> msgstats[msgnum],
|
|
259 m_seqbits (mp)));
|
|
260 }
|
|
261
|
|
262 m_replace (pfolder, folder);
|
|
263 m_sync (mp);
|
|
264 m_update ();
|
|
265
|
|
266 done (0);
|
|
267 }
|