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 x
= strchr(++x
, '?');
465 sep
[j
].ss_where
= (x
== NULL
|| x
- 1 == *nq
) ? "subject"
466 : savestrbuf(*nq
+ 1, PTR2SIZE(x
- *nq
) - 1);
468 x
= (x
== NULL
? *nq
: x
) + 1;
469 if (*x
== '\0') { /* XXX Simply remove from list instead? */
470 fprintf(stderr
, tr(525, "Empty `?[..]?' search expression\n"));
475 if (anyof("^.[]*+?(){}|$", x
)) {
476 sep
[j
].ss_sexpr
= NULL
;
477 if (regcomp(&sep
[j
].ss_reexpr
, x
,
478 REG_EXTENDED
| REG_ICASE
| REG_NOSUB
) != 0) {
479 fprintf(stderr
, tr(526,
480 "Invalid regular expression: >>> %s <<<\n"), x
);
489 goto jnamesearch_sepfree
;
493 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
494 imap_getheaders(1, msgCount
);
497 allnet
= ok_blook(allnet
);
498 for (i
= 1; i
<= msgCount
; ++i
) {
499 mp
= message
+ i
- 1;
502 for (nq
= namelist
; *nq
!= NULL
; ++nq
) {
504 if (_match_qm(mp
, sep
+ PTR2SIZE(nq
- namelist
))) {
508 } else if (**nq
== '/') {
509 if (_match_dash(mp
, *nq
)) {
513 } else if (_matchsender(mp
, *nq
, allnet
)) {
519 if (j
== 0 && id
&& _matchmid(mp
, id
, idfield
))
522 mp
->m_flag
&= ~MMARK
;
527 /* Make sure we got some decent messages */
529 for (i
= 1; i
<= msgCount
; ++i
)
530 if (message
[i
- 1].m_flag
& MMARK
) {
535 if (!inhook
&& np
> namelist
) {
536 printf(tr(120, "No applicable messages from {%s"), namelist
[0]);
537 for (nq
= namelist
+ 1; *nq
!= NULL
; ++nq
)
538 printf(tr(121, ", %s"), *nq
);
539 printf(tr(122, "}\n"));
541 printf(tr(227, "Parent message not found\n"));
543 goto jnamesearch_sepfree
;
549 for (j
= PTR2SIZE(np
- namelist
); j
-- != 0;)
550 if (sep
[j
].ss_sexpr
== NULL
)
551 regfree(&sep
[j
].ss_reexpr
);
559 /* If any colon modifiers were given, go through and unmark any
560 * messages which do not satisfy the modifiers */
562 for (i
= 1; i
<= msgCount
; ++i
) {
563 struct coltab
const *colp
;
566 mp
= &message
[i
- 1];
567 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
568 if ((colp
->co_bit
& colmod
) &&
569 ((mp
->m_flag
& colp
->co_mask
) == (unsigned)colp
->co_equal
))
574 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
575 if (mp
->m_flag
& MMARK
)
577 if (PTRCMP(mp
, >=, message
+ msgCount
)) {
578 struct coltab
const *colp
;
581 printf(tr(123, "No messages satisfy"));
582 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
583 if (colp
->co_bit
& colmod
)
584 printf(" :%c", colp
->co_char
);
604 struct coltab
const *colp
;
612 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
613 if (colp
->co_char
== col
) {
623 check(int mesg
, int f
)
628 if (mesg
< 1 || mesg
> msgCount
) {
629 printf(tr(124, "%d: Invalid message number\n"), mesg
);
632 mp
= &message
[mesg
- 1];
633 if (mp
->m_flag
& MHIDDEN
||
634 (f
!= MDELETED
&& (mp
->m_flag
& MDELETED
) != 0)) {
635 fprintf(stderr
, tr(125, "%d: Inappropriate message\n"), mesg
);
651 int rv
, c
, inquote
, quotec
;
652 struct lex
const *lp
;
656 strncpy(lexstring
, string_stack
[regretp
], STRINGLEN
);
657 lexstring
[STRINGLEN
-1]='\0';
658 lexnumber
= numberstack
[regretp
];
659 rv
= regretstack
[regretp
--];
667 /* strip away leading white space */
671 /* If no characters remain, we are at end of line, so report that */
678 /* Select members of a message thread */
681 if (*cp
== '\0' || spacechar(*cp
)) {
691 /* If the leading character is a digit, scan the number and convert it
692 * on the fly. Return TNUMBER when done */
695 while (digitchar(c
)) {
696 lexnumber
= lexnumber
*10 + c
- '0';
706 /* An IMAP SEARCH list. Note that TOPEN has always been included in
707 * singles[] in Mail and mailx. Thus although there is no formal
708 * definition for (LIST) lists, they do not collide with historical
709 * practice because a subject string (LIST) could never been matched
716 if ((c
= *cp
++&0377) == '\0') {
718 fprintf(stderr
, "Missing \")\".\n");
722 if (inquote
&& c
== '\\') {
735 else if (spacechar(c
)) {
736 /* Replace unquoted whitespace by single space characters, to make
737 * the string IMAP SEARCH conformant */
743 } while (c
!= ')' || level
> 0);
750 /* Check for single character tokens; return such if found */
751 for (lp
= _singles
; lp
->l_char
!= '\0'; ++lp
)
752 if (c
== lp
->l_char
) {
760 /* We've got a string! Copy all the characters of the string into
761 * lexstring, until we see a null, space, or tab. If the lead character is
762 * a " or ', save it and scan until you get another */
764 if (c
== '\'' || c
== '"') {
769 if (quotec
== 0 && c
== '\\' && *cp
)
775 if (quotec
== 0 && blankchar(c
))
777 if (PTRCMP(cp2
- lexstring
, <, STRINGLEN
- 1))
781 if (quotec
&& c
== 0) {
782 fprintf(stderr
, tr(127, "Missing %c\n"), quotec
);
798 if (++regretp
>= REGDEP
)
799 panic(tr(128, "Too many regrets"));
800 regretstack
[regretp
] = token
;
801 lexstring
[STRINGLEN
- 1] = '\0';
802 string_stack
[regretp
] = savestr(lexstring
);
803 numberstack
[regretp
] = lexnumber
;
817 _matchsender(struct message
*mp
, char const *str
, bool_t allnet
)
823 char *cp
= nameof(mp
, 0);
826 if ((*cp
== '@' || *cp
== '\0') && (*str
== '@' || *str
== '\0')) {
832 } while (cp
++, *str
++ != '\0');
836 rv
= !strcmp(str
, (ok_blook(showname
) ? realname
: skin
)(name1(mp
, 0)));
843 _matchmid(struct message
*mp
, char *id
, enum idfield idfield
)
849 if ((cp
= hfield1("message-id", mp
)) != NULL
) {
852 rv
= !msgidcmp(id
, cp
);
854 case ID_IN_REPLY_TO
: {
857 if ((np
= extract(id
, GREF
)) != NULL
)
859 if (!msgidcmp(np
->n_name
, cp
)) {
863 } while ((np
= np
->n_flink
) != NULL
);
875 _match_dash(struct message
*mp
, char const *str
)
877 static char lastscan
[128];
880 char *hfield
, *hbody
;
884 if (*++str
== '\0') {
887 strncpy(lastscan
, str
, sizeof lastscan
); /* XXX use new n_str object! */
888 lastscan
[sizeof lastscan
- 1] = '\0';
891 /* Now look, ignoring case, for the word in the string */
892 if (ok_blook(searchheaders
) && (hfield
= strchr(str
, ':'))) {
893 size_t l
= PTR2SIZE(hfield
- str
);
894 hfield
= ac_alloc(l
+ 1);
895 memcpy(hfield
, str
, l
);
897 hbody
= hfieldX(hfield
, mp
);
899 hfield
= UNCONST(str
+ l
+ 1);
901 hfield
= UNCONST(str
);
902 hbody
= hfield1("subject", mp
);
910 in
.l
= strlen(hbody
);
911 mime_fromhdr(&in
, &out
, TD_ICONV
);
912 rv
= substr(out
.s
, hfield
);
920 _match_qm(struct message
*mp
, struct search_expr
*sep
)
923 char *nfield
, *cfield
;
927 nfield
= savestr(sep
->ss_where
);
929 while ((cfield
= n_strsep(&nfield
, ',', TRU1
)) != NULL
) {
930 if (!asccasecmp(cfield
, "body")) {
933 if ((rv
= message_match(mp
, sep
, rv
)))
935 } else if (!asccasecmp(cfield
, "text")) {
938 } else if ((in
.s
= hfieldX(cfield
, mp
)) == NULL
)
942 mime_fromhdr(&in
, &out
, TD_ICONV
);
944 if (sep
->ss_sexpr
== NULL
)
945 rv
= (regexec(&sep
->ss_reexpr
, out
.s
, 0,NULL
, 0) != REG_NOMATCH
);
948 rv
= substr(out
.s
, sep
->ss_sexpr
);
965 if (i
< 1 || UICMP(z
, i
, >, msgCount
))
966 panic(tr(130, "Bad message number to unmark"));
967 message
[i
- 1].m_flag
&= ~MMARK
;
972 metamess(int meta
, int f
)
980 case '^': /* First 'good' message left */
981 mp
= mb
.mb_threaded
? threadroot
: &message
[0];
982 while (PTRCMP(mp
, <, message
+ msgCount
)) {
983 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) ==(unsigned)f
){
984 c
= (int)PTR2SIZE(mp
- message
+ 1);
987 if (mb
.mb_threaded
) {
988 mp
= next_in_thread(mp
);
995 printf(tr(132, "No applicable messages\n"));
998 case '$': /* Last 'good message left */
999 mp
= mb
.mb_threaded
? this_in_thread(threadroot
, -1)
1000 : &message
[msgCount
-1];
1001 while (mp
>= &message
[0]) {
1002 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1003 c
= (int)PTR2SIZE(mp
- message
+ 1);
1006 if (mb
.mb_threaded
) {
1007 mp
= prev_in_thread(mp
);
1014 printf(tr(132, "No applicable messages\n"));
1018 /* Current message */
1019 m
= dot
- message
+ 1;
1020 if ((dot
->m_flag
& MHIDDEN
) || (dot
->m_flag
& MDELETED
) != (unsigned)f
) {
1021 printf(tr(133, "%d: Inappropriate message\n"), m
);
1028 /* Previously current message */
1029 if (prevdot
== NULL
) {
1030 fprintf(stderr
, tr(228, "No previously current message\n"));
1033 m
= prevdot
- message
+ 1;
1034 if ((prevdot
->m_flag
& MHIDDEN
) ||
1035 (prevdot
->m_flag
& MDELETED
) != (unsigned)f
) {
1036 fprintf(stderr
, tr(133, "%d: Inappropriate message\n"), m
);
1043 fprintf(stderr
, tr(134, "Unknown metachar (%c)\n"), c
);
1055 getmsglist(char *buf
, int *vector
, int flags
)
1062 msglist_is_single
= FAL0
;
1064 if (msgCount
== 0) {
1070 msglist_is_single
= TRU1
;
1071 if (markall(buf
, flags
) < 0) {
1079 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1080 if (mp
->m_flag
& MMARK
) {
1081 if ((mp
->m_flag
& MNEWEST
) == 0)
1082 unmark((int)PTR2SIZE(mp
- message
+ 1));
1092 if (mb
.mb_threaded
== 0) {
1093 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1094 if (mp
->m_flag
& MMARK
)
1095 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1097 for (mp
= threadroot
; mp
!= NULL
; mp
= next_in_thread(mp
))
1098 if (mp
->m_flag
& MMARK
)
1099 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1102 mc
= (int)PTR2SIZE(ip
- vector
);
1103 msglist_is_single
= (mc
== 1);
1110 getrawlist(char const *line
, size_t linesize
, char **argv
, int argc
,
1113 char c
, *cp2
, quotec
, *linebuf
;
1118 list_saw_numbers
= FAL0
;
1122 linebuf
= ac_alloc(linesize
+ 1);
1124 for (; blankchar(*cp
); ++cp
)
1128 if (argn
>= argc
- 1) {
1129 printf(tr(126, "Too many elements in the list; excess discarded.\n"));
1134 while ((c
= *cp
) != '\0') {
1136 if (quotec
!= '\0') {
1141 } else if (c
== '\\')
1142 switch (c
= *cp
++) {
1148 case '0': case '1': case '2': case '3':
1149 case '4': case '5': case '6': case '7':
1151 if (*cp >= '0' && *cp <= '7')
1152 c = c * 8 + *cp++ - '0';
1153 if (*cp >= '0' && *cp <= '7')
1154 c = c * 8 + *cp++ - '0';
1177 if (cp
[-1] != quotec
|| echolist
)
1181 /*else if (c == '^') {
1185 /\* null doesn't show up anyway *\/
1186 else if ((c >= 'A' && c <= '_') ||
1187 (c >= 'a' && c <= 'z'))
1195 } else if (c
== '"' || c
== '\'') {
1199 } else if (c
== '\\' && !echolist
) {
1204 } else if (blankchar(c
))
1210 argv
[argn
++] = savestr(linebuf
);
1225 if (msgCount
== 0) {
1233 mb
.mb_threaded
? mp
!= NULL
: PTRCMP(mp
, <, message
+ msgCount
);
1234 mb
.mb_threaded
? mp
= next_in_thread(mp
) : ++mp
) {
1235 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (unsigned)f
) {
1236 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1241 if (dot
> message
) {
1242 for (mp
= dot
-1; (mb
.mb_threaded
? mp
!= NULL
: mp
>= message
);
1243 mb
.mb_threaded
? mp
= prev_in_thread(mp
) : --mp
) {
1244 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (unsigned)f
) {
1245 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1257 mark(int mesg
, int f
)
1264 if (i
< 1 || i
> msgCount
)
1265 panic(tr(129, "Bad message number to mark"));
1266 if (mb
.mb_threaded
== 1 && threadflag
) {
1267 if ((message
[i
- 1].m_flag
& MHIDDEN
) == 0) {
1268 if (f
== MDELETED
|| (message
[i
- 1].m_flag
&MDELETED
) == 0)
1269 message
[i
- 1].m_flag
|= MMARK
;
1272 if (message
[i
- 1].m_child
) {
1273 mp
= message
[i
- 1].m_child
;
1274 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1275 for (mp
= mp
->m_younger
; mp
; mp
= mp
->m_younger
)
1276 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1279 message
[i
- 1].m_flag
|= MMARK
;
1283 /* vim:set fenc=utf-8:s-it-mode */