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 - 2015 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. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #ifndef HAVE_AMALGAMATION
42 /* Token values returned by the scanner used for argument lists.
43 * Also, sizes of scanner-related things */
45 TEOL
= 0, /* End of the command line */
46 TNUMBER
= 1, /* A message number */
47 TDASH
= 2, /* A simple dash */
48 TSTRING
= 3, /* A string (possibly containing -) */
51 TDOLLAR
= 6, /* A "$" */
52 TSTAR
= 7, /* A "*" */
53 TOPEN
= 8, /* A '(' */
54 TCLOSE
= 9, /* A ')' */
55 TPLUS
= 10, /* A '+' */
56 TERROR
= 11, /* A lexical error */
57 TCOMMA
= 12, /* A ',' */
58 TSEMI
= 13, /* A ';' */
59 TBACK
= 14 /* A '`' */
62 #define REGDEP 2 /* Maximum regret depth. */
70 CMNEW
= 1<<0, /* New messages */
71 CMOLD
= 1<<1, /* Old messages */
72 CMUNREAD
= 1<<2, /* Unread messages */
73 CMDELETED
=1<<3, /* Deleted messages */
74 CMREAD
= 1<<4, /* Read messages */
75 CMFLAG
= 1<<5, /* Flagged messages */
76 CMANSWER
= 1<<6, /* Answered messages */
77 CMDRAFT
= 1<<7, /* Draft messages */
78 CMSPAM
= 1<<8, /* Spam messages */
79 CMSPAMUN
= 1<<9 /* Maybe spam messages (unsure) */
83 char co_char
; /* What to find past : */
84 int co_bit
; /* Associated modifier bit */
85 int co_mask
; /* m_status bits to mask */
86 int co_equal
; /* ... must equal this */
94 static struct coltab
const _coltab
[] = {
95 { 'n', CMNEW
, MNEW
, MNEW
},
96 { 'o', CMOLD
, MNEW
, 0 },
97 { 'u', CMUNREAD
, MREAD
, 0 },
98 { 'd', CMDELETED
, MDELETED
, MDELETED
},
99 { 'r', CMREAD
, MREAD
, MREAD
},
100 { 'f', CMFLAG
, MFLAGGED
, MFLAGGED
},
101 { 'a', CMANSWER
, MANSWERED
, MANSWERED
},
102 { 't', CMDRAFT
, MDRAFTED
, MDRAFTED
},
103 { 's', CMSPAM
, MSPAM
, MSPAM
},
104 { 'S', CMSPAMUN
, MSPAMUNSURE
, MSPAMUNSURE
},
108 static struct lex
const _singles
[] = {
123 static bool_t _list_saw_d
, _list_last_saw_d
; /* :d on its way HACK TODO */
124 static size_t STRINGLEN
;
125 static int lexnumber
; /* Number of TNUMBER from scan() */
126 static char *lexstring
; /* String from TSTRING, scan() */
127 static int regretp
; /* Pointer to TOS of regret tokens */
128 static int regretstack
[REGDEP
]; /* Stack of regretted tokens */
129 static char *string_stack
[REGDEP
]; /* Stack of regretted strings */
130 static int numberstack
[REGDEP
]; /* Stack of regretted numbers */
131 static int threadflag
; /* mark entire threads */
133 /* Append, taking care of resizes */
134 static char ** add_to_namelist(char ***namelist
, size_t *nmlsize
,
135 char **np
, char *string
);
137 /* Mark all messages that the user wanted from the command line in the message
138 * structure. Return 0 on success, -1 on error */
139 static int markall(char *buf
, int f
);
141 /* Turn the character after a colon modifier into a bit value */
142 static int evalcol(int col
);
144 /* Check the passed message number for legality and proper flags. If f is
145 * MDELETED, then either kind will do. Otherwise, the message has to be
147 static int check(int mesg
, int f
);
149 /* Scan out a single lexical item and return its token number, updating the
150 * string pointer passed **sp. Also, store the value of the number or string
151 * scanned in lexnumber or lexstring as appropriate. In any event, store the
152 * scanned "thing" in lexstring */
153 static int scan(char **sp
);
155 /* Unscan the named token by pushing it onto the regret stack */
156 static void regret(int token
);
158 /* Reset all the scanner global variables */
159 static void scaninit(void);
161 /* See if the passed name sent the passed message */
162 static bool_t
_matchsender(struct message
*mp
, char const *str
, bool_t allnet
);
164 static bool_t
_matchmid(struct message
*mp
, char *id
, enum idfield idfield
);
166 /* See if the given string matches.
167 * For the purpose of the scan, we ignore case differences.
168 * This is the engine behind the "/" search */
169 static bool_t
_match_dash(struct message
*mp
, char const *str
);
171 /* See if the given search expression matches.
172 * For the purpose of the scan, we ignore case differences.
173 * This is the engine behind the "@[..]@" search */
174 static bool_t
_match_at(struct message
*mp
, struct search_expr
*sep
);
176 /* Unmark the named message */
177 static void unmark(int mesg
);
179 /* Return the message number corresponding to the passed meta character */
180 static int metamess(int meta
, int f
);
183 add_to_namelist(char ***namelist
, size_t *nmlsize
, char **np
, char *string
)
188 if ((idx
= PTR2SIZE(np
- *namelist
)) >= *nmlsize
) {
189 *namelist
= srealloc(*namelist
, (*nmlsize
+= 8) * sizeof *np
);
190 np
= *namelist
+ idx
;
198 markall(char *buf
, int f
)
200 #define markall_ret(i) do { rv = i; goto jleave; } while (0);
202 /* TODO use a bit carrier for all the states */
203 char **np
, **nq
, **namelist
, *bufp
, *id
= NULL
, *cp
;
204 int rv
= 0, i
, tok
, beg
, other
, valdot
, colmod
, colresult
;
205 struct message
*mp
, *mx
;
206 bool_t mc
, star
, topen
, tback
;
208 enum idfield idfield
= ID_REFERENCES
;
211 lexstring
= ac_alloc(STRINGLEN
= 2 * strlen(buf
) +1);
212 valdot
= (int)PTR2SIZE(dot
- message
+ 1);
215 for (i
= 1; i
<= msgCount
; ++i
) {
218 mf
= message
[i
- 1].m_flag
;
224 message
[i
- 1].m_flag
= mf
;
227 np
= namelist
= smalloc((nmlsize
= 8) * sizeof *namelist
);
231 beg
= star
= other
= topen
= tback
= FAL0
;
233 for (tok
= scan(&bufp
); tok
!= TEOL
;) {
238 n_err(_("No numbers mixed with *\n"));
241 pstate
|= PS_MSGLIST_SAW_NO
;
244 if (check(lexnumber
, f
))
247 while (mb
.mb_threaded
? 1 : i
<= lexnumber
) {
248 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
249 (f
== MDELETED
|| !(message
[i
- 1].m_flag
& MDELETED
)))
251 if (mb
.mb_threaded
) {
254 mx
= next_in_thread(&message
[i
- 1]);
257 i
= (int)PTR2SIZE(mx
- message
+ 1);
276 pstate
&= ~PS_MSGLIST_DIRECT
;
278 printf(_("Non-numeric second argument\n"));
283 if (mb
.mb_threaded
) {
284 mx
= next_in_thread(message
+ i
- 1);
285 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : msgCount
+ 1;
289 n_err(_("Referencing beyond EOF\n"));
292 } while (message
[i
- 1].m_flag
== MHIDDEN
||
293 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
298 pstate
&= ~PS_MSGLIST_DIRECT
;
302 if (mb
.mb_threaded
) {
303 mx
= prev_in_thread(message
+ i
- 1);
304 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : 0;
308 n_err(_("Referencing before 1\n"));
311 } while ((message
[i
- 1].m_flag
& MHIDDEN
) ||
312 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
318 pstate
&= ~PS_MSGLIST_DIRECT
;
320 n_err(_("Non-numeric second argument\n"));
324 if ((cp
= lexstring
)[0] == ':') {
325 while (*++cp
!= '\0') {
326 colresult
= evalcol(*cp
);
327 if (colresult
== 0) {
328 n_err(_("Unknown colon modifier \"%s\"\n"), lexstring
);
331 if (colresult
== CMDELETED
) {
338 np
= add_to_namelist(&namelist
, &nmlsize
, np
, savestr(lexstring
));
342 #ifdef HAVE_IMAP_SEARCH
343 pstate
&= ~PS_MSGLIST_DIRECT
;
344 if (imap_search(lexstring
, f
) == STOP
)
348 n_err(_("Optional selector is not available: \"%s\"\n"),
358 pstate
&= ~PS_MSGLIST_DIRECT
;
359 lexnumber
= metamess(lexstring
[0], f
);
365 pstate
&= ~PS_MSGLIST_DIRECT
;
367 for (i
= 1; i
<= msgCount
; i
++) {
368 struct message
const *mp_t
= message
+ i
- 1;
370 if (mp_t
->m_flag
& MHIDDEN
)
372 if ((mp_t
->m_flag
& MDELETED
) != (unsigned)f
) {
373 if (!_list_last_saw_d
)
377 if (mp_t
->m_flag
& MOLDMARK
)
383 pstate
&= ~PS_MSGLIST_DIRECT
;
385 n_err(_("Can't mix \"*\" with anything\n"));
392 pstate
&= ~PS_MSGLIST_DIRECT
;
393 if (id
== NULL
&& (cp
= hfield1("in-reply-to", dot
)) != NULL
) {
395 idfield
= ID_IN_REPLY_TO
;
397 if (id
== NULL
&& (cp
= hfield1("references", dot
)) != NULL
) {
400 if ((enp
= extract(cp
, GREF
)) != NULL
) {
401 while (enp
->n_flink
!= NULL
)
403 id
= savestr(enp
->n_name
);
404 idfield
= ID_REFERENCES
;
409 "Cannot determine parent Message-ID of the current message\n"));
415 pstate
&= ~PS_MSGLIST_DIRECT
;
416 pstate
|= PS_MSGLIST_SAW_NO
;
423 np
= add_to_namelist(&namelist
, &nmlsize
, np
, NULL
);
427 for (i
= 0; i
< msgCount
; ++i
) {
428 struct message
const *mp_t
= message
+ i
;
430 if (mp_t
->m_flag
& MHIDDEN
)
432 if (!_list_saw_d
&& (mp_t
->m_flag
& MDELETED
) != (unsigned)f
)
439 if (!(pstate
& PS_HOOK_MASK
))
440 printf(_("No applicable messages.\n"));
446 if ((topen
|| tback
) && !mc
) {
447 for (i
= 0; i
< msgCount
; ++i
)
448 if (message
[i
].m_flag
& MMARK
)
451 if (!(pstate
& PS_HOOK_MASK
)) {
453 n_err(_("No previously marked messages\n"));
455 printf(_("No messages satisfy (criteria)\n"));
461 /* If no numbers were given, mark all messages, so that we can unmark
462 * any whose sender was not selected if any user names were given */
463 if ((np
> namelist
|| colmod
!= 0 || id
) && !mc
) {
464 for (i
= 1; i
<= msgCount
; ++i
) {
465 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
466 (message
[i
- 1].m_flag
& MDELETED
) == (unsigned)f
)
471 /* If any names were given, eliminate any messages which don't match */
472 if (np
> namelist
|| id
) {
473 struct search_expr
*sep
= NULL
;
476 /* The @ search works with struct search_expr, so build an array.
477 * To simplify array, i.e., regex_t destruction, and optimize for the
478 * common case we walk the entire array even in case of errors */
480 sep
= scalloc(PTR2SIZE(np
- namelist
), sizeof(*sep
));
481 for (j
= 0, nq
= namelist
; *nq
!= NULL
; ++j
, ++nq
) {
485 if (*x
!= '@' || rv
< 0)
488 for (y
= x
+ 1;; ++y
) {
489 if (*y
== '\0' || !fieldnamechar(*y
)) {
498 sep
[j
].ss_where
= (x
== NULL
|| x
- 1 == *nq
)
499 ? "subject" : savestrbuf(*nq
+ 1, PTR2SIZE(x
- *nq
) - 1);
501 x
= (x
== NULL
? *nq
: x
) + 1;
502 if (*x
== '\0') { /* XXX Simply remove from list instead? */
503 n_err(_("Empty \"[@..]@\" search expression\n"));
508 if (is_maybe_regex(x
)) {
509 sep
[j
].ss_sexpr
= NULL
;
510 if (regcomp(&sep
[j
].ss_regex
, x
,
511 REG_EXTENDED
| REG_ICASE
| REG_NOSUB
) != 0) {
512 n_err(_("Invalid regular expression: >>> %s <<<\n"), x
);
521 goto jnamesearch_sepfree
;
525 allnet
= ok_blook(allnet
);
526 for (i
= 1; i
<= msgCount
; ++i
) {
527 mp
= message
+ i
- 1;
530 for (nq
= namelist
; *nq
!= NULL
; ++nq
) {
532 if (_match_at(mp
, sep
+ PTR2SIZE(nq
- namelist
))) {
536 } else if (**nq
== '/') {
537 if (_match_dash(mp
, *nq
)) {
541 } else if (_matchsender(mp
, *nq
, allnet
)) {
547 if (j
== 0 && id
&& _matchmid(mp
, id
, idfield
))
550 mp
->m_flag
&= ~MMARK
;
555 /* Make sure we got some decent messages */
557 for (i
= 1; i
<= msgCount
; ++i
)
558 if (message
[i
- 1].m_flag
& MMARK
) {
563 if (!(pstate
& PS_HOOK_MASK
) && np
> namelist
) {
564 printf(_("No applicable messages from {%s"), namelist
[0]);
565 for (nq
= namelist
+ 1; *nq
!= NULL
; ++nq
)
566 printf(_(", %s"), *nq
);
569 printf(_("Parent message not found\n"));
571 goto jnamesearch_sepfree
;
577 for (j
= PTR2SIZE(np
- namelist
); j
-- != 0;)
578 if (sep
[j
].ss_sexpr
== NULL
)
579 regfree(&sep
[j
].ss_regex
);
587 /* If any colon modifiers were given, go through and unmark any
588 * messages which do not satisfy the modifiers */
590 for (i
= 1; i
<= msgCount
; ++i
) {
591 struct coltab
const *colp
;
594 mp
= message
+ i
- 1;
595 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
596 if ((colp
->co_bit
& colmod
) &&
597 ((mp
->m_flag
& colp
->co_mask
) == (unsigned)colp
->co_equal
)) {
605 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
606 if (mp
->m_flag
& MMARK
)
609 if (PTRCMP(mp
, >=, message
+ msgCount
)) {
610 struct coltab
const *colp
;
612 if (!(pstate
& PS_HOOK_MASK
)) {
613 printf(_("No messages satisfy"));
614 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
615 if (colp
->co_bit
& colmod
)
616 printf(" :%c", colp
->co_char
);
636 struct coltab
const *colp
;
641 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
642 if (colp
->co_char
== col
) {
651 check(int mesg
, int f
)
656 if (mesg
< 1 || mesg
> msgCount
) {
657 printf(_("%d: Invalid message number\n"), mesg
);
660 mp
= message
+ mesg
- 1;
661 if (mp
->m_flag
& MHIDDEN
||
662 (f
!= MDELETED
&& (mp
->m_flag
& MDELETED
) != 0)) {
663 n_err(_("%d: inappropriate message\n"), mesg
);
679 int rv
, c
, inquote
, quotec
;
680 struct lex
const *lp
;
684 strncpy(lexstring
, string_stack
[regretp
], STRINGLEN
);
685 lexstring
[STRINGLEN
-1] = '\0';
686 lexnumber
= numberstack
[regretp
];
687 rv
= regretstack
[regretp
--];
695 /* strip away leading white space */
699 /* If no characters remain, we are at end of line, so report that */
706 /* Select members of a message thread */
709 if (*cp
== '\0' || spacechar(*cp
)) {
719 /* If the leading character is a digit, scan the number and convert it
720 * on the fly. Return TNUMBER when done */
723 while (digitchar(c
)) {
724 lexnumber
= lexnumber
*10 + c
- '0';
734 /* An IMAP SEARCH list. Note that TOPEN has always been included in
735 * singles[] in Mail and mailx. Thus although there is no formal
736 * definition for (LIST) lists, they do not collide with historical
737 * practice because a subject string (LIST) could never been matched
744 if ((c
= *cp
++&0377) == '\0') {
746 n_err(_("Missing \")\"\n"));
750 if (inquote
&& c
== '\\') {
763 else if (spacechar(c
)) {
764 /* Replace unquoted whitespace by single space characters, to make
765 * the string IMAP SEARCH conformant */
771 } while (c
!= ')' || level
> 0);
778 /* Check for single character tokens; return such if found */
779 for (lp
= _singles
; lp
->l_char
!= '\0'; ++lp
)
780 if (c
== lp
->l_char
) {
788 /* We've got a string! Copy all the characters of the string into
789 * lexstring, until we see a null, space, or tab. If the lead character is
790 * a " or ', save it and scan until you get another */
792 if (c
== '\'' || c
== '"') {
797 if (quotec
== 0 && c
== '\\' && *cp
!= '\0')
803 if (quotec
== 0 && blankchar(c
))
805 if (PTRCMP(cp2
- lexstring
, <, STRINGLEN
- 1))
809 if (quotec
&& c
== 0) {
810 n_err(_("Missing %c\n"), quotec
);
826 if (++regretp
>= REGDEP
)
827 n_panic(_("Too many regrets"));
828 regretstack
[regretp
] = token
;
829 lexstring
[STRINGLEN
-1] = '\0';
830 string_stack
[regretp
] = savestr(lexstring
);
831 numberstack
[regretp
] = lexnumber
;
845 _matchsender(struct message
*mp
, char const *str
, bool_t allnet
)
847 char const *str_base
, *np_base
, *np
;
852 /* Empty string doesn't match */
853 if (*(str_base
= str
) == '\0') {
858 /* *allnet* is POSIX and, since it explicitly mentions login and user names,
859 * most likely case-sensitive. XXX Still allow substr matching, though
860 * XXX possibly the first letter should be case-insensitive, then? */
862 np_base
= np
= nameof(mp
, 0);
864 if ((sc
= *str
++) == '@')
866 if ((nc
= *np
++) == '@' || nc
== '\0' || sc
== '\0')
875 char const *real_base
= name1(mp
, 0);
876 bool_t again
= ok_blook(showname
);
878 /* TODO POSIX says ~"match any address as shown in header overview",
879 * TODO but a normalized match would be more sane i guess.
880 * TODO struct name should gain a comparison method, normalize realname
881 * TODO content (in TODO) and thus match as likewise
882 * TODO "Buddy (Today) <here>" and "(Now) Buddy <here>" */
884 np_base
= np
= again
? realname(real_base
) : skin(real_base
);
887 if ((nc
= *np
++) == '\0' || sc
== '\0')
897 /* And really if i want to match 'on@' then i want it to match even if
898 * *showname* is set! */
899 if (!(rv
= (sc
== '\0')) && again
) {
910 _matchmid(struct message
*mp
, char *id
, enum idfield idfield
)
916 if ((cp
= hfield1("message-id", mp
)) != NULL
) {
919 rv
= !msgidcmp(id
, cp
);
921 case ID_IN_REPLY_TO
: {
924 if ((np
= extract(id
, GREF
)) != NULL
)
926 if (!msgidcmp(np
->n_name
, cp
)) {
930 } while ((np
= np
->n_flink
) != NULL
);
942 _match_dash(struct message
*mp
, char const *str
)
944 static char lastscan
[128];
947 char *hfield
, *hbody
;
951 if (*++str
== '\0') {
954 strncpy(lastscan
, str
, sizeof lastscan
); /* XXX use new n_str object! */
955 lastscan
[sizeof lastscan
-1] = '\0';
958 /* Now look, ignoring case, for the word in the string */
959 if (ok_blook(searchheaders
) && (hfield
= strchr(str
, ':'))) {
960 size_t l
= PTR2SIZE(hfield
- str
);
961 hfield
= ac_alloc(l
+1);
962 memcpy(hfield
, str
, l
);
964 hbody
= hfieldX(hfield
, mp
);
966 hfield
= UNCONST(str
+ l
+ 1);
968 hfield
= UNCONST(str
);
969 hbody
= hfield1("subject", mp
);
977 in
.l
= strlen(hbody
);
978 mime_fromhdr(&in
, &out
, TD_ICONV
);
979 rv
= substr(out
.s
, hfield
);
987 _match_at(struct message
*mp
, struct search_expr
*sep
)
995 nfield
= savestr(sep
->ss_where
);
997 while ((cfield
= n_strsep(&nfield
, ',', TRU1
)) != NULL
) {
998 if (!asccasecmp(cfield
, "body") ||
999 (cfield
[1] == '\0' && cfield
[0] == '>')) {
1002 if ((rv
= message_match(mp
, sep
, rv
)))
1006 if (!asccasecmp(cfield
, "text") ||
1007 (cfield
[1] == '\0' && cfield
[0] == '=')) {
1012 if (!asccasecmp(cfield
, "header") ||
1013 (cfield
[1] == '\0' && cfield
[0] == '<')) {
1014 if ((rv
= header_match(mp
, sep
)))
1019 /* This is not a special name, so take care for the "skin" prefix !
1020 * and possible abbreviations */
1025 if ((doskin
= (*cfield
== '~')))
1027 if (cfield
[0] != '\0' && cfield
[1] == '\0') {
1028 char const x
[][8] = {
1029 "from", "to", "cc", "bcc", "subject"
1032 char c1
= lowerconv(cfield
[0]);
1034 for (i
= 0; i
< NELEM(x
); ++i
) {
1035 if (c1
== x
[i
][0]) {
1041 if ((in
.s
= hfieldX(cfield
, mp
)) == NULL
)
1044 /* Shall we split into address list and match the addresses only? */
1046 np
= lextract(in
.s
, GSKIN
);
1052 in
.l
= strlen(in
.s
);
1053 mime_fromhdr(&in
, &out
, TD_ICONV
);
1057 if (sep
->ss_sexpr
== NULL
)
1058 rv
= (regexec(&sep
->ss_regex
, out
.s
, 0,NULL
, 0) != REG_NOMATCH
);
1061 rv
= substr(out
.s
, sep
->ss_sexpr
);
1066 if (np
!= NULL
&& (np
= np
->n_flink
) != NULL
) {
1083 if (i
< 1 || UICMP(z
, i
, >, msgCount
))
1084 n_panic(_("Bad message number to unmark"));
1085 message
[i
- 1].m_flag
&= ~MMARK
;
1090 metamess(int meta
, int f
)
1098 case '^': /* First 'good' message left */
1099 mp
= mb
.mb_threaded
? threadroot
: message
;
1100 while (PTRCMP(mp
, <, message
+ msgCount
)) {
1101 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1102 c
= (int)PTR2SIZE(mp
- message
+ 1);
1105 if (mb
.mb_threaded
) {
1106 mp
= next_in_thread(mp
);
1112 if (!(pstate
& PS_HOOK_MASK
))
1113 printf(_("No applicable messages\n"));
1116 case '$': /* Last 'good message left */
1118 ? this_in_thread(threadroot
, -1) : message
+ msgCount
- 1;
1119 while (mp
>= message
) {
1120 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1121 c
= (int)PTR2SIZE(mp
- message
+ 1);
1124 if (mb
.mb_threaded
) {
1125 mp
= prev_in_thread(mp
);
1131 if (!(pstate
& PS_HOOK_MASK
))
1132 printf(_("No applicable messages\n"));
1136 /* Current message */
1137 m
= dot
- message
+ 1;
1138 if ((dot
->m_flag
& MHIDDEN
) || (dot
->m_flag
& MDELETED
) != (ui32_t
)f
) {
1139 printf(_("%d: inappropriate message\n"), m
);
1146 /* Previously current message */
1147 if (prevdot
== NULL
) {
1148 n_err(_("No previously current message\n"));
1151 m
= prevdot
- message
+ 1;
1152 if ((prevdot
->m_flag
& MHIDDEN
) ||
1153 (prevdot
->m_flag
& MDELETED
) != (ui32_t
)f
) {
1154 n_err(_("%d: inappropriate message\n"), m
);
1161 n_err(_("Unknown metachar (%c)\n"), c
);
1173 argcount(char **argv
)/* FIXME -> lex.c */
1178 for (ap
= argv
; *ap
++ != NULL
;)
1181 return (int)PTR2SIZE(ap
- argv
- 1);
1185 getmsglist(char *buf
, int *vector
, int flags
)
1191 pstate
&= ~PS_MSGLIST_MASK
;
1192 _list_last_saw_d
= _list_saw_d
;
1195 if (msgCount
== 0) {
1201 pstate
|= PS_MSGLIST_DIRECT
;
1203 if (markall(buf
, flags
) < 0) {
1209 if (pstate
& PS_HOOK_NEWMAIL
) {
1211 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1212 if (mp
->m_flag
& MMARK
) {
1213 if (!(mp
->m_flag
& MNEWEST
))
1214 unmark((int)PTR2SIZE(mp
- message
+ 1));
1224 if (mb
.mb_threaded
== 0) {
1225 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1226 if (mp
->m_flag
& MMARK
)
1227 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1229 for (mp
= threadroot
; mp
!= NULL
; mp
= next_in_thread(mp
))
1230 if (mp
->m_flag
& MMARK
)
1231 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1234 mc
= (int)PTR2SIZE(ip
- vector
);
1236 pstate
&= ~PS_MSGLIST_DIRECT
;
1243 getrawlist(char const *line
, size_t linesize
, char **argv
, int argc
,
1246 char c
, *cp2
, quotec
, *linebuf
;
1250 pstate
&= ~PS_MSGLIST_MASK
;
1252 linebuf
= ac_alloc(linesize
);
1255 if (!argn
|| !echolist
) {
1256 for (; blankchar(*line
); ++line
)
1261 if (argn
>= argc
- 1) {
1262 n_err(_("Too many elements in the list; excess discarded\n"));
1267 for (quotec
= '\0'; ((c
= *line
++) != '\0');) {
1268 if (quotec
!= '\0') {
1273 } else if (c
== '\\') {
1274 switch (c
= *line
++) {
1280 if (line
[-1] != quotec
|| echolist
)
1286 } else if (c
== '"' || c
== '\'') {
1290 } else if (c
== '\\' && !echolist
)
1291 *cp2
++ = (*line
!= '\0') ? *line
++ : c
;
1292 else if (blankchar(c
))
1297 argv
[argn
++] = savestrbuf(linebuf
, PTR2SIZE(cp2
- linebuf
));
1315 if (msgCount
== 0) {
1323 mb
.mb_threaded
? (mp
!= NULL
) : PTRCMP(mp
, <, message
+ msgCount
);
1324 mb
.mb_threaded
? (mp
= next_in_thread(mp
)) : ++mp
) {
1325 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (ui32_t
)f
) {
1326 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1331 if (dot
> message
) {
1332 for (mp
= dot
- 1; (mb
.mb_threaded
? (mp
!= NULL
) : (mp
>= message
));
1333 mb
.mb_threaded
? (mp
= prev_in_thread(mp
)) : --mp
) {
1334 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (ui32_t
)f
) {
1335 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1347 mark(int mesg
, int f
)
1354 if (i
< 1 || i
> msgCount
)
1355 n_panic(_("Bad message number to mark"));
1357 if (mb
.mb_threaded
== 1 && threadflag
) {
1358 struct message
*mp_t
= message
+ i
- 1;
1360 if (!(mp_t
->m_flag
& MHIDDEN
)) {
1361 if (f
== MDELETED
|| !(mp_t
->m_flag
& MDELETED
) || _list_saw_d
)
1362 mp_t
->m_flag
|= MMARK
;
1365 if (mp_t
->m_child
!= NULL
) {
1367 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1368 for (mp
= mp
->m_younger
; mp
!= NULL
; mp
= mp
->m_younger
)
1369 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1372 message
[i
- 1].m_flag
|= MMARK
;