📄 mailblib.c
字号:
{
if (letters[item-1].status == M_DELETED)
continue;
if (
RetrieveLine(letters[item-1].subject, line, LSIZE ) &&
strstr( strlwr(line), token ))
/* This item have subject? */
{
SetItem( item );
hit = TRUE;
} /* if */
} /* for */
if (hit) /* Did we find the string for user? */
{
if ( next_token == NULL )
*input = NULL;
else
strcpy( *input, next_token );
return SetTrailing( input , bits ); /* Yes --> Success */
} /* if (hit) */
else {
printf("No mail items found with subject \"%s\"\n",token);
return FALSE;
} /* else */
} /* SearchSubject */
/*--------------------------------------------------------------------*/
/* S e a r c h U s e r */
/* */
/* Search for a user id on mail items */
/*--------------------------------------------------------------------*/
static boolean SearchUser( char *token , char **input, const int bits)
{
char line[LSIZE];
int item;
boolean hit = FALSE;
token = strlwr(token); /* Case insensitive search */
/*--------------------------------------------------------------------*/
/* Our loop is as follows for each item in the mailbox: */
/* */
/* If the letter is deleted, ignore it */
/* If the From line can be retrieved from the item: */
/* */
/* 1) Read the line */
/* 2) Scan up to the first whitespace */
/* 2a) If there is no whitespace, use entire line */
/* 2b) If there is whitespace, step past it to next */
/* non-whitespace character */
/* 3) Lowercase the line */
/* 4) Scan for the the target address in the line: */
/* 4a) If found select the item for processing */
/* 4b) If not found, build a standard outgoing address */
/* and search again. If found, select the item */
/* */
/* If the From line cannot be retrieved: */
/* 1) call ReturnAddress to format the return address */
/* (Because the line cannot be retrieved, it will */
/* "-- unknown --", the same string displayed by */
/* Headers. */
/* 2) Scan for the the target address in the returned */
/* address */
/* 3) If found, select the item for processing */
/*--------------------------------------------------------------------*/
for ( item = 1; item <= letternum; item++)
{
printmsg(2,"Examining item %d", item);
if (letters[item-1].status == M_DELETED)
continue;
if (RetrieveLine(letters[item - 1].from, line, LSIZE))
{
char *addr = strpbrk(line,WHITESPACE);
if (addr == NULL) /* Whitespace in input line? */
addr = line; /* No --> Use entire line */
else
while(isspace(*addr)) /* Yes --> Skip past first WS */
addr++;
printmsg(2,"SearchUser: Address %d is: %s",item-1,addr);
if ( strstr( strlwr(addr), token )) /* Find address? */
hit = SetItem( item ); /* Yes--> Select item for use */
else { /* No--> Expand & search again*/
char result[MAXADDR];
BuildAddress( result, addr);
/* Get expanded address for user */
printmsg(2,"SearchUser: Formatted address %d is: %s",
item-1,result);
if ( strstr( strlwr(result), token ))
/* This item have correct sender? */
hit = SetItem( item ); /* Yes --> Set it */
else
printmsg(2,"SearchUser: Item %d not selected.",
item-1);
} /* else */
} /* if */
else {
ReturnAddress(line,&letters[item - 1]);
/* Get standard error text for letter */
printmsg(2,"SearchUser: Default address %d is: %s",
item-1,line);
if ( strstr( strlwr(line), token ))
/* This item have correct sender? */
hit = SetItem( item ); /* Yes --> Set it */
} /* else */
} /* for */
/*--------------------------------------------------------------------*/
/* End of loop; determined success and return to caller */
/*--------------------------------------------------------------------*/
if (hit) /* Did we find the string for user? */
return SetTrailing( input , bits ); /* Yes --> Success */
else {
printf("No mail items found from \"%s\"\n",token);
return FALSE;
} /* else */
} /* SearchUser */
/*--------------------------------------------------------------------*/
/* S e t T r a i l i n g */
/* */
/* Determine success of command parse based on trailing operands */
/*--------------------------------------------------------------------*/
boolean SetTrailing( char **input, int bits )
{
/*--------------------------------------------------------------------*/
/* Trim trailing spaces */
/*--------------------------------------------------------------------*/
if (*input != NULL)
{
char *s = *input;
while( isspace(*s))
s++;
if ( *s == '\0' ) /* Anything left in string? */
*input = NULL; /* No --> Flag input as NULL */
else
*input = s; /* Yes --> Point input to next operand */
}
/*--------------------------------------------------------------------*/
/* Trailing address operands? */
/*--------------------------------------------------------------------*/
if (( bits & USER_OP ) || ( *input == NULL ))
return TRUE; /* Let Get_Operand check operands */
/*--------------------------------------------------------------------*/
/* Trailing file name? */
/*--------------------------------------------------------------------*/
if ( bits & FILE_OP )
{
char *token = strtok( *input , WHITESPACE );
token = strtok( NULL , "" );
if ( token == NULL )
return TRUE;
else {
printf("%s: Only one file operand allowed on command\n",
token);
return FALSE;
} /* else */
} /* if */
/*--------------------------------------------------------------------*/
/* No operand allowed; reject it */
/*--------------------------------------------------------------------*/
printf("%s: Unknown operand on command\n", *input);
return FALSE;
} /* SetTrailing */
/*--------------------------------------------------------------------*/
/* S e t I t e m */
/* */
/* Validate and select a single item */
/*--------------------------------------------------------------------*/
boolean SetItem( int item )
{
if ( item_list == NULL )
{
item_list = calloc( letternum, sizeof *item_list);
checkref( item_list );
}
if ((item > 0) && ( item <= letternum ))
{
item_list[ next_item++ ] = item - 1;
return TRUE;
}
else {
printf("Invalid item (%d) selected for processing\n",item);
return FALSE;
} /* else */
} /* SetItem */
/*--------------------------------------------------------------------*/
/* G e t _ O p e r a n d */
/* */
/* Get next operand to process */
/*--------------------------------------------------------------------*/
boolean Get_Operand( int *item,
char **token,
int bits,
boolean first_pass )
{
/*--------------------------------------------------------------------*/
/* Handle no operand */
/*--------------------------------------------------------------------*/
if (bits & NO_OPERANDS)
{
if ( *token == NULL )
return first_pass;
else {
printf("Operands not allowed on this command!\n");
return FALSE;
} /* else */
}
/*--------------------------------------------------------------------*/
/* User operands are like string operands, but required */
/*--------------------------------------------------------------------*/
if ( (bits & USER_OP) && (*token == NULL))
{
printf("Missing addressees for command\n");
return FALSE;
}
/*--------------------------------------------------------------------*/
/* Handle letter operand */
/*--------------------------------------------------------------------*/
if ( bits & LETTER_OP )
{
static size_t subscript;
subscript = first_pass ? 0 : subscript + 1;
if (subscript < next_item)
{
*item = item_list[subscript];
return TRUE;
} /* else */
else {
free( item_list );
item_list = NULL;
return FALSE;
} /* else */
} /* if*/
/*--------------------------------------------------------------------*/
/* Handle string operands */
/*--------------------------------------------------------------------*/
if ( bits & (STRING_OP | USER_OP))
{
char *buf = *token;
if (first_pass &&
(buf != NULL) &&
( buf[ strlen(buf) - 1 ] == '\n'))
buf[ strlen(buf) - 1 ] = '\0';
return first_pass;
}
/*--------------------------------------------------------------------*/
/* Handle tokenized operands */
/*--------------------------------------------------------------------*/
if ( bits & TOKEN_OP )
{
static char *rest = NULL ;
if (first_pass)
rest = *token;
if ((rest == NULL) || (*rest == (char) NULL))
{
*token = NULL;
return first_pass;
} /* if */
*token = strtok( rest , WHITESPACE );
if ( *token == (char) NULL)
{
rest = NULL;
return first_pass;
}
else {
rest = strtok( NULL , "" );
return TRUE;
} /* else */
} /* if */
/*--------------------------------------------------------------------*/
/* Handle integer operands */
/*--------------------------------------------------------------------*/
if ( bits & KEWSHORT_OP)
{
char *p;
if ( (*token == NULL) || ! first_pass )
{
*item = 1;
return first_pass;
}
p = strtok( *token, WHITESPACE );
if (!Numeric( p ))
{
printf("%s: Operand is not numeric\n", p );
return FALSE;
} /* if */
*item = atoi( p );
p = strtok( NULL, WHITESPACE );
if (p != NULL )
{
printf("%s: extra operand not allowed on command\n", p);
return FALSE;
}
return TRUE;
} /* if */
/*--------------------------------------------------------------------*/
/* We cannot handle this command */
/*--------------------------------------------------------------------*/
printf("Unknown processing option = %x, cannot process command\n",
bits);
return FALSE;
} /* Get_Operand */
/*--------------------------------------------------------------------*/
/* P u s h I t e m L i s t */
/* */
/* Save item parsing list */
/*--------------------------------------------------------------------*/
int PushItemList( int **save_list )
{
*save_list = item_list;
item_list = NULL;
return next_item;
} /* PushItemList */
/*--------------------------------------------------------------------*/
/* P o p I t e m L i s t */
/* */
/* Restore parsing information saved by PushItemList */
/*--------------------------------------------------------------------*/
void PopItemList( int *save_list, int save_item )
{
item_list = save_list;
next_item = save_item;
} /* PopItemList */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -