* For mailing lists, Alpine adds a description of the type of link
[alpine.git] / pith / search.c
blob840dc2bf1a053085aff03a2475acddd8cb98db07
1 /*
2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 #include "../pith/headers.h"
16 #include "../pith/search.h"
19 SEARCHSET *
20 build_searchset(MAILSTREAM *stream)
22 long i, run;
23 SEARCHSET *ret_s = NULL, **set;
24 MESSAGECACHE *mc;
26 if(!stream)
27 return(NULL);
29 for(i = 1L, set = &ret_s, run = 0L; i <= stream->nmsgs; i++){
30 if(!((mc = mail_elt(stream, i)) && mc->sequence)){ /* end of run */
31 if(run){ /* run in progress */
32 set = &(*set)->next;
33 run = 0L;
36 else if(run++){ /* next in run */
37 (*set)->last = i;
39 else{ /* start of new run */
40 *set = mail_newsearchset();
42 * Leave off (*set)->last until we get more than one msg
43 * in the run, to avoid 607:607 in SEARCH.
45 (*set)->first = (*set)->last = i;
49 return(ret_s);
53 int
54 in_searchset(SEARCHSET *srch, long unsigned int num)
56 SEARCHSET *s;
57 unsigned long i;
59 if(srch)
60 for(s = srch; s; s = s->next)
61 for(i = s->first; i <= s->last; i++){
62 if(i == num)
63 return 1;
66 return 0;