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
44 /* Token values returned by the scanner used for argument lists.
45 * Also, sizes of scanner-related things */
47 TEOL
= 0, /* End of the command line */
48 TNUMBER
= 1, /* A message number */
49 TDASH
= 2, /* A simple dash */
50 TSTRING
= 3, /* A string (possibly containing -) */
53 TDOLLAR
= 6, /* A "$" */
54 TSTAR
= 7, /* A "*" */
55 TOPEN
= 8, /* A '(' */
56 TCLOSE
= 9, /* A ')' */
57 TPLUS
= 10, /* A '+' */
58 TERROR
= 11, /* A lexical error */
59 TCOMMA
= 12, /* A ',' */
60 TSEMI
= 13, /* A ';' */
61 TBACK
= 14 /* A '`' */
64 #define REGDEP 2 /* Maximum regret depth. */
72 CMNEW
= 1<<0, /* New messages */
73 CMOLD
= 1<<1, /* Old messages */
74 CMUNREAD
= 1<<2, /* Unread messages */
75 CMDELETED
=1<<3, /* Deleted messages */
76 CMREAD
= 1<<4, /* Read messages */
77 CMFLAG
= 1<<5, /* Flagged messages */
78 CMANSWER
= 1<<6, /* Answered messages */
79 CMDRAFT
= 1<<7, /* Draft messages */
80 CMSPAM
= 1<<8 /* Spam messages */
84 char co_char
; /* What to find past : */
85 int co_bit
; /* Associated modifier bit */
86 int co_mask
; /* m_status bits to mask */
87 int co_equal
; /* ... must equal this */
95 static struct coltab
const _coltab
[] = {
96 { 'n', CMNEW
, MNEW
, MNEW
},
97 { 'o', CMOLD
, MNEW
, 0 },
98 { 'u', CMUNREAD
, MREAD
, 0 },
99 { 'd', CMDELETED
, MDELETED
, MDELETED
},
100 { 'r', CMREAD
, MREAD
, MREAD
},
101 { 'f', CMFLAG
, MFLAGGED
, MFLAGGED
},
102 { 'a', CMANSWER
, MANSWERED
, MANSWERED
},
103 { 't', CMDRAFT
, MDRAFTED
, MDRAFTED
},
104 { 's', CMSPAM
, MSPAM
, MSPAM
},
108 static struct lex
const _singles
[] = {
123 static int lastcolmod
;
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
;
214 lexstring
= ac_alloc(STRINGLEN
= 2 * strlen(buf
) +1);
215 valdot
= (int)PTR2SIZE(dot
- message
+ 1);
218 for (i
= 1; i
<= msgCount
; ++i
) {
221 mf
= message
[i
- 1].m_flag
;
227 message
[i
- 1].m_flag
= mf
;
230 np
= namelist
= smalloc((nmlsize
= 8) * sizeof *namelist
);
234 beg
= star
= other
= topen
= tback
= FAL0
;
239 for (tok
= scan(&bufp
); tok
!= TEOL
;) {
244 fprintf(stderr
, tr(112, "No numbers mixed with *\n"));
247 list_saw_numbers
= TRU1
;
251 if (check(lexnumber
, f
))
254 while (mb
.mb_threaded
? 1 : i
<= lexnumber
) {
255 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
256 (f
== MDELETED
|| !(message
[i
- 1].m_flag
& MDELETED
)))
258 if (mb
.mb_threaded
) {
261 mx
= next_in_thread(&message
[i
- 1]);
264 i
= (int)PTR2SIZE(mx
- message
+ 1);
283 msglist_is_single
= FAL0
;
285 printf(tr(113, "Non-numeric second argument\n"));
290 if (mb
.mb_threaded
) {
291 mx
= next_in_thread(message
+ i
- 1);
292 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : msgCount
+ 1;
296 fprintf(stderr
, tr(114, "Referencing beyond EOF\n"));
299 } while (message
[i
- 1].m_flag
== MHIDDEN
||
300 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
305 msglist_is_single
= FAL0
;
309 if (mb
.mb_threaded
) {
310 mx
= prev_in_thread(message
+ i
- 1);
311 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : 0;
315 fprintf(stderr
, tr(115, "Referencing before 1\n"));
318 } while ((message
[i
- 1].m_flag
& MHIDDEN
) ||
319 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
325 msglist_is_single
= FAL0
;
327 fprintf(stderr
, tr(116, "Non-numeric second argument\n"));
331 if (lexstring
[0] == ':') {
332 colresult
= evalcol(lexstring
[1]);
333 if (colresult
== 0) {
334 fprintf(stderr
, tr(117, "Unknown colon modifier \"%s\"\n"),
341 np
= add_to_namelist(&namelist
, &nmlsize
, np
, savestr(lexstring
));
345 #ifdef HAVE_IMAP_SEARCH
346 msglist_is_single
= FAL0
;
347 if (imap_search(lexstring
, f
) == STOP
)
351 fprintf(stderr
, tr(42,
352 "`%s': the used selector is optional and not available\n"),
362 msglist_is_single
= FAL0
;
363 lexnumber
= metamess(lexstring
[0], f
);
369 msglist_is_single
= FAL0
;
371 for (i
= 1; i
<= msgCount
; i
++) {
372 if ((message
[i
- 1].m_flag
& MHIDDEN
) ||
373 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
)
375 if (message
[i
- 1].m_flag
& MOLDMARK
)
381 msglist_is_single
= FAL0
;
383 fprintf(stderr
, tr(118, "Can't mix \"*\" with anything\n"));
390 msglist_is_single
= FAL0
;
392 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
393 imap_getheaders(1, msgCount
);
395 if (id
== NULL
&& (cp
= hfield1("in-reply-to", dot
)) != NULL
) {
397 idfield
= ID_IN_REPLY_TO
;
399 if (id
== NULL
&& (cp
= hfield1("references", dot
)) != NULL
) {
402 if ((enp
= extract(cp
, GREF
)) != NULL
) {
403 while (enp
->n_flink
!= NULL
)
405 id
= savestr(enp
->n_name
);
406 idfield
= ID_REFERENCES
;
411 "Cannot determine parent Message-ID of the current message\n"));
417 list_saw_numbers
= TRU1
;
418 msglist_is_single
= FAL0
;
426 np
= add_to_namelist(&namelist
, &nmlsize
, np
, NULL
);
430 for (i
= 0; i
< msgCount
; ++i
) {
431 if (!(message
[i
].m_flag
& MHIDDEN
) &&
432 (message
[i
].m_flag
& MDELETED
) == (unsigned)f
) {
439 printf(tr(119, "No applicable messages.\n"));
445 if ((topen
|| tback
) && !mc
) {
446 for (i
= 0; i
< msgCount
; ++i
)
447 if (message
[i
].m_flag
& MMARK
)
452 fprintf(stderr
, tr(131, "No previously marked messages.\n"));
454 printf("No messages satisfy (criteria).\n");/*TODO tr*/
460 /* If no numbers were given, mark all messages, so that we can unmark
461 * any whose sender was not selected if any user names were given */
462 if ((np
> namelist
|| colmod
!= 0 || id
) && !mc
)
463 for (i
= 1; i
<= msgCount
; ++i
) {
464 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
465 (message
[i
- 1].m_flag
& MDELETED
) == (unsigned)f
)
469 /* If any names were given, eliminate any messages which don't match */
470 if (np
> namelist
|| id
) {
471 struct search_expr
*sep
= NULL
;
474 /* The `@' search works with struct search_expr, so build an array.
475 * To simplify array, i.e., regex_t destruction, and optimize for the
476 * common case we walk the entire array even in case of errors */
478 sep
= scalloc(PTR2SIZE(np
- namelist
), sizeof(*sep
));
479 for (j
= 0, nq
= namelist
; *nq
!= NULL
; ++j
, ++nq
) {
483 if (*x
!= '@' || rv
< 0)
486 for (y
= x
+ 1;; ++y
) {
487 if (*y
== '\0' || !fieldnamechar(*y
)) {
496 sep
[j
].ss_where
= (x
== NULL
|| x
- 1 == *nq
)
497 ? "subject" : savestrbuf(*nq
+ 1, PTR2SIZE(x
- *nq
) - 1);
499 x
= (x
== NULL
? *nq
: x
) + 1;
500 if (*x
== '\0') { /* XXX Simply remove from list instead? */
501 fprintf(stderr
, tr(525, "Empty `[@..]@' search expression\n"));
506 if (anyof("^.[]*+?(){}|$", x
)) {
507 sep
[j
].ss_sexpr
= NULL
;
508 if (regcomp(&sep
[j
].ss_reexpr
, x
,
509 REG_EXTENDED
| REG_ICASE
| REG_NOSUB
) != 0) {
510 fprintf(stderr
, tr(526,
511 "Invalid regular expression: >>> %s <<<\n"), x
);
520 goto jnamesearch_sepfree
;
524 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
525 imap_getheaders(1, msgCount
);
528 allnet
= ok_blook(allnet
);
529 for (i
= 1; i
<= msgCount
; ++i
) {
530 mp
= message
+ i
- 1;
533 for (nq
= namelist
; *nq
!= NULL
; ++nq
) {
535 if (_match_at(mp
, sep
+ PTR2SIZE(nq
- namelist
))) {
539 } else if (**nq
== '/') {
540 if (_match_dash(mp
, *nq
)) {
544 } else if (_matchsender(mp
, *nq
, allnet
)) {
550 if (j
== 0 && id
&& _matchmid(mp
, id
, idfield
))
553 mp
->m_flag
&= ~MMARK
;
558 /* Make sure we got some decent messages */
560 for (i
= 1; i
<= msgCount
; ++i
)
561 if (message
[i
- 1].m_flag
& MMARK
) {
566 if (!inhook
&& np
> namelist
) {
567 printf(tr(120, "No applicable messages from {%s"), namelist
[0]);
568 for (nq
= namelist
+ 1; *nq
!= NULL
; ++nq
)
569 printf(tr(121, ", %s"), *nq
);
570 printf(tr(122, "}\n"));
572 printf(tr(227, "Parent message not found\n"));
574 goto jnamesearch_sepfree
;
580 for (j
= PTR2SIZE(np
- namelist
); j
-- != 0;)
581 if (sep
[j
].ss_sexpr
== NULL
)
582 regfree(&sep
[j
].ss_reexpr
);
590 /* If any colon modifiers were given, go through and unmark any
591 * messages which do not satisfy the modifiers */
593 for (i
= 1; i
<= msgCount
; ++i
) {
594 struct coltab
const *colp
;
597 mp
= message
+ i
- 1;
598 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
599 if ((colp
->co_bit
& colmod
) &&
600 ((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
)
608 if (PTRCMP(mp
, >=, message
+ msgCount
)) {
609 struct coltab
const *colp
;
612 printf(tr(123, "No messages satisfy"));
613 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
614 if (colp
->co_bit
& colmod
)
615 printf(" :%c", colp
->co_char
);
635 struct coltab
const *colp
;
643 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
644 if (colp
->co_char
== col
) {
654 check(int mesg
, int f
)
659 if (mesg
< 1 || mesg
> msgCount
) {
660 printf(tr(124, "%d: Invalid message number\n"), mesg
);
663 mp
= message
+ mesg
- 1;
664 if (mp
->m_flag
& MHIDDEN
||
665 (f
!= MDELETED
&& (mp
->m_flag
& MDELETED
) != 0)) {
666 fprintf(stderr
, tr(125, "%d: Inappropriate message\n"), mesg
);
682 int rv
, c
, inquote
, quotec
;
683 struct lex
const *lp
;
687 strncpy(lexstring
, string_stack
[regretp
], STRINGLEN
);
688 lexstring
[STRINGLEN
-1] = '\0';
689 lexnumber
= numberstack
[regretp
];
690 rv
= regretstack
[regretp
--];
698 /* strip away leading white space */
702 /* If no characters remain, we are at end of line, so report that */
709 /* Select members of a message thread */
712 if (*cp
== '\0' || spacechar(*cp
)) {
722 /* If the leading character is a digit, scan the number and convert it
723 * on the fly. Return TNUMBER when done */
726 while (digitchar(c
)) {
727 lexnumber
= lexnumber
*10 + c
- '0';
737 /* An IMAP SEARCH list. Note that TOPEN has always been included in
738 * singles[] in Mail and mailx. Thus although there is no formal
739 * definition for (LIST) lists, they do not collide with historical
740 * practice because a subject string (LIST) could never been matched
747 if ((c
= *cp
++&0377) == '\0') {
749 fprintf(stderr
, "Missing \")\".\n");
753 if (inquote
&& c
== '\\') {
766 else if (spacechar(c
)) {
767 /* Replace unquoted whitespace by single space characters, to make
768 * the string IMAP SEARCH conformant */
774 } while (c
!= ')' || level
> 0);
781 /* Check for single character tokens; return such if found */
782 for (lp
= _singles
; lp
->l_char
!= '\0'; ++lp
)
783 if (c
== lp
->l_char
) {
791 /* We've got a string! Copy all the characters of the string into
792 * lexstring, until we see a null, space, or tab. If the lead character is
793 * a " or ', save it and scan until you get another */
795 if (c
== '\'' || c
== '"') {
800 if (quotec
== 0 && c
== '\\' && *cp
!= '\0')
806 if (quotec
== 0 && blankchar(c
))
808 if (PTRCMP(cp2
- lexstring
, <, STRINGLEN
- 1))
812 if (quotec
&& c
== 0) {
813 fprintf(stderr
, tr(127, "Missing %c\n"), quotec
);
829 if (++regretp
>= REGDEP
)
830 panic(tr(128, "Too many regrets"));
831 regretstack
[regretp
] = token
;
832 lexstring
[STRINGLEN
-1] = '\0';
833 string_stack
[regretp
] = savestr(lexstring
);
834 numberstack
[regretp
] = lexnumber
;
848 _matchsender(struct message
*mp
, char const *str
, bool_t allnet
)
854 char *cp
= nameof(mp
, 0);
857 if ((*cp
== '@' || *cp
== '\0') && (*str
== '@' || *str
== '\0')) {
863 } while (++cp
, *str
++ != '\0');
867 rv
= !strcmp(str
, (*(ok_blook(showname
) ? &realname
: &skin
))(name1(mp
, 0)));
874 _matchmid(struct message
*mp
, char *id
, enum idfield idfield
)
880 if ((cp
= hfield1("message-id", mp
)) != NULL
) {
883 rv
= !msgidcmp(id
, cp
);
885 case ID_IN_REPLY_TO
: {
888 if ((np
= extract(id
, GREF
)) != NULL
)
890 if (!msgidcmp(np
->n_name
, cp
)) {
894 } while ((np
= np
->n_flink
) != NULL
);
906 _match_dash(struct message
*mp
, char const *str
)
908 static char lastscan
[128];
911 char *hfield
, *hbody
;
915 if (*++str
== '\0') {
918 strncpy(lastscan
, str
, sizeof lastscan
); /* XXX use new n_str object! */
919 lastscan
[sizeof lastscan
-1] = '\0';
922 /* Now look, ignoring case, for the word in the string */
923 if (ok_blook(searchheaders
) && (hfield
= strchr(str
, ':'))) {
924 size_t l
= PTR2SIZE(hfield
- str
);
925 hfield
= ac_alloc(l
+1);
926 memcpy(hfield
, str
, l
);
928 hbody
= hfieldX(hfield
, mp
);
930 hfield
= UNCONST(str
+ l
+ 1);
932 hfield
= UNCONST(str
);
933 hbody
= hfield1("subject", mp
);
941 in
.l
= strlen(hbody
);
942 mime_fromhdr(&in
, &out
, TD_ICONV
);
943 rv
= substr(out
.s
, hfield
);
951 _match_at(struct message
*mp
, struct search_expr
*sep
)
954 char *nfield
, *cfield
;
958 nfield
= savestr(sep
->ss_where
);
960 while ((cfield
= n_strsep(&nfield
, ',', TRU1
)) != NULL
) {
961 if (!asccasecmp(cfield
, "body")) {
964 if ((rv
= message_match(mp
, sep
, rv
)))
966 } else if (!asccasecmp(cfield
, "text")) {
969 } else if ((in
.s
= hfieldX(cfield
, mp
)) == NULL
)
973 mime_fromhdr(&in
, &out
, TD_ICONV
);
975 if (sep
->ss_sexpr
== NULL
)
976 rv
= (regexec(&sep
->ss_reexpr
, out
.s
, 0,NULL
, 0) != REG_NOMATCH
);
979 rv
= substr(out
.s
, sep
->ss_sexpr
);
996 if (i
< 1 || UICMP(z
, i
, >, msgCount
))
997 panic(tr(130, "Bad message number to unmark"));
998 message
[i
- 1].m_flag
&= ~MMARK
;
1003 metamess(int meta
, int f
)
1011 case '^': /* First 'good' message left */
1012 mp
= mb
.mb_threaded
? threadroot
: message
;
1013 while (PTRCMP(mp
, <, message
+ msgCount
)) {
1014 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1015 c
= (int)PTR2SIZE(mp
- message
+ 1);
1018 if (mb
.mb_threaded
) {
1019 mp
= next_in_thread(mp
);
1026 printf(tr(132, "No applicable messages\n"));
1029 case '$': /* Last 'good message left */
1031 ? this_in_thread(threadroot
, -1) : message
+ msgCount
- 1;
1032 while (mp
>= message
) {
1033 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1034 c
= (int)PTR2SIZE(mp
- message
+ 1);
1037 if (mb
.mb_threaded
) {
1038 mp
= prev_in_thread(mp
);
1045 printf(tr(132, "No applicable messages\n"));
1049 /* Current message */
1050 m
= dot
- message
+ 1;
1051 if ((dot
->m_flag
& MHIDDEN
) || (dot
->m_flag
& MDELETED
) != (ui32_t
)f
) {
1052 printf(tr(133, "%d: Inappropriate message\n"), m
);
1059 /* Previously current message */
1060 if (prevdot
== NULL
) {
1061 fprintf(stderr
, tr(228, "No previously current message\n"));
1064 m
= prevdot
- message
+ 1;
1065 if ((prevdot
->m_flag
& MHIDDEN
) ||
1066 (prevdot
->m_flag
& MDELETED
) != (ui32_t
)f
) {
1067 fprintf(stderr
, tr(133, "%d: Inappropriate message\n"), m
);
1074 fprintf(stderr
, tr(134, "Unknown metachar (%c)\n"), c
);
1086 getmsglist(char *buf
, int *vector
, int flags
)
1093 msglist_is_single
= FAL0
;
1095 if (msgCount
== 0) {
1101 msglist_is_single
= TRU1
;
1102 if (markall(buf
, flags
) < 0) {
1110 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1111 if (mp
->m_flag
& MMARK
) {
1112 if (!(mp
->m_flag
& MNEWEST
))
1113 unmark((int)PTR2SIZE(mp
- message
+ 1));
1123 if (mb
.mb_threaded
== 0) {
1124 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1125 if (mp
->m_flag
& MMARK
)
1126 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1128 for (mp
= threadroot
; mp
!= NULL
; mp
= next_in_thread(mp
))
1129 if (mp
->m_flag
& MMARK
)
1130 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1133 mc
= (int)PTR2SIZE(ip
- vector
);
1134 msglist_is_single
= (mc
== 1);
1141 getrawlist(char const *line
, size_t linesize
, char **argv
, int argc
,
1144 char c
, *cp2
, quotec
, *linebuf
;
1149 list_saw_numbers
= FAL0
;
1153 linebuf
= ac_alloc(linesize
+1);
1155 for (; blankchar(*cp
); ++cp
)
1159 if (argn
>= argc
- 1) {
1160 printf(tr(126, "Too many elements in the list; excess discarded.\n"));
1165 while ((c
= *cp
) != '\0') {
1167 if (quotec
!= '\0') {
1172 } else if (c
== '\\')
1173 switch (c
= *cp
++) {
1179 case '0': case '1': case '2': case '3':
1180 case '4': case '5': case '6': case '7':
1182 if (*cp >= '0' && *cp <= '7')
1183 c = c * 8 + *cp++ - '0';
1184 if (*cp >= '0' && *cp <= '7')
1185 c = c * 8 + *cp++ - '0';
1208 if (cp
[-1] != quotec
|| echolist
)
1212 /*else if (c == '^') {
1216 /\* null doesn't show up anyway *\/
1217 else if ((c >= 'A' && c <= '_') ||
1218 (c >= 'a' && c <= 'z'))
1226 } else if (c
== '"' || c
== '\'') {
1230 } else if (c
== '\\' && !echolist
) {
1235 } else if (blankchar(c
))
1241 argv
[argn
++] = savestr(linebuf
);
1256 if (msgCount
== 0) {
1264 mb
.mb_threaded
? (mp
!= NULL
) : PTRCMP(mp
, <, message
+ msgCount
);
1265 mb
.mb_threaded
? (mp
= next_in_thread(mp
)) : ++mp
) {
1266 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (ui32_t
)f
) {
1267 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1272 if (dot
> message
) {
1273 for (mp
= dot
- 1; (mb
.mb_threaded
? (mp
!= NULL
) : (mp
>= message
));
1274 mb
.mb_threaded
? (mp
= prev_in_thread(mp
)) : --mp
) {
1275 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (ui32_t
)f
) {
1276 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1288 mark(int mesg
, int f
)
1295 if (i
< 1 || i
> msgCount
)
1296 panic(tr(129, "Bad message number to mark"));
1297 if (mb
.mb_threaded
== 1 && threadflag
) {
1298 if (!(message
[i
- 1].m_flag
& MHIDDEN
)) {
1299 if (f
== MDELETED
|| !(message
[i
- 1].m_flag
& MDELETED
))
1300 message
[i
- 1].m_flag
|= MMARK
;
1303 if (message
[i
- 1].m_child
) {
1304 mp
= message
[i
- 1].m_child
;
1305 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1306 for (mp
= mp
->m_younger
; mp
!= NULL
; mp
= mp
->m_younger
)
1307 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1310 message
[i
- 1].m_flag
|= MMARK
;
1314 /* vim:set fenc=utf-8:s-it-mode */