1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Message (search a.k.a. argument) list handling.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #ifndef HAVE_AMALGAMATION
50 CMNEW
= 1<<0, /* New messages */
51 CMOLD
= 1<<1, /* Old messages */
52 CMUNREAD
= 1<<2, /* Unread messages */
53 CMDELETED
=1<<3, /* Deleted messages */
54 CMREAD
= 1<<4, /* Read messages */
55 CMFLAG
= 1<<5, /* Flagged messages */
56 CMANSWER
= 1<<6, /* Answered messages */
57 CMDRAFT
= 1<<7, /* Draft messages */
58 CMSPAM
= 1<<8 /* Spam messages */
62 char co_char
; /* What to find past : */
63 int co_bit
; /* Associated modifier bit */
64 int co_mask
; /* m_status bits to mask */
65 int co_equal
; /* ... must equal this */
73 static struct coltab
const _coltab
[] = {
74 { 'n', CMNEW
, MNEW
, MNEW
},
75 { 'o', CMOLD
, MNEW
, 0 },
76 { 'u', CMUNREAD
, MREAD
, 0 },
77 { 'd', CMDELETED
, MDELETED
, MDELETED
},
78 { 'r', CMREAD
, MREAD
, MREAD
},
79 { 'f', CMFLAG
, MFLAGGED
, MFLAGGED
},
80 { 'a', CMANSWER
, MANSWERED
, MANSWERED
},
81 { 't', CMDRAFT
, MDRAFTED
, MDRAFTED
},
82 { 's', CMSPAM
, MSPAM
, MSPAM
},
86 static struct lex
const _singles
[] = {
101 static int lastcolmod
;
102 static size_t STRINGLEN
;
103 static int lexnumber
; /* Number of TNUMBER from scan() */
104 static char *lexstring
; /* String from TSTRING, scan() */
105 static int regretp
; /* Pointer to TOS of regret tokens */
106 static int regretstack
[REGDEP
]; /* Stack of regretted tokens */
107 static char *string_stack
[REGDEP
]; /* Stack of regretted strings */
108 static int numberstack
[REGDEP
]; /* Stack of regretted numbers */
109 static int threadflag
; /* mark entire threads */
111 /* Append, taking care of resizes */
112 static char ** add_to_namelist(char ***namelist
, size_t *nmlsize
,
113 char **np
, char *string
);
115 /* Mark all messages that the user wanted from the command line in the message
116 * structure. Return 0 on success, -1 on error */
117 static int markall(char *buf
, int f
);
119 /* Turn the character after a colon modifier into a bit value */
120 static int evalcol(int col
);
122 /* Check the passed message number for legality and proper flags. If f is
123 * MDELETED, then either kind will do. Otherwise, the message has to be
125 static int check(int mesg
, int f
);
127 /* Scan out a single lexical item and return its token number, updating the
128 * string pointer passed **sp. Also, store the value of the number or string
129 * scanned in lexnumber or lexstring as appropriate. In any event, store the
130 * scanned `thing' in lexstring */
131 static int scan(char **sp
);
133 /* Unscan the named token by pushing it onto the regret stack */
134 static void regret(int token
);
136 /* Reset all the scanner global variables */
137 static void scaninit(void);
139 /* See if the passed name sent the passed message */
140 static bool_t
_matchsender(struct message
*mp
, char const *str
, bool_t allnet
);
142 static bool_t
_matchmid(struct message
*mp
, char *id
, enum idfield idfield
);
144 /* See if the given string matches.
145 * For the purpose of the scan, we ignore case differences.
146 * This is the engine behind the `/' search */
147 static bool_t
_match_dash(struct message
*mp
, char const *str
);
149 /* See if the given search expression matches.
150 * For the purpose of the scan, we ignore case differences.
151 * This is the engine behind the `@[..]@' search */
152 static bool_t
_match_qm(struct message
*mp
, struct search_expr
*sep
);
154 /* Unmark the named message */
155 static void unmark(int mesg
);
157 /* Return the message number corresponding to the passed meta character */
158 static int metamess(int meta
, int f
);
161 add_to_namelist(char ***namelist
, size_t *nmlsize
, char **np
, char *string
)
166 if ((idx
= PTR2SIZE(np
- *namelist
)) >= *nmlsize
) {
167 *namelist
= srealloc(*namelist
, (*nmlsize
+= 8) * sizeof *np
);
168 np
= *namelist
+ idx
;
176 markall(char *buf
, int f
)
178 #define markall_ret(i) do { rv = i; goto jleave; } while (0);
180 /* TODO use a bit carrier for all the states */
181 char **np
, **nq
, **namelist
, *bufp
, *id
= NULL
, *cp
;
182 int rv
= 0, i
, tok
, beg
, mc
, other
, valdot
, colmod
, colresult
;
183 struct message
*mp
, *mx
;
184 bool_t star
, topen
, tback
;
186 enum idfield idfield
= ID_REFERENCES
;
192 lexstring
= ac_alloc(STRINGLEN
= 2 * strlen(buf
) + 1);
193 valdot
= (int)PTR2SIZE(dot
- message
+ 1);
196 for (i
= 1; i
<= msgCount
; ++i
) {
199 mf
= message
[i
- 1].m_flag
;
205 message
[i
- 1].m_flag
= mf
;
208 namelist
= smalloc((nmlsize
= 8) * sizeof *namelist
);
212 beg
= mc
= star
= other
= topen
= tback
= FAL0
;
217 for (tok
= scan(&bufp
); tok
!= TEOL
;) {
222 fprintf(stderr
, tr(112, "No numbers mixed with *\n"));
225 list_saw_numbers
= TRU1
;
229 if (check(lexnumber
, f
))
232 while (mb
.mb_threaded
? 1 : i
<= lexnumber
) {
233 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
234 (f
== MDELETED
|| !(message
[i
- 1].m_flag
& MDELETED
)))
236 if (mb
.mb_threaded
) {
239 mx
= next_in_thread(&message
[i
- 1]);
242 i
= (int)PTR2SIZE(mx
- message
+ 1);
261 msglist_is_single
= FAL0
;
263 printf(tr(113, "Non-numeric second argument\n"));
268 if (mb
.mb_threaded
) {
269 mx
= next_in_thread(&message
[i
- 1]);
270 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : msgCount
+ 1;
274 fprintf(stderr
, tr(114, "Referencing beyond EOF\n"));
277 } while (message
[i
-1].m_flag
== MHIDDEN
||
278 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
283 msglist_is_single
= FAL0
;
287 if (mb
.mb_threaded
) {
288 mx
= prev_in_thread(&message
[i
- 1]);
289 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : 0;
293 fprintf(stderr
, tr(115, "Referencing before 1\n"));
296 } while ((message
[i
- 1].m_flag
& MHIDDEN
) ||
297 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
303 msglist_is_single
= FAL0
;
305 fprintf(stderr
, tr(116, "Non-numeric second argument\n"));
309 if (lexstring
[0] == ':') {
310 colresult
= evalcol(lexstring
[1]);
311 if (colresult
== 0) {
312 fprintf(stderr
, tr(117, "Unknown colon modifier \"%s\"\n"),
319 np
= add_to_namelist(&namelist
, &nmlsize
, np
, savestr(lexstring
));
323 #ifdef HAVE_IMAP_SEARCH
324 msglist_is_single
= FAL0
;
325 if (imap_search(lexstring
, f
) == STOP
)
329 fprintf(stderr
, tr(42,
330 "`%s': the used selector is optional and not available\n"),
340 msglist_is_single
= FAL0
;
341 lexnumber
= metamess(lexstring
[0], f
);
347 msglist_is_single
= FAL0
;
349 for (i
= 1; i
<= msgCount
; i
++) {
350 if ((message
[i
- 1].m_flag
& MHIDDEN
) ||
351 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
)
353 if (message
[i
- 1].m_flag
& MOLDMARK
)
359 msglist_is_single
= FAL0
;
361 fprintf(stderr
, tr(118, "Can't mix \"*\" with anything\n"));
368 msglist_is_single
= FAL0
;
370 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
371 imap_getheaders(1, msgCount
);
373 if (id
== NULL
&& (cp
= hfield1("in-reply-to", dot
)) != NULL
) {
375 idfield
= ID_IN_REPLY_TO
;
377 if (id
== NULL
&& (cp
= hfield1("references", dot
)) != NULL
) {
380 if ((enp
= extract(cp
, GREF
)) != NULL
) {
381 while (enp
->n_flink
!= NULL
)
383 id
= savestr(enp
->n_name
);
384 idfield
= ID_REFERENCES
;
389 "Cannot determine parent Message-ID of the current message\n"));
395 list_saw_numbers
= TRU1
;
396 msglist_is_single
= FAL0
;
404 np
= add_to_namelist(&namelist
, &nmlsize
, np
, NULL
);
408 for (i
= 0; i
< msgCount
; ++i
) {
409 if (!(message
[i
].m_flag
& MHIDDEN
) &&
410 (message
[i
].m_flag
& MDELETED
) == (unsigned)f
) {
417 printf(tr(119, "No applicable messages.\n"));
423 if ((topen
|| tback
) && mc
== 0) {
424 for (i
= 0; i
< msgCount
; ++i
)
425 if (message
[i
].m_flag
& MMARK
)
430 fprintf(stderr
, tr(131, "No previously marked messages.\n"));
432 printf("No messages satisfy (criteria).\n");/*TODO tr*/
438 /* If no numbers were given, mark all messages, so that we can unmark
439 * any whose sender was not selected if any user names were given */
440 if ((np
> namelist
|| colmod
!= 0 || id
) && mc
== 0)
441 for (i
= 1; i
<= msgCount
; ++i
) {
442 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
443 (message
[i
- 1].m_flag
& MDELETED
) == (unsigned)f
)
447 /* If any names were given, eliminate any messages which don't match */
448 if (np
> namelist
|| id
) {
449 struct search_expr
*sep
= NULL
;
452 /* The `@' search works with struct search_expr, so build an array.
453 * To simplify array, i.e., regex_t destruction, and optimize for the
454 * common case we walk the entire array even in case of errors */
456 sep
= scalloc(PTR2SIZE(np
- namelist
), sizeof(*sep
));
457 for (j
= 0, nq
= namelist
; *nq
!= NULL
; ++j
, ++nq
) {
461 if (*x
!= '@' || rv
< 0)
464 for (y
= x
+ 1;; ++y
) {
465 if (*y
== '\0' || !fieldnamechar(*y
)) {
474 sep
[j
].ss_where
= (x
== NULL
|| x
- 1 == *nq
) ? "subject"
475 : savestrbuf(*nq
+ 1, PTR2SIZE(x
- *nq
) - 1);
477 x
= (x
== NULL
? *nq
: x
) + 1;
478 if (*x
== '\0') { /* XXX Simply remove from list instead? */
479 fprintf(stderr
, tr(525, "Empty `[@..]@' search expression\n"));
484 if (anyof("^.[]*+?(){}|$", x
)) {
485 sep
[j
].ss_sexpr
= NULL
;
486 if (regcomp(&sep
[j
].ss_reexpr
, x
,
487 REG_EXTENDED
| REG_ICASE
| REG_NOSUB
) != 0) {
488 fprintf(stderr
, tr(526,
489 "Invalid regular expression: >>> %s <<<\n"), x
);
498 goto jnamesearch_sepfree
;
502 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
503 imap_getheaders(1, msgCount
);
506 allnet
= ok_blook(allnet
);
507 for (i
= 1; i
<= msgCount
; ++i
) {
508 mp
= message
+ i
- 1;
511 for (nq
= namelist
; *nq
!= NULL
; ++nq
) {
513 if (_match_qm(mp
, sep
+ PTR2SIZE(nq
- namelist
))) {
517 } else if (**nq
== '/') {
518 if (_match_dash(mp
, *nq
)) {
522 } else if (_matchsender(mp
, *nq
, allnet
)) {
528 if (j
== 0 && id
&& _matchmid(mp
, id
, idfield
))
531 mp
->m_flag
&= ~MMARK
;
536 /* Make sure we got some decent messages */
538 for (i
= 1; i
<= msgCount
; ++i
)
539 if (message
[i
- 1].m_flag
& MMARK
) {
544 if (!inhook
&& np
> namelist
) {
545 printf(tr(120, "No applicable messages from {%s"), namelist
[0]);
546 for (nq
= namelist
+ 1; *nq
!= NULL
; ++nq
)
547 printf(tr(121, ", %s"), *nq
);
548 printf(tr(122, "}\n"));
550 printf(tr(227, "Parent message not found\n"));
552 goto jnamesearch_sepfree
;
558 for (j
= PTR2SIZE(np
- namelist
); j
-- != 0;)
559 if (sep
[j
].ss_sexpr
== NULL
)
560 regfree(&sep
[j
].ss_reexpr
);
568 /* If any colon modifiers were given, go through and unmark any
569 * messages which do not satisfy the modifiers */
571 for (i
= 1; i
<= msgCount
; ++i
) {
572 struct coltab
const *colp
;
575 mp
= &message
[i
- 1];
576 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
577 if ((colp
->co_bit
& colmod
) &&
578 ((mp
->m_flag
& colp
->co_mask
) == (unsigned)colp
->co_equal
))
583 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
584 if (mp
->m_flag
& MMARK
)
586 if (PTRCMP(mp
, >=, message
+ msgCount
)) {
587 struct coltab
const *colp
;
590 printf(tr(123, "No messages satisfy"));
591 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
592 if (colp
->co_bit
& colmod
)
593 printf(" :%c", colp
->co_char
);
613 struct coltab
const *colp
;
621 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
622 if (colp
->co_char
== col
) {
632 check(int mesg
, int f
)
637 if (mesg
< 1 || mesg
> msgCount
) {
638 printf(tr(124, "%d: Invalid message number\n"), mesg
);
641 mp
= &message
[mesg
- 1];
642 if (mp
->m_flag
& MHIDDEN
||
643 (f
!= MDELETED
&& (mp
->m_flag
& MDELETED
) != 0)) {
644 fprintf(stderr
, tr(125, "%d: Inappropriate message\n"), mesg
);
660 int rv
, c
, inquote
, quotec
;
661 struct lex
const *lp
;
665 strncpy(lexstring
, string_stack
[regretp
], STRINGLEN
);
666 lexstring
[STRINGLEN
-1]='\0';
667 lexnumber
= numberstack
[regretp
];
668 rv
= regretstack
[regretp
--];
676 /* strip away leading white space */
680 /* If no characters remain, we are at end of line, so report that */
687 /* Select members of a message thread */
690 if (*cp
== '\0' || spacechar(*cp
)) {
700 /* If the leading character is a digit, scan the number and convert it
701 * on the fly. Return TNUMBER when done */
704 while (digitchar(c
)) {
705 lexnumber
= lexnumber
*10 + c
- '0';
715 /* An IMAP SEARCH list. Note that TOPEN has always been included in
716 * singles[] in Mail and mailx. Thus although there is no formal
717 * definition for (LIST) lists, they do not collide with historical
718 * practice because a subject string (LIST) could never been matched
725 if ((c
= *cp
++&0377) == '\0') {
727 fprintf(stderr
, "Missing \")\".\n");
731 if (inquote
&& c
== '\\') {
744 else if (spacechar(c
)) {
745 /* Replace unquoted whitespace by single space characters, to make
746 * the string IMAP SEARCH conformant */
752 } while (c
!= ')' || level
> 0);
759 /* Check for single character tokens; return such if found */
760 for (lp
= _singles
; lp
->l_char
!= '\0'; ++lp
)
761 if (c
== lp
->l_char
) {
769 /* We've got a string! Copy all the characters of the string into
770 * lexstring, until we see a null, space, or tab. If the lead character is
771 * a " or ', save it and scan until you get another */
773 if (c
== '\'' || c
== '"') {
778 if (quotec
== 0 && c
== '\\' && *cp
)
784 if (quotec
== 0 && blankchar(c
))
786 if (PTRCMP(cp2
- lexstring
, <, STRINGLEN
- 1))
790 if (quotec
&& c
== 0) {
791 fprintf(stderr
, tr(127, "Missing %c\n"), quotec
);
807 if (++regretp
>= REGDEP
)
808 panic(tr(128, "Too many regrets"));
809 regretstack
[regretp
] = token
;
810 lexstring
[STRINGLEN
- 1] = '\0';
811 string_stack
[regretp
] = savestr(lexstring
);
812 numberstack
[regretp
] = lexnumber
;
826 _matchsender(struct message
*mp
, char const *str
, bool_t allnet
)
832 char *cp
= nameof(mp
, 0);
835 if ((*cp
== '@' || *cp
== '\0') && (*str
== '@' || *str
== '\0')) {
841 } while (cp
++, *str
++ != '\0');
845 rv
= !strcmp(str
, (ok_blook(showname
) ? realname
: skin
)(name1(mp
, 0)));
852 _matchmid(struct message
*mp
, char *id
, enum idfield idfield
)
858 if ((cp
= hfield1("message-id", mp
)) != NULL
) {
861 rv
= !msgidcmp(id
, cp
);
863 case ID_IN_REPLY_TO
: {
866 if ((np
= extract(id
, GREF
)) != NULL
)
868 if (!msgidcmp(np
->n_name
, cp
)) {
872 } while ((np
= np
->n_flink
) != NULL
);
884 _match_dash(struct message
*mp
, char const *str
)
886 static char lastscan
[128];
889 char *hfield
, *hbody
;
893 if (*++str
== '\0') {
896 strncpy(lastscan
, str
, sizeof lastscan
); /* XXX use new n_str object! */
897 lastscan
[sizeof lastscan
- 1] = '\0';
900 /* Now look, ignoring case, for the word in the string */
901 if (ok_blook(searchheaders
) && (hfield
= strchr(str
, ':'))) {
902 size_t l
= PTR2SIZE(hfield
- str
);
903 hfield
= ac_alloc(l
+ 1);
904 memcpy(hfield
, str
, l
);
906 hbody
= hfieldX(hfield
, mp
);
908 hfield
= UNCONST(str
+ l
+ 1);
910 hfield
= UNCONST(str
);
911 hbody
= hfield1("subject", mp
);
919 in
.l
= strlen(hbody
);
920 mime_fromhdr(&in
, &out
, TD_ICONV
);
921 rv
= substr(out
.s
, hfield
);
929 _match_qm(struct message
*mp
, struct search_expr
*sep
)
932 char *nfield
, *cfield
;
936 nfield
= savestr(sep
->ss_where
);
938 while ((cfield
= n_strsep(&nfield
, ',', TRU1
)) != NULL
) {
939 if (!asccasecmp(cfield
, "body")) {
942 if ((rv
= message_match(mp
, sep
, rv
)))
944 } else if (!asccasecmp(cfield
, "text")) {
947 } else if ((in
.s
= hfieldX(cfield
, mp
)) == NULL
)
951 mime_fromhdr(&in
, &out
, TD_ICONV
);
953 if (sep
->ss_sexpr
== NULL
)
954 rv
= (regexec(&sep
->ss_reexpr
, out
.s
, 0,NULL
, 0) != REG_NOMATCH
);
957 rv
= substr(out
.s
, sep
->ss_sexpr
);
974 if (i
< 1 || UICMP(z
, i
, >, msgCount
))
975 panic(tr(130, "Bad message number to unmark"));
976 message
[i
- 1].m_flag
&= ~MMARK
;
981 metamess(int meta
, int f
)
989 case '^': /* First 'good' message left */
990 mp
= mb
.mb_threaded
? threadroot
: &message
[0];
991 while (PTRCMP(mp
, <, message
+ msgCount
)) {
992 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) ==(unsigned)f
){
993 c
= (int)PTR2SIZE(mp
- message
+ 1);
996 if (mb
.mb_threaded
) {
997 mp
= next_in_thread(mp
);
1004 printf(tr(132, "No applicable messages\n"));
1007 case '$': /* Last 'good message left */
1008 mp
= mb
.mb_threaded
? this_in_thread(threadroot
, -1)
1009 : &message
[msgCount
-1];
1010 while (mp
>= &message
[0]) {
1011 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1012 c
= (int)PTR2SIZE(mp
- message
+ 1);
1015 if (mb
.mb_threaded
) {
1016 mp
= prev_in_thread(mp
);
1023 printf(tr(132, "No applicable messages\n"));
1027 /* Current message */
1028 m
= dot
- message
+ 1;
1029 if ((dot
->m_flag
& MHIDDEN
) || (dot
->m_flag
& MDELETED
) != (unsigned)f
) {
1030 printf(tr(133, "%d: Inappropriate message\n"), m
);
1037 /* Previously current message */
1038 if (prevdot
== NULL
) {
1039 fprintf(stderr
, tr(228, "No previously current message\n"));
1042 m
= prevdot
- message
+ 1;
1043 if ((prevdot
->m_flag
& MHIDDEN
) ||
1044 (prevdot
->m_flag
& MDELETED
) != (unsigned)f
) {
1045 fprintf(stderr
, tr(133, "%d: Inappropriate message\n"), m
);
1052 fprintf(stderr
, tr(134, "Unknown metachar (%c)\n"), c
);
1064 getmsglist(char *buf
, int *vector
, int flags
)
1071 msglist_is_single
= FAL0
;
1073 if (msgCount
== 0) {
1079 msglist_is_single
= TRU1
;
1080 if (markall(buf
, flags
) < 0) {
1088 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1089 if (mp
->m_flag
& MMARK
) {
1090 if ((mp
->m_flag
& MNEWEST
) == 0)
1091 unmark((int)PTR2SIZE(mp
- message
+ 1));
1101 if (mb
.mb_threaded
== 0) {
1102 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1103 if (mp
->m_flag
& MMARK
)
1104 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1106 for (mp
= threadroot
; mp
!= NULL
; mp
= next_in_thread(mp
))
1107 if (mp
->m_flag
& MMARK
)
1108 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1111 mc
= (int)PTR2SIZE(ip
- vector
);
1112 msglist_is_single
= (mc
== 1);
1119 getrawlist(char const *line
, size_t linesize
, char **argv
, int argc
,
1122 char c
, *cp2
, quotec
, *linebuf
;
1127 list_saw_numbers
= FAL0
;
1131 linebuf
= ac_alloc(linesize
+ 1);
1133 for (; blankchar(*cp
); ++cp
)
1137 if (argn
>= argc
- 1) {
1138 printf(tr(126, "Too many elements in the list; excess discarded.\n"));
1143 while ((c
= *cp
) != '\0') {
1145 if (quotec
!= '\0') {
1150 } else if (c
== '\\')
1151 switch (c
= *cp
++) {
1157 case '0': case '1': case '2': case '3':
1158 case '4': case '5': case '6': case '7':
1160 if (*cp >= '0' && *cp <= '7')
1161 c = c * 8 + *cp++ - '0';
1162 if (*cp >= '0' && *cp <= '7')
1163 c = c * 8 + *cp++ - '0';
1186 if (cp
[-1] != quotec
|| echolist
)
1190 /*else if (c == '^') {
1194 /\* null doesn't show up anyway *\/
1195 else if ((c >= 'A' && c <= '_') ||
1196 (c >= 'a' && c <= 'z'))
1204 } else if (c
== '"' || c
== '\'') {
1208 } else if (c
== '\\' && !echolist
) {
1213 } else if (blankchar(c
))
1219 argv
[argn
++] = savestr(linebuf
);
1234 if (msgCount
== 0) {
1242 mb
.mb_threaded
? mp
!= NULL
: PTRCMP(mp
, <, message
+ msgCount
);
1243 mb
.mb_threaded
? mp
= next_in_thread(mp
) : ++mp
) {
1244 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (unsigned)f
) {
1245 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1250 if (dot
> message
) {
1251 for (mp
= dot
-1; (mb
.mb_threaded
? mp
!= NULL
: mp
>= message
);
1252 mb
.mb_threaded
? mp
= prev_in_thread(mp
) : --mp
) {
1253 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (unsigned)f
) {
1254 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1266 mark(int mesg
, int f
)
1273 if (i
< 1 || i
> msgCount
)
1274 panic(tr(129, "Bad message number to mark"));
1275 if (mb
.mb_threaded
== 1 && threadflag
) {
1276 if ((message
[i
- 1].m_flag
& MHIDDEN
) == 0) {
1277 if (f
== MDELETED
|| (message
[i
- 1].m_flag
&MDELETED
) == 0)
1278 message
[i
- 1].m_flag
|= MMARK
;
1281 if (message
[i
- 1].m_child
) {
1282 mp
= message
[i
- 1].m_child
;
1283 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1284 for (mp
= mp
->m_younger
; mp
; mp
= mp
->m_younger
)
1285 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1288 message
[i
- 1].m_flag
|= MMARK
;
1292 /* vim:set fenc=utf-8:s-it-mode */