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_at(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 np
= namelist
= smalloc((nmlsize
= 8) * sizeof *namelist
);
211 beg
= mc
= star
= other
= topen
= tback
= FAL0
;
216 for (tok
= scan(&bufp
); tok
!= TEOL
;) {
221 fprintf(stderr
, tr(112, "No numbers mixed with *\n"));
224 list_saw_numbers
= TRU1
;
228 if (check(lexnumber
, f
))
231 while (mb
.mb_threaded
? 1 : i
<= lexnumber
) {
232 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
233 (f
== MDELETED
|| !(message
[i
- 1].m_flag
& MDELETED
)))
235 if (mb
.mb_threaded
) {
238 mx
= next_in_thread(&message
[i
- 1]);
241 i
= (int)PTR2SIZE(mx
- message
+ 1);
260 msglist_is_single
= FAL0
;
262 printf(tr(113, "Non-numeric second argument\n"));
267 if (mb
.mb_threaded
) {
268 mx
= next_in_thread(message
+ i
- 1);
269 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : msgCount
+ 1;
273 fprintf(stderr
, tr(114, "Referencing beyond EOF\n"));
276 } while (message
[i
- 1].m_flag
== MHIDDEN
||
277 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
282 msglist_is_single
= FAL0
;
286 if (mb
.mb_threaded
) {
287 mx
= prev_in_thread(message
+ i
- 1);
288 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : 0;
292 fprintf(stderr
, tr(115, "Referencing before 1\n"));
295 } while ((message
[i
- 1].m_flag
& MHIDDEN
) ||
296 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
302 msglist_is_single
= FAL0
;
304 fprintf(stderr
, tr(116, "Non-numeric second argument\n"));
308 if (lexstring
[0] == ':') {
309 colresult
= evalcol(lexstring
[1]);
310 if (colresult
== 0) {
311 fprintf(stderr
, tr(117, "Unknown colon modifier \"%s\"\n"),
318 np
= add_to_namelist(&namelist
, &nmlsize
, np
, savestr(lexstring
));
322 #ifdef HAVE_IMAP_SEARCH
323 msglist_is_single
= FAL0
;
324 if (imap_search(lexstring
, f
) == STOP
)
328 fprintf(stderr
, tr(42,
329 "`%s': the used selector is optional and not available\n"),
339 msglist_is_single
= FAL0
;
340 lexnumber
= metamess(lexstring
[0], f
);
346 msglist_is_single
= FAL0
;
348 for (i
= 1; i
<= msgCount
; i
++) {
349 if ((message
[i
- 1].m_flag
& MHIDDEN
) ||
350 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
)
352 if (message
[i
- 1].m_flag
& MOLDMARK
)
358 msglist_is_single
= FAL0
;
360 fprintf(stderr
, tr(118, "Can't mix \"*\" with anything\n"));
367 msglist_is_single
= FAL0
;
369 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
370 imap_getheaders(1, msgCount
);
372 if (id
== NULL
&& (cp
= hfield1("in-reply-to", dot
)) != NULL
) {
374 idfield
= ID_IN_REPLY_TO
;
376 if (id
== NULL
&& (cp
= hfield1("references", dot
)) != NULL
) {
379 if ((enp
= extract(cp
, GREF
)) != NULL
) {
380 while (enp
->n_flink
!= NULL
)
382 id
= savestr(enp
->n_name
);
383 idfield
= ID_REFERENCES
;
388 "Cannot determine parent Message-ID of the current message\n"));
394 list_saw_numbers
= TRU1
;
395 msglist_is_single
= FAL0
;
403 np
= add_to_namelist(&namelist
, &nmlsize
, np
, NULL
);
407 for (i
= 0; i
< msgCount
; ++i
) {
408 if (!(message
[i
].m_flag
& MHIDDEN
) &&
409 (message
[i
].m_flag
& MDELETED
) == (unsigned)f
) {
416 printf(tr(119, "No applicable messages.\n"));
422 if ((topen
|| tback
) && mc
== 0) {
423 for (i
= 0; i
< msgCount
; ++i
)
424 if (message
[i
].m_flag
& MMARK
)
429 fprintf(stderr
, tr(131, "No previously marked messages.\n"));
431 printf("No messages satisfy (criteria).\n");/*TODO tr*/
437 /* If no numbers were given, mark all messages, so that we can unmark
438 * any whose sender was not selected if any user names were given */
439 if ((np
> namelist
|| colmod
!= 0 || id
) && mc
== 0)
440 for (i
= 1; i
<= msgCount
; ++i
) {
441 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
442 (message
[i
- 1].m_flag
& MDELETED
) == (unsigned)f
)
446 /* If any names were given, eliminate any messages which don't match */
447 if (np
> namelist
|| id
) {
448 struct search_expr
*sep
= NULL
;
451 /* The `@' search works with struct search_expr, so build an array.
452 * To simplify array, i.e., regex_t destruction, and optimize for the
453 * common case we walk the entire array even in case of errors */
455 sep
= scalloc(PTR2SIZE(np
- namelist
), sizeof(*sep
));
456 for (j
= 0, nq
= namelist
; *nq
!= NULL
; ++j
, ++nq
) {
460 if (*x
!= '@' || rv
< 0)
463 for (y
= x
+ 1;; ++y
) {
464 if (*y
== '\0' || !fieldnamechar(*y
)) {
473 sep
[j
].ss_where
= (x
== NULL
|| x
- 1 == *nq
)
474 ? "subject" : savestrbuf(*nq
+ 1, PTR2SIZE(x
- *nq
) - 1);
476 x
= (x
== NULL
? *nq
: x
) + 1;
477 if (*x
== '\0') { /* XXX Simply remove from list instead? */
478 fprintf(stderr
, tr(525, "Empty `[@..]@' search expression\n"));
483 if (anyof("^.[]*+?(){}|$", x
)) {
484 sep
[j
].ss_sexpr
= NULL
;
485 if (regcomp(&sep
[j
].ss_reexpr
, x
,
486 REG_EXTENDED
| REG_ICASE
| REG_NOSUB
) != 0) {
487 fprintf(stderr
, tr(526,
488 "Invalid regular expression: >>> %s <<<\n"), x
);
497 goto jnamesearch_sepfree
;
501 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
502 imap_getheaders(1, msgCount
);
505 allnet
= ok_blook(allnet
);
506 for (i
= 1; i
<= msgCount
; ++i
) {
507 mp
= message
+ i
- 1;
510 for (nq
= namelist
; *nq
!= NULL
; ++nq
) {
512 if (_match_at(mp
, sep
+ PTR2SIZE(nq
- namelist
))) {
516 } else if (**nq
== '/') {
517 if (_match_dash(mp
, *nq
)) {
521 } else if (_matchsender(mp
, *nq
, allnet
)) {
527 if (j
== 0 && id
&& _matchmid(mp
, id
, idfield
))
530 mp
->m_flag
&= ~MMARK
;
535 /* Make sure we got some decent messages */
537 for (i
= 1; i
<= msgCount
; ++i
)
538 if (message
[i
- 1].m_flag
& MMARK
) {
543 if (!inhook
&& np
> namelist
) {
544 printf(tr(120, "No applicable messages from {%s"), namelist
[0]);
545 for (nq
= namelist
+ 1; *nq
!= NULL
; ++nq
)
546 printf(tr(121, ", %s"), *nq
);
547 printf(tr(122, "}\n"));
549 printf(tr(227, "Parent message not found\n"));
551 goto jnamesearch_sepfree
;
557 for (j
= PTR2SIZE(np
- namelist
); j
-- != 0;)
558 if (sep
[j
].ss_sexpr
== NULL
)
559 regfree(&sep
[j
].ss_reexpr
);
567 /* If any colon modifiers were given, go through and unmark any
568 * messages which do not satisfy the modifiers */
570 for (i
= 1; i
<= msgCount
; ++i
) {
571 struct coltab
const *colp
;
574 mp
= message
+ i
- 1;
575 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
576 if ((colp
->co_bit
& colmod
) &&
577 ((mp
->m_flag
& colp
->co_mask
) == (unsigned)colp
->co_equal
))
582 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
583 if (mp
->m_flag
& MMARK
)
585 if (PTRCMP(mp
, >=, message
+ msgCount
)) {
586 struct coltab
const *colp
;
589 printf(tr(123, "No messages satisfy"));
590 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
591 if (colp
->co_bit
& colmod
)
592 printf(" :%c", colp
->co_char
);
612 struct coltab
const *colp
;
620 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
621 if (colp
->co_char
== col
) {
631 check(int mesg
, int f
)
636 if (mesg
< 1 || mesg
> msgCount
) {
637 printf(tr(124, "%d: Invalid message number\n"), mesg
);
640 mp
= message
+ mesg
- 1;
641 if (mp
->m_flag
& MHIDDEN
||
642 (f
!= MDELETED
&& (mp
->m_flag
& MDELETED
) != 0)) {
643 fprintf(stderr
, tr(125, "%d: Inappropriate message\n"), mesg
);
659 int rv
, c
, inquote
, quotec
;
660 struct lex
const *lp
;
664 strncpy(lexstring
, string_stack
[regretp
], STRINGLEN
);
665 lexstring
[STRINGLEN
-1] = '\0';
666 lexnumber
= numberstack
[regretp
];
667 rv
= regretstack
[regretp
--];
675 /* strip away leading white space */
679 /* If no characters remain, we are at end of line, so report that */
686 /* Select members of a message thread */
689 if (*cp
== '\0' || spacechar(*cp
)) {
699 /* If the leading character is a digit, scan the number and convert it
700 * on the fly. Return TNUMBER when done */
703 while (digitchar(c
)) {
704 lexnumber
= lexnumber
*10 + c
- '0';
714 /* An IMAP SEARCH list. Note that TOPEN has always been included in
715 * singles[] in Mail and mailx. Thus although there is no formal
716 * definition for (LIST) lists, they do not collide with historical
717 * practice because a subject string (LIST) could never been matched
724 if ((c
= *cp
++&0377) == '\0') {
726 fprintf(stderr
, "Missing \")\".\n");
730 if (inquote
&& c
== '\\') {
743 else if (spacechar(c
)) {
744 /* Replace unquoted whitespace by single space characters, to make
745 * the string IMAP SEARCH conformant */
751 } while (c
!= ')' || level
> 0);
758 /* Check for single character tokens; return such if found */
759 for (lp
= _singles
; lp
->l_char
!= '\0'; ++lp
)
760 if (c
== lp
->l_char
) {
768 /* We've got a string! Copy all the characters of the string into
769 * lexstring, until we see a null, space, or tab. If the lead character is
770 * a " or ', save it and scan until you get another */
772 if (c
== '\'' || c
== '"') {
777 if (quotec
== 0 && c
== '\\' && *cp
!= '\0')
783 if (quotec
== 0 && blankchar(c
))
785 if (PTRCMP(cp2
- lexstring
, <, STRINGLEN
- 1))
789 if (quotec
&& c
== 0) {
790 fprintf(stderr
, tr(127, "Missing %c\n"), quotec
);
806 if (++regretp
>= REGDEP
)
807 panic(tr(128, "Too many regrets"));
808 regretstack
[regretp
] = token
;
809 lexstring
[STRINGLEN
-1] = '\0';
810 string_stack
[regretp
] = savestr(lexstring
);
811 numberstack
[regretp
] = lexnumber
;
825 _matchsender(struct message
*mp
, char const *str
, bool_t allnet
)
831 char *cp
= nameof(mp
, 0);
834 if ((*cp
== '@' || *cp
== '\0') && (*str
== '@' || *str
== '\0')) {
840 } while (++cp
, *str
++ != '\0');
844 rv
= !strcmp(str
, (*(ok_blook(showname
) ? &realname
: &skin
))(name1(mp
, 0)));
851 _matchmid(struct message
*mp
, char *id
, enum idfield idfield
)
857 if ((cp
= hfield1("message-id", mp
)) != NULL
) {
860 rv
= !msgidcmp(id
, cp
);
862 case ID_IN_REPLY_TO
: {
865 if ((np
= extract(id
, GREF
)) != NULL
)
867 if (!msgidcmp(np
->n_name
, cp
)) {
871 } while ((np
= np
->n_flink
) != NULL
);
883 _match_dash(struct message
*mp
, char const *str
)
885 static char lastscan
[128];
888 char *hfield
, *hbody
;
892 if (*++str
== '\0') {
895 strncpy(lastscan
, str
, sizeof lastscan
); /* XXX use new n_str object! */
896 lastscan
[sizeof lastscan
-1] = '\0';
899 /* Now look, ignoring case, for the word in the string */
900 if (ok_blook(searchheaders
) && (hfield
= strchr(str
, ':'))) {
901 size_t l
= PTR2SIZE(hfield
- str
);
902 hfield
= ac_alloc(l
+1);
903 memcpy(hfield
, str
, l
);
905 hbody
= hfieldX(hfield
, mp
);
907 hfield
= UNCONST(str
+ l
+ 1);
909 hfield
= UNCONST(str
);
910 hbody
= hfield1("subject", mp
);
918 in
.l
= strlen(hbody
);
919 mime_fromhdr(&in
, &out
, TD_ICONV
);
920 rv
= substr(out
.s
, hfield
);
928 _match_at(struct message
*mp
, struct search_expr
*sep
)
931 char *nfield
, *cfield
;
935 nfield
= savestr(sep
->ss_where
);
937 while ((cfield
= n_strsep(&nfield
, ',', TRU1
)) != NULL
) {
938 if (!asccasecmp(cfield
, "body")) {
941 if ((rv
= message_match(mp
, sep
, rv
)))
943 } else if (!asccasecmp(cfield
, "text")) {
946 } else if ((in
.s
= hfieldX(cfield
, mp
)) == NULL
)
950 mime_fromhdr(&in
, &out
, TD_ICONV
);
952 if (sep
->ss_sexpr
== NULL
)
953 rv
= (regexec(&sep
->ss_reexpr
, out
.s
, 0,NULL
, 0) != REG_NOMATCH
);
956 rv
= substr(out
.s
, sep
->ss_sexpr
);
973 if (i
< 1 || UICMP(z
, i
, >, msgCount
))
974 panic(tr(130, "Bad message number to unmark"));
975 message
[i
- 1].m_flag
&= ~MMARK
;
980 metamess(int meta
, int f
)
988 case '^': /* First 'good' message left */
989 mp
= mb
.mb_threaded
? threadroot
: message
;
990 while (PTRCMP(mp
, <, message
+ msgCount
)) {
991 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
992 c
= (int)PTR2SIZE(mp
- message
+ 1);
995 if (mb
.mb_threaded
) {
996 mp
= next_in_thread(mp
);
1003 printf(tr(132, "No applicable messages\n"));
1006 case '$': /* Last 'good message left */
1008 ? this_in_thread(threadroot
, -1) : message
+ msgCount
- 1;
1009 while (mp
>= message
) {
1010 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1011 c
= (int)PTR2SIZE(mp
- message
+ 1);
1014 if (mb
.mb_threaded
) {
1015 mp
= prev_in_thread(mp
);
1022 printf(tr(132, "No applicable messages\n"));
1026 /* Current message */
1027 m
= dot
- message
+ 1;
1028 if ((dot
->m_flag
& MHIDDEN
) || (dot
->m_flag
& MDELETED
) != (ui32_t
)f
) {
1029 printf(tr(133, "%d: Inappropriate message\n"), m
);
1036 /* Previously current message */
1037 if (prevdot
== NULL
) {
1038 fprintf(stderr
, tr(228, "No previously current message\n"));
1041 m
= prevdot
- message
+ 1;
1042 if ((prevdot
->m_flag
& MHIDDEN
) ||
1043 (prevdot
->m_flag
& MDELETED
) != (ui32_t
)f
) {
1044 fprintf(stderr
, tr(133, "%d: Inappropriate message\n"), m
);
1051 fprintf(stderr
, tr(134, "Unknown metachar (%c)\n"), c
);
1063 getmsglist(char *buf
, int *vector
, int flags
)
1070 msglist_is_single
= FAL0
;
1072 if (msgCount
== 0) {
1078 msglist_is_single
= TRU1
;
1079 if (markall(buf
, flags
) < 0) {
1087 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1088 if (mp
->m_flag
& MMARK
) {
1089 if (!(mp
->m_flag
& MNEWEST
))
1090 unmark((int)PTR2SIZE(mp
- message
+ 1));
1100 if (mb
.mb_threaded
== 0) {
1101 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1102 if (mp
->m_flag
& MMARK
)
1103 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1105 for (mp
= threadroot
; mp
!= NULL
; mp
= next_in_thread(mp
))
1106 if (mp
->m_flag
& MMARK
)
1107 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1110 mc
= (int)PTR2SIZE(ip
- vector
);
1111 msglist_is_single
= (mc
== 1);
1118 getrawlist(char const *line
, size_t linesize
, char **argv
, int argc
,
1121 char c
, *cp2
, quotec
, *linebuf
;
1126 list_saw_numbers
= FAL0
;
1130 linebuf
= ac_alloc(linesize
+1);
1132 for (; blankchar(*cp
); ++cp
)
1136 if (argn
>= argc
- 1) {
1137 printf(tr(126, "Too many elements in the list; excess discarded.\n"));
1142 while ((c
= *cp
) != '\0') {
1144 if (quotec
!= '\0') {
1149 } else if (c
== '\\')
1150 switch (c
= *cp
++) {
1156 case '0': case '1': case '2': case '3':
1157 case '4': case '5': case '6': case '7':
1159 if (*cp >= '0' && *cp <= '7')
1160 c = c * 8 + *cp++ - '0';
1161 if (*cp >= '0' && *cp <= '7')
1162 c = c * 8 + *cp++ - '0';
1185 if (cp
[-1] != quotec
|| echolist
)
1189 /*else if (c == '^') {
1193 /\* null doesn't show up anyway *\/
1194 else if ((c >= 'A' && c <= '_') ||
1195 (c >= 'a' && c <= 'z'))
1203 } else if (c
== '"' || c
== '\'') {
1207 } else if (c
== '\\' && !echolist
) {
1212 } else if (blankchar(c
))
1218 argv
[argn
++] = savestr(linebuf
);
1233 if (msgCount
== 0) {
1241 mb
.mb_threaded
? (mp
!= NULL
) : PTRCMP(mp
, <, message
+ msgCount
);
1242 mb
.mb_threaded
? (mp
= next_in_thread(mp
)) : ++mp
) {
1243 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (ui32_t
)f
) {
1244 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1249 if (dot
> message
) {
1250 for (mp
= dot
- 1; (mb
.mb_threaded
? (mp
!= NULL
) : (mp
>= message
));
1251 mb
.mb_threaded
? (mp
= prev_in_thread(mp
)) : --mp
) {
1252 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (ui32_t
)f
) {
1253 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1265 mark(int mesg
, int f
)
1272 if (i
< 1 || i
> msgCount
)
1273 panic(tr(129, "Bad message number to mark"));
1274 if (mb
.mb_threaded
== 1 && threadflag
) {
1275 if (!(message
[i
- 1].m_flag
& MHIDDEN
)) {
1276 if (f
== MDELETED
|| !(message
[i
- 1].m_flag
& MDELETED
))
1277 message
[i
- 1].m_flag
|= MMARK
;
1280 if (message
[i
- 1].m_child
) {
1281 mp
= message
[i
- 1].m_child
;
1282 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1283 for (mp
= mp
->m_younger
; mp
!= NULL
; mp
= mp
->m_younger
)
1284 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1287 message
[i
- 1].m_flag
|= MMARK
;
1291 /* vim:set fenc=utf-8:s-it-mode */