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
, mc
, other
, valdot
, colmod
, colresult
;
205 struct message
*mp
, *mx
;
206 bool_t 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
);
233 beg
= mc
= star
= other
= topen
= tback
= FAL0
;
238 for (tok
= scan(&bufp
); tok
!= TEOL
;) {
243 fprintf(stderr
, tr(112, "No numbers mixed with *\n"));
246 list_saw_numbers
= TRU1
;
250 if (check(lexnumber
, f
))
253 while (mb
.mb_threaded
? 1 : i
<= lexnumber
) {
254 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
255 (f
== MDELETED
|| !(message
[i
- 1].m_flag
& MDELETED
)))
257 if (mb
.mb_threaded
) {
260 mx
= next_in_thread(&message
[i
- 1]);
263 i
= (int)PTR2SIZE(mx
- message
+ 1);
282 msglist_is_single
= FAL0
;
284 printf(tr(113, "Non-numeric second argument\n"));
289 if (mb
.mb_threaded
) {
290 mx
= next_in_thread(message
+ i
- 1);
291 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : msgCount
+ 1;
295 fprintf(stderr
, tr(114, "Referencing beyond EOF\n"));
298 } while (message
[i
- 1].m_flag
== MHIDDEN
||
299 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
304 msglist_is_single
= FAL0
;
308 if (mb
.mb_threaded
) {
309 mx
= prev_in_thread(message
+ i
- 1);
310 i
= mx
? (int)PTR2SIZE(mx
- message
+ 1) : 0;
314 fprintf(stderr
, tr(115, "Referencing before 1\n"));
317 } while ((message
[i
- 1].m_flag
& MHIDDEN
) ||
318 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
);
324 msglist_is_single
= FAL0
;
326 fprintf(stderr
, tr(116, "Non-numeric second argument\n"));
330 if (lexstring
[0] == ':') {
331 colresult
= evalcol(lexstring
[1]);
332 if (colresult
== 0) {
333 fprintf(stderr
, tr(117, "Unknown colon modifier \"%s\"\n"),
340 np
= add_to_namelist(&namelist
, &nmlsize
, np
, savestr(lexstring
));
344 #ifdef HAVE_IMAP_SEARCH
345 msglist_is_single
= FAL0
;
346 if (imap_search(lexstring
, f
) == STOP
)
350 fprintf(stderr
, tr(42,
351 "`%s': the used selector is optional and not available\n"),
361 msglist_is_single
= FAL0
;
362 lexnumber
= metamess(lexstring
[0], f
);
368 msglist_is_single
= FAL0
;
370 for (i
= 1; i
<= msgCount
; i
++) {
371 if ((message
[i
- 1].m_flag
& MHIDDEN
) ||
372 (message
[i
- 1].m_flag
& MDELETED
) != (unsigned)f
)
374 if (message
[i
- 1].m_flag
& MOLDMARK
)
380 msglist_is_single
= FAL0
;
382 fprintf(stderr
, tr(118, "Can't mix \"*\" with anything\n"));
389 msglist_is_single
= FAL0
;
391 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
392 imap_getheaders(1, msgCount
);
394 if (id
== NULL
&& (cp
= hfield1("in-reply-to", dot
)) != NULL
) {
396 idfield
= ID_IN_REPLY_TO
;
398 if (id
== NULL
&& (cp
= hfield1("references", dot
)) != NULL
) {
401 if ((enp
= extract(cp
, GREF
)) != NULL
) {
402 while (enp
->n_flink
!= NULL
)
404 id
= savestr(enp
->n_name
);
405 idfield
= ID_REFERENCES
;
410 "Cannot determine parent Message-ID of the current message\n"));
416 list_saw_numbers
= TRU1
;
417 msglist_is_single
= FAL0
;
425 np
= add_to_namelist(&namelist
, &nmlsize
, np
, NULL
);
429 for (i
= 0; i
< msgCount
; ++i
) {
430 if (!(message
[i
].m_flag
& MHIDDEN
) &&
431 (message
[i
].m_flag
& MDELETED
) == (unsigned)f
) {
438 printf(tr(119, "No applicable messages.\n"));
444 if ((topen
|| tback
) && mc
== 0) {
445 for (i
= 0; i
< msgCount
; ++i
)
446 if (message
[i
].m_flag
& MMARK
)
451 fprintf(stderr
, tr(131, "No previously marked messages.\n"));
453 printf("No messages satisfy (criteria).\n");/*TODO tr*/
459 /* If no numbers were given, mark all messages, so that we can unmark
460 * any whose sender was not selected if any user names were given */
461 if ((np
> namelist
|| colmod
!= 0 || id
) && mc
== 0)
462 for (i
= 1; i
<= msgCount
; ++i
) {
463 if (!(message
[i
- 1].m_flag
& MHIDDEN
) &&
464 (message
[i
- 1].m_flag
& MDELETED
) == (unsigned)f
)
468 /* If any names were given, eliminate any messages which don't match */
469 if (np
> namelist
|| id
) {
470 struct search_expr
*sep
= NULL
;
473 /* The `@' search works with struct search_expr, so build an array.
474 * To simplify array, i.e., regex_t destruction, and optimize for the
475 * common case we walk the entire array even in case of errors */
477 sep
= scalloc(PTR2SIZE(np
- namelist
), sizeof(*sep
));
478 for (j
= 0, nq
= namelist
; *nq
!= NULL
; ++j
, ++nq
) {
482 if (*x
!= '@' || rv
< 0)
485 for (y
= x
+ 1;; ++y
) {
486 if (*y
== '\0' || !fieldnamechar(*y
)) {
495 sep
[j
].ss_where
= (x
== NULL
|| x
- 1 == *nq
)
496 ? "subject" : savestrbuf(*nq
+ 1, PTR2SIZE(x
- *nq
) - 1);
498 x
= (x
== NULL
? *nq
: x
) + 1;
499 if (*x
== '\0') { /* XXX Simply remove from list instead? */
500 fprintf(stderr
, tr(525, "Empty `[@..]@' search expression\n"));
505 if (anyof("^.[]*+?(){}|$", x
)) {
506 sep
[j
].ss_sexpr
= NULL
;
507 if (regcomp(&sep
[j
].ss_reexpr
, x
,
508 REG_EXTENDED
| REG_ICASE
| REG_NOSUB
) != 0) {
509 fprintf(stderr
, tr(526,
510 "Invalid regular expression: >>> %s <<<\n"), x
);
519 goto jnamesearch_sepfree
;
523 if (mb
.mb_type
== MB_IMAP
&& gotheaders
++ == 0)
524 imap_getheaders(1, msgCount
);
527 allnet
= ok_blook(allnet
);
528 for (i
= 1; i
<= msgCount
; ++i
) {
529 mp
= message
+ i
- 1;
532 for (nq
= namelist
; *nq
!= NULL
; ++nq
) {
534 if (_match_at(mp
, sep
+ PTR2SIZE(nq
- namelist
))) {
538 } else if (**nq
== '/') {
539 if (_match_dash(mp
, *nq
)) {
543 } else if (_matchsender(mp
, *nq
, allnet
)) {
549 if (j
== 0 && id
&& _matchmid(mp
, id
, idfield
))
552 mp
->m_flag
&= ~MMARK
;
557 /* Make sure we got some decent messages */
559 for (i
= 1; i
<= msgCount
; ++i
)
560 if (message
[i
- 1].m_flag
& MMARK
) {
565 if (!inhook
&& np
> namelist
) {
566 printf(tr(120, "No applicable messages from {%s"), namelist
[0]);
567 for (nq
= namelist
+ 1; *nq
!= NULL
; ++nq
)
568 printf(tr(121, ", %s"), *nq
);
569 printf(tr(122, "}\n"));
571 printf(tr(227, "Parent message not found\n"));
573 goto jnamesearch_sepfree
;
579 for (j
= PTR2SIZE(np
- namelist
); j
-- != 0;)
580 if (sep
[j
].ss_sexpr
== NULL
)
581 regfree(&sep
[j
].ss_reexpr
);
589 /* If any colon modifiers were given, go through and unmark any
590 * messages which do not satisfy the modifiers */
592 for (i
= 1; i
<= msgCount
; ++i
) {
593 struct coltab
const *colp
;
596 mp
= message
+ i
- 1;
597 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
598 if ((colp
->co_bit
& colmod
) &&
599 ((mp
->m_flag
& colp
->co_mask
) == (unsigned)colp
->co_equal
))
604 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
605 if (mp
->m_flag
& MMARK
)
607 if (PTRCMP(mp
, >=, message
+ msgCount
)) {
608 struct coltab
const *colp
;
611 printf(tr(123, "No messages satisfy"));
612 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
613 if (colp
->co_bit
& colmod
)
614 printf(" :%c", colp
->co_char
);
634 struct coltab
const *colp
;
642 for (colp
= _coltab
; colp
->co_char
!= '\0'; ++colp
)
643 if (colp
->co_char
== col
) {
653 check(int mesg
, int f
)
658 if (mesg
< 1 || mesg
> msgCount
) {
659 printf(tr(124, "%d: Invalid message number\n"), mesg
);
662 mp
= message
+ mesg
- 1;
663 if (mp
->m_flag
& MHIDDEN
||
664 (f
!= MDELETED
&& (mp
->m_flag
& MDELETED
) != 0)) {
665 fprintf(stderr
, tr(125, "%d: Inappropriate message\n"), mesg
);
681 int rv
, c
, inquote
, quotec
;
682 struct lex
const *lp
;
686 strncpy(lexstring
, string_stack
[regretp
], STRINGLEN
);
687 lexstring
[STRINGLEN
-1] = '\0';
688 lexnumber
= numberstack
[regretp
];
689 rv
= regretstack
[regretp
--];
697 /* strip away leading white space */
701 /* If no characters remain, we are at end of line, so report that */
708 /* Select members of a message thread */
711 if (*cp
== '\0' || spacechar(*cp
)) {
721 /* If the leading character is a digit, scan the number and convert it
722 * on the fly. Return TNUMBER when done */
725 while (digitchar(c
)) {
726 lexnumber
= lexnumber
*10 + c
- '0';
736 /* An IMAP SEARCH list. Note that TOPEN has always been included in
737 * singles[] in Mail and mailx. Thus although there is no formal
738 * definition for (LIST) lists, they do not collide with historical
739 * practice because a subject string (LIST) could never been matched
746 if ((c
= *cp
++&0377) == '\0') {
748 fprintf(stderr
, "Missing \")\".\n");
752 if (inquote
&& c
== '\\') {
765 else if (spacechar(c
)) {
766 /* Replace unquoted whitespace by single space characters, to make
767 * the string IMAP SEARCH conformant */
773 } while (c
!= ')' || level
> 0);
780 /* Check for single character tokens; return such if found */
781 for (lp
= _singles
; lp
->l_char
!= '\0'; ++lp
)
782 if (c
== lp
->l_char
) {
790 /* We've got a string! Copy all the characters of the string into
791 * lexstring, until we see a null, space, or tab. If the lead character is
792 * a " or ', save it and scan until you get another */
794 if (c
== '\'' || c
== '"') {
799 if (quotec
== 0 && c
== '\\' && *cp
!= '\0')
805 if (quotec
== 0 && blankchar(c
))
807 if (PTRCMP(cp2
- lexstring
, <, STRINGLEN
- 1))
811 if (quotec
&& c
== 0) {
812 fprintf(stderr
, tr(127, "Missing %c\n"), quotec
);
828 if (++regretp
>= REGDEP
)
829 panic(tr(128, "Too many regrets"));
830 regretstack
[regretp
] = token
;
831 lexstring
[STRINGLEN
-1] = '\0';
832 string_stack
[regretp
] = savestr(lexstring
);
833 numberstack
[regretp
] = lexnumber
;
847 _matchsender(struct message
*mp
, char const *str
, bool_t allnet
)
853 char *cp
= nameof(mp
, 0);
856 if ((*cp
== '@' || *cp
== '\0') && (*str
== '@' || *str
== '\0')) {
862 } while (++cp
, *str
++ != '\0');
866 rv
= !strcmp(str
, (*(ok_blook(showname
) ? &realname
: &skin
))(name1(mp
, 0)));
873 _matchmid(struct message
*mp
, char *id
, enum idfield idfield
)
879 if ((cp
= hfield1("message-id", mp
)) != NULL
) {
882 rv
= !msgidcmp(id
, cp
);
884 case ID_IN_REPLY_TO
: {
887 if ((np
= extract(id
, GREF
)) != NULL
)
889 if (!msgidcmp(np
->n_name
, cp
)) {
893 } while ((np
= np
->n_flink
) != NULL
);
905 _match_dash(struct message
*mp
, char const *str
)
907 static char lastscan
[128];
910 char *hfield
, *hbody
;
914 if (*++str
== '\0') {
917 strncpy(lastscan
, str
, sizeof lastscan
); /* XXX use new n_str object! */
918 lastscan
[sizeof lastscan
-1] = '\0';
921 /* Now look, ignoring case, for the word in the string */
922 if (ok_blook(searchheaders
) && (hfield
= strchr(str
, ':'))) {
923 size_t l
= PTR2SIZE(hfield
- str
);
924 hfield
= ac_alloc(l
+1);
925 memcpy(hfield
, str
, l
);
927 hbody
= hfieldX(hfield
, mp
);
929 hfield
= UNCONST(str
+ l
+ 1);
931 hfield
= UNCONST(str
);
932 hbody
= hfield1("subject", mp
);
940 in
.l
= strlen(hbody
);
941 mime_fromhdr(&in
, &out
, TD_ICONV
);
942 rv
= substr(out
.s
, hfield
);
950 _match_at(struct message
*mp
, struct search_expr
*sep
)
953 char *nfield
, *cfield
;
957 nfield
= savestr(sep
->ss_where
);
959 while ((cfield
= n_strsep(&nfield
, ',', TRU1
)) != NULL
) {
960 if (!asccasecmp(cfield
, "body")) {
963 if ((rv
= message_match(mp
, sep
, rv
)))
965 } else if (!asccasecmp(cfield
, "text")) {
968 } else if ((in
.s
= hfieldX(cfield
, mp
)) == NULL
)
972 mime_fromhdr(&in
, &out
, TD_ICONV
);
974 if (sep
->ss_sexpr
== NULL
)
975 rv
= (regexec(&sep
->ss_reexpr
, out
.s
, 0,NULL
, 0) != REG_NOMATCH
);
978 rv
= substr(out
.s
, sep
->ss_sexpr
);
995 if (i
< 1 || UICMP(z
, i
, >, msgCount
))
996 panic(tr(130, "Bad message number to unmark"));
997 message
[i
- 1].m_flag
&= ~MMARK
;
1002 metamess(int meta
, int f
)
1010 case '^': /* First 'good' message left */
1011 mp
= mb
.mb_threaded
? threadroot
: message
;
1012 while (PTRCMP(mp
, <, message
+ msgCount
)) {
1013 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1014 c
= (int)PTR2SIZE(mp
- message
+ 1);
1017 if (mb
.mb_threaded
) {
1018 mp
= next_in_thread(mp
);
1025 printf(tr(132, "No applicable messages\n"));
1028 case '$': /* Last 'good message left */
1030 ? this_in_thread(threadroot
, -1) : message
+ msgCount
- 1;
1031 while (mp
>= message
) {
1032 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& MDELETED
) == (ui32_t
)f
) {
1033 c
= (int)PTR2SIZE(mp
- message
+ 1);
1036 if (mb
.mb_threaded
) {
1037 mp
= prev_in_thread(mp
);
1044 printf(tr(132, "No applicable messages\n"));
1048 /* Current message */
1049 m
= dot
- message
+ 1;
1050 if ((dot
->m_flag
& MHIDDEN
) || (dot
->m_flag
& MDELETED
) != (ui32_t
)f
) {
1051 printf(tr(133, "%d: Inappropriate message\n"), m
);
1058 /* Previously current message */
1059 if (prevdot
== NULL
) {
1060 fprintf(stderr
, tr(228, "No previously current message\n"));
1063 m
= prevdot
- message
+ 1;
1064 if ((prevdot
->m_flag
& MHIDDEN
) ||
1065 (prevdot
->m_flag
& MDELETED
) != (ui32_t
)f
) {
1066 fprintf(stderr
, tr(133, "%d: Inappropriate message\n"), m
);
1073 fprintf(stderr
, tr(134, "Unknown metachar (%c)\n"), c
);
1085 getmsglist(char *buf
, int *vector
, int flags
)
1092 msglist_is_single
= FAL0
;
1094 if (msgCount
== 0) {
1100 msglist_is_single
= TRU1
;
1101 if (markall(buf
, flags
) < 0) {
1109 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1110 if (mp
->m_flag
& MMARK
) {
1111 if (!(mp
->m_flag
& MNEWEST
))
1112 unmark((int)PTR2SIZE(mp
- message
+ 1));
1122 if (mb
.mb_threaded
== 0) {
1123 for (mp
= message
; PTRCMP(mp
, <, message
+ msgCount
); ++mp
)
1124 if (mp
->m_flag
& MMARK
)
1125 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1127 for (mp
= threadroot
; mp
!= NULL
; mp
= next_in_thread(mp
))
1128 if (mp
->m_flag
& MMARK
)
1129 *ip
++ = (int)PTR2SIZE(mp
- message
+ 1);
1132 mc
= (int)PTR2SIZE(ip
- vector
);
1133 msglist_is_single
= (mc
== 1);
1140 getrawlist(char const *line
, size_t linesize
, char **argv
, int argc
,
1143 char c
, *cp2
, quotec
, *linebuf
;
1148 list_saw_numbers
= FAL0
;
1152 linebuf
= ac_alloc(linesize
+1);
1154 for (; blankchar(*cp
); ++cp
)
1158 if (argn
>= argc
- 1) {
1159 printf(tr(126, "Too many elements in the list; excess discarded.\n"));
1164 while ((c
= *cp
) != '\0') {
1166 if (quotec
!= '\0') {
1171 } else if (c
== '\\')
1172 switch (c
= *cp
++) {
1178 case '0': case '1': case '2': case '3':
1179 case '4': case '5': case '6': case '7':
1181 if (*cp >= '0' && *cp <= '7')
1182 c = c * 8 + *cp++ - '0';
1183 if (*cp >= '0' && *cp <= '7')
1184 c = c * 8 + *cp++ - '0';
1207 if (cp
[-1] != quotec
|| echolist
)
1211 /*else if (c == '^') {
1215 /\* null doesn't show up anyway *\/
1216 else if ((c >= 'A' && c <= '_') ||
1217 (c >= 'a' && c <= 'z'))
1225 } else if (c
== '"' || c
== '\'') {
1229 } else if (c
== '\\' && !echolist
) {
1234 } else if (blankchar(c
))
1240 argv
[argn
++] = savestr(linebuf
);
1255 if (msgCount
== 0) {
1263 mb
.mb_threaded
? (mp
!= NULL
) : PTRCMP(mp
, <, message
+ msgCount
);
1264 mb
.mb_threaded
? (mp
= next_in_thread(mp
)) : ++mp
) {
1265 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (ui32_t
)f
) {
1266 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1271 if (dot
> message
) {
1272 for (mp
= dot
- 1; (mb
.mb_threaded
? (mp
!= NULL
) : (mp
>= message
));
1273 mb
.mb_threaded
? (mp
= prev_in_thread(mp
)) : --mp
) {
1274 if (!(mp
->m_flag
& MHIDDEN
) && (mp
->m_flag
& m
) == (ui32_t
)f
) {
1275 rv
= (int)PTR2SIZE(mp
- message
+ 1);
1287 mark(int mesg
, int f
)
1294 if (i
< 1 || i
> msgCount
)
1295 panic(tr(129, "Bad message number to mark"));
1296 if (mb
.mb_threaded
== 1 && threadflag
) {
1297 if (!(message
[i
- 1].m_flag
& MHIDDEN
)) {
1298 if (f
== MDELETED
|| !(message
[i
- 1].m_flag
& MDELETED
))
1299 message
[i
- 1].m_flag
|= MMARK
;
1302 if (message
[i
- 1].m_child
) {
1303 mp
= message
[i
- 1].m_child
;
1304 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1305 for (mp
= mp
->m_younger
; mp
!= NULL
; mp
= mp
->m_younger
)
1306 mark((int)PTR2SIZE(mp
- message
+ 1), f
);
1309 message
[i
- 1].m_flag
|= MMARK
;
1313 /* vim:set fenc=utf-8:s-it-mode */