[Hula-dev] Imap search fixes.
Daniel James
daniel at calamity.org.uk
Sat Mar 19 05:22:41 MST 2005
I've attached a patch to fix some problems with the imap search command.
It contains a few changes, I could break it up if that would be better.
To start with the simplest change, imsearch.c contains:
/* Fixme - Shouldn't the response be different for UID Search? */
RFC 3501 says:
> 7.2.5. SEARCH Response
>
> Contents: zero or more numbers
>
> The SEARCH response occurs as a result of a SEARCH or UID SEARCH
> command. The number(s) refer to those messages that match the
> search criteria. For SEARCH, these are message sequence numbers;
> for UID SEARCH, these are unique identifiers. Each number is
> delimited by a space.
>
> Example: S: * SEARCH 2 3 6
So, the answer is no and I removed the comment.
Next up, astring was failing for several valid astrings, for example,
searching for a number. So I changed it to accept them. It still doesn't
work for all valid astrings, to do so would require using a different
function for parsing astrings to other token types. I also don't like
the way it silently ignores errors. I think that the IMAP parser
requires a lot of work.
While I was doing this, I removed header_fld_name(), since astring() now
deals with the cases it copes with.
There are also some changes to the nmap search code. First I've fixed
some of the code for dealing with parameters that are too large for the
buffers.
Also, the code currently only allows alphanumeric characters and '_' in
the search parameters. This breaks for a search command like:
1 SEARCH (HEADER X-List-Id ???)
Since - is a valid atom character. Imapd could be changed to convert
atoms like that into strings, but it seemed simpler just to change nmapd
to allow other characters in search parameters. I couldn't see anything
in the NMAP specification to suggest it was wrong to do that.
Daniel
-------------- next part --------------
Index: src/agents/imap/imsearch.c
===================================================================
--- src/agents/imap/imsearch.c (revision 126)
+++ src/agents/imap/imsearch.c (working copy)
@@ -81,7 +81,6 @@
BITVECTOR *set( IMAPSEARCH *Search, BITVECTOR *bv);
BITVECTOR *sequence_num( IMAPSEARCH *Search, BITVECTOR *bv);
void astring( IMAPSEARCH *Search);
-void header_fld_name( IMAPSEARCH *Search);
void number( IMAPSEARCH *Search);
void date( IMAPSEARCH *Search);
void InSymbol( IMAPSEARCH *Search);
@@ -210,10 +209,6 @@
/*int msg, len; */
BITVECTOR *bv = 0;
- if (ByUID) {
- /* Fixme - Shouldn't the response be different for UID Search? */
- }
-
/*---------------------------- */
/* is a charset parameter of other than us-ascii being used */
if (XplStrNCaseCmp(Client->Command + 6, " charset ", 9) == 0) {
@@ -717,11 +712,11 @@
astring( Search);
return ImapSearchQuery( Search);
- case HEADERsy: /* "HEADER" SPACE header_fld_name SPACE astring */
+ case HEADERsy: /* "HEADER" SPACE astring SPACE astring */
Emit( Search, string, "HDR");
InSymbol( Search);
TestTerminal( Search, spacesy);
- header_fld_name( Search);
+ astring( Search);
TestTerminal( Search, spacesy);
astring( Search);
return ImapSearchQuery( Search);
@@ -892,52 +887,59 @@
------------------------------------------------------------------------------*/
void astring( IMAPSEARCH *Search)
{
- switch( Search->sy)
- {
- case atomsy:
- case stringsy:
- Emit( Search, ident, 0);
- InSymbol( Search);
- break;
- default: // should not happen
- break;
-
- }
+ switch( Search->sy)
+ {
+ case UIDsy:
+ case SEARCHsy:
+ case CHARSETsy:
+ case BODYsy:
+ case TEXTsy:
+ case TOsy:
+ case FROMsy:
+ case SUBJECTsy:
+ case CCsy:
+ case BCCsy:
+ case HEADERsy:
+ case NEWsy:
+ case OLDsy:
+ case RECENTsy:
+ case ANSWEREDsy:
+ case UNANSWEREDsy:
+ case DELETEDsy:
+ case UNDELETEDsy:
+ case DRAFTsy:
+ case UNDRAFTsy:
+ case FLAGGEDsy:
+ case UNFLAGGEDsy:
+ case SEENsy:
+ case UNSEENsy:
+ case KEYWORDsy:
+ case UNKEYWORDsy:
+ case LARGERsy:
+ case SMALLERsy:
+ case NOTsy:
+ case ORsy:
+ case BEFOREsy:
+ case ONsy:
+ case SINCEsy:
+ case SENTBEFOREsy:
+ case SENTONsy:
+ case SENTSINCEsy:
+ case ALLsy:
+ case nz_numbersy:
+ case atomsy:
+ case stringsy:
+ case numbersy:
+ Emit( Search, ident, 0);
+ InSymbol( Search);
+ break;
+ default: // should not happen
+ break;
+ }
}
/*----------------------------------------------------------------------------
-;header_fld_name
-Title:
-Globals:
-Return:
-Descrip: this is a specialization of TestTerminal
- header_fld_name ::= astring
- similar to astring except that here all headers are valid
-
-------------------------------------------------------------------------------*/
-void header_fld_name( IMAPSEARCH *Search)
-{
- switch( Search->sy)
- {
- case atomsy:
- case stringsy:
- case TOsy:
- case FROMsy:
- case SUBJECTsy:
- case CCsy:
- case BCCsy:
- Emit( Search, ident, 0);
- InSymbol( Search);
- break;
- default: // should not happen
- break;
-
- }
-}
-
-
-/*----------------------------------------------------------------------------
;date
Title:
Globals:
Index: src/agents/nmap/search.c
===================================================================
--- src/agents/nmap/search.c (revision 126)
+++ src/agents/nmap/search.c (working copy)
@@ -88,7 +88,7 @@
int offsetIn; /* current offset of bufferIn (Command) */
int identStart; /* identifier offset start */
int identLen; /* identifier length */
- unsigned char ident[ IDENTSIZE+2]; /* current identifier */
+ unsigned char ident[ IDENTSIZE+1]; /* current identifier */
unsigned char *Command; /* short cut to Client->Command */
void *Client; /* JIC baggage */
MessageInfoStruct *MsgInfo;
@@ -336,8 +336,8 @@
unsigned long flag;
long date, size;
SYMBOL sentReceived, beforeOnSince, smallerEqualLarger, headerBodyText;
- char fieldString[ IDENTSIZE];
- char searchString[ IDENTSIZE];
+ char fieldString[ IDENTSIZE+1];
+ char searchString[ IDENTSIZE+1];
switch( Search->sy)
{
@@ -682,7 +682,7 @@
{
char Path[XPL_MAX_PATH+1];
char Answer[CONN_BUFSIZE+1];
- char newSearchString[ IDENTSIZE+2]; /* add 2 for the quotes we add */
+ char newSearchString[ IDENTSIZE+3]; /* add 2 for the quotes we add + 1 for null terminator */
unsigned long msg;
long EndPos, CurPos;
char *pColon;
@@ -908,6 +908,7 @@
digit ::= "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
------------------------------------------------------------------------------*/
+
static void
InSymbol( NMAPSEARCH *Search)
{
@@ -965,7 +966,7 @@
Search->ident[i] = 0;
Search->identLen = i;
} else {
- Search->ident[IDENTSIZE+1] = 0;
+ Search->ident[IDENTSIZE] = 0;
Search->identLen = IDENTSIZE;
}
@@ -975,7 +976,7 @@
default:
i = 0;
- if (isalnum(lch) || ('_' == lch)) {
+ if (Search->ch != ' ' && Search->ch != 0) {
Search->ident[i] = lch;
i++;
} else {
@@ -983,8 +984,7 @@
break;
}
- /* while it is letter or underscore */
- while( isalnum( Search->ch) || ('_' == Search->ch)) {
+ while (Search->ch != ' ' && Search->ch != 0) {
if( i < IDENTSIZE) {
Search->ident[i] = Search->ch;
i++;
@@ -996,8 +996,8 @@
if( i < IDENTSIZE) {
Search->ident[i] = 0;
Search->identLen = i;
- } else {
- Search->ident[IDENTSIZE+1] = 0;
+ } else {
+ Search->ident[IDENTSIZE] = 0;
Search->identLen = IDENTSIZE;
}
More information about the Hula-dev
mailing list