1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#if !defined(lint) && !defined(DOS)
static char rcsid[] = "$Id: search.c 842 2007-12-04 00:13:55Z hubert@u.washington.edu $";
#endif
/*
* ========================================================================
* Copyright 2006 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* ========================================================================
*/
#include "../pith/headers.h"
#include "../pith/search.h"
SEARCHSET *
build_searchset(MAILSTREAM *stream)
{
long i, run;
SEARCHSET *ret_s = NULL, **set;
MESSAGECACHE *mc;
if(!stream)
return(NULL);
for(i = 1L, set = &ret_s, run = 0L; i <= stream->nmsgs; i++){
if(!((mc = mail_elt(stream, i)) && mc->sequence)){ /* end of run */
if(run){ /* run in progress */
set = &(*set)->next;
run = 0L;
}
}
else if(run++){ /* next in run */
(*set)->last = i;
}
else{ /* start of new run */
*set = mail_newsearchset();
/*
* Leave off (*set)->last until we get more than one msg
* in the run, to avoid 607:607 in SEARCH.
*/
(*set)->first = (*set)->last = i;
}
}
return(ret_s);
}
int
in_searchset(SEARCHSET *srch, long unsigned int num)
{
SEARCHSET *s;
unsigned long i;
if(srch)
for(s = srch; s; s = s->next)
for(i = s->first; i <= s->last; i++){
if(i == num)
return 1;
}
return 0;
}
|