2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
16 struct swit switches
[] = {
30 if(!(cp
= mhnam(&argv
[1])))
32 printf("%s\n", cp
); /* Expanded message list */
43 char *folder
, *maildir
, *msgs
[100];
47 char *arguments
[50], **argp
;
49 setbuf(stdout
, _sobuf
);
53 VOID
copyip(args
, arguments
);
57 switch(smatch(++cp
, switches
)) {
58 case -2:ambigsw(cp
, switches
); /* ambiguous */
61 case -1:fprintf(stderr
, "mhnam: -%s unknown\n", cp
);
64 case 0: fprintf(stderr
, "\"-all\" changed to \"all\"\n");
66 case 1: help("mhnam [+folder] [msgs] [switches]", switches
);
71 fprintf(stderr
, "Only one folder at a time.\n");
74 folder
= path(cp
+1, TFOLDER
);
78 if(!m_find("path")) free(path("./", TFOLDER
));
80 /* Mhpath defaults to the folder name */
82 *** msgs[msgp++] = "cur";
86 folder
= m_getfolder();
87 maildir
= m_maildir(folder
);
94 if(chdir(maildir
) < 0) {
95 fprintf(stderr
, "Can't chdir to: ");
100 if(!(mp
= m_gmsg(folder
))) {
101 fprintf(stderr
, "Can't read folder!?\n");
104 /* Need to accomodate MAXFOLDER messages instead of mp->hghmsg */
105 if( (char *) (mp
= (struct msgs
*)
106 realloc((char *) mp
, (unsigned)(sizeof *mp
+ MAXFOLDER
+ 1 + 2)))
110 /* Clear the newly allocated space */
111 for(j
= mp
->hghmsg
+ 1; j
<= MAXFOLDER
; j
++)
114 /* Mhpath permits empty folders */
115 /*** if(mp->hghmsg == 0) {
116 *** fprintf(stderr, "No messages in \"%s\".\n", folder);
122 for(msgnum
= 0; msgnum
< msgp
; msgnum
++)
123 if(!convert(msgs
[msgnum
]))
125 if(mp
->numsel
== 0) {
126 fprintf(stderr
, "mhnam: Never get here. \n");
129 if(mp
->numsel
> MAXARGS
-2) {
130 fprintf(stderr
, "mhnam: more than %d messages \n", MAXARGS
-2);
134 for(msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++)
135 if(mp
->msgstats
[msgnum
]&SELECTED
)
137 VOID
sprintf(buf
,"%s%c%s", maildir
,'/', m_name(msgnum
));
140 string
= add("\n", string
);
141 string
= add(buf
, string
);
142 /*** printf("buf %s string %s\n",buf,string); ***/
153 #define FIRST 1 /***/
156 convert(name
) /*** Slightly hacked version of ../subs/m_convert.c */
160 register int first
, last
;
161 int found
, range
, err
;
167 if(strcmp((cp
= name
), "new") == 0) /***/
169 if((err
= first
= getnew(cp
)) <= 0)
173 if(strcmp((cp
= name
), "all") == 0)
175 if((err
= first
= conv(cp
, FIRST
)) <= 0) /***/
177 if(*(cp
= delimp
) && *cp
!= '-' && *cp
!= ':') {
178 baddel
: fprintf(stderr
, "Illegal argument delimiter: \"%c\"\n", *delimp
);
183 if((err
= last
= conv(cp
, LAST
)) <= 0) { /***/
184 badbad
: if(err
== -1)
185 fprintf(stderr
, "No %s message\n", cp
);
186 else if (err
== -2) /***/
188 "Message %s out of range 1-%d\n",
191 badlist
: fprintf(stderr
, "Bad message list \"%s\".\n",
195 if(last
< first
) goto badlist
;
196 if(*delimp
) goto baddel
;
197 if(first
> mp
->hghmsg
|| last
< mp
->lowmsg
) {
198 rangerr
: fprintf(stderr
,"No messages in range \"%s\".\n",name
);
201 if(last
> mp
->hghmsg
)
203 if(first
< mp
->lowmsg
)
205 } else if(*cp
== ':') {
210 } else if(*cp
== '+') {
214 if((range
= atoi(bp
= cp
)) == 0)
216 while(isdigit(*bp
)) bp
++;
219 if((convdir
> 0 && first
> mp
->hghmsg
) ||
220 (convdir
< 0 && first
< mp
->lowmsg
))
222 if(first
< mp
->lowmsg
)
224 if(first
> mp
->hghmsg
)
226 for(last
= first
; last
>= mp
->lowmsg
&& last
<= mp
->hghmsg
;
228 if(mp
->msgstats
[last
]&EXISTS
)
231 if(last
< mp
->lowmsg
)
233 if(last
> mp
->hghmsg
)
236 range
= last
; last
= first
; first
= range
;
239 /*** Here's the hack: cur message, single numeric message,
240 *** or new message are permitted to be non-existent
242 single
: last
= first
;
243 mp
->msgstats
[first
] |= SELECT_EMPTY
;
245 while(first
<= last
) {
246 if(mp
->msgstats
[first
]&(EXISTS
|SELECT_EMPTY
)) { /***/
247 if(!(mp
->msgstats
[first
]&SELECTED
)) {
249 mp
->msgstats
[first
] |= SELECTED
;
250 if(first
< mp
->lowsel
)
252 if(first
> mp
->hghsel
)
264 conv(str
, callno
) /*** Slightly hacked version of ../subs/m_conv.c */
268 register char *cp
, *bp
;
275 while(isdigit(*bp
)) bp
++;
277 /*** return (i = atoi(cp)) > MAXFOLDER ? MAXFOLDER : i; ***/
278 /* If msg # <= MAXFOLDER, return it;
279 * if > MAXFOLDER but part of a range, return MAXFOLDER;
280 * if single explicit msg #, return error.
282 return (i
= atoi(cp
)) <= MAXFOLDER
? i
:
283 *delimp
|| callno
== LAST
? MAXFOLDER
: -2;
286 while((*cp
>= 'a' && *cp
<= 'z') || *cp
== '.')
290 if(strcmp(buf
, "first") == 0)
291 return(mp
->hghmsg
? mp
->lowmsg
: -1); /* Folder empty? */
292 /*** return(mp->lowmsg); ***/
293 else if(strcmp(buf
, "last") == 0) {
295 return(mp
->hghmsg
? mp
->hghmsg
: -1);
296 /*** return(mp->hghmsg); ***/
297 } else if(strcmp(buf
, "cur") == 0 || strcmp(buf
, ".") == 0)
298 return(mp
->curmsg
> 0 ? mp
->curmsg
: -1);
299 else if(strcmp(buf
, "prev") == 0) {
301 for(i
= (mp
->curmsg
<=mp
->hghmsg
)? mp
->curmsg
-1: mp
->hghmsg
;
302 i
>= mp
->lowmsg
; i
--) {
303 if(mp
->msgstats
[i
]&EXISTS
)
306 return(-1); /* non-existent message */
307 } else if(strcmp(buf
, "next") == 0) {
308 for(i
= (mp
->curmsg
>=mp
->lowmsg
)? mp
->curmsg
+1: mp
->lowmsg
;
309 i
<= mp
->hghmsg
; i
++) {
310 if(mp
->msgstats
[i
]&EXISTS
)
315 return(0); /* bad message list */
323 return(mp
->hghmsg
<MAXFOLDER
? mp
->hghmsg
+ 1 :