Ejemplo n.º 1
0
 SEARCHPGM*
 ImapClient::search_criteria(std::vector<std::string> aCriteria) {
   SEARCHPGM *lSearchProgram = NIL;
   
   /* initializing the search program */
   lSearchProgram= mail_newsearchpgm ();
   
   /* Now, we iterate through the whole vector containing the search critera, building our search program */
   for (std::vector<std::string>::iterator lIterator = aCriteria.begin(); lIterator != aCriteria.end(); ++lIterator) {
     if (*lIterator == "ALL") {
       /* do nothing ... */
     } else if (*lIterator == "ANSWERED") {
       lSearchProgram->answered = T;
     } else if (*lIterator == "BCC") {
       char * lNext = getNextStringAsChar(++lIterator); 
       mail_criteria_string (&lSearchProgram->bcc, &lNext);
     } else if (*lIterator == "BEFORE") {
       char* lNext = getNextStringAsChar(++lIterator); 
       mail_criteria_date(&lSearchProgram->before, &lNext);
     } else if (*lIterator == "BODY") {
       char* lNext = getNextStringAsChar(++lIterator); 
       mail_criteria_string(&lSearchProgram->body, &lNext);
     } else if (*lIterator == "CC") {
       char* lNext = getNextStringAsChar(++lIterator); 
       mail_criteria_string(&lSearchProgram->cc, &lNext);
     } else if (*lIterator == "DELETED") {
       lSearchProgram->deleted = T;
     } else if (*lIterator == "DRAFT") {
       lSearchProgram->draft = T;
     } else if (*lIterator == "FLAGGED") {
       lSearchProgram->flagged = T;
     } else if (*lIterator == "FROM") {
       char* lNext = getNextStringAsChar(++lIterator); 
       mail_criteria_string(&lSearchProgram->from, &lNext);
     } else if (*lIterator == "HEADER") {
       char *lHeaderField = getNextStringAsChar(++lIterator);
       char *lHeaderContent = getNextStringAsChar(++lIterator);  
       SEARCHHEADER* lSearchHeader = mail_newsearchheader(lHeaderField, lHeaderContent);
       if (lSearchProgram->header) {
         lSearchProgram->header->next = lSearchHeader;
       } else {
         lSearchProgram->header = lSearchHeader;
       }  
     } else if (*lIterator == "KEYWORD") {
       char * lNext = getNextStringAsChar(++lIterator); 
       mail_criteria_string(&lSearchProgram->keyword, &lNext);
     } else if (*lIterator == "LARGER") {
       lIterator++;
       // get the unsigned long value that should follow the Keyword LARGER
       std::stringstream lLargerValueStream;
       lLargerValueStream << (*lIterator).c_str();
       unsigned long lLargerValue; 
       lLargerValueStream >> lLargerValue;
       lSearchProgram->larger = lLargerValue;
     } else if (*lIterator == "NEW") {
Ejemplo n.º 2
0
int prune_criteria_number (unsigned long *number,char **r)
{
  char *t;
  STRINGLIST *s = NIL;
				/* parse the date and return fn if OK */
  int ret = (mail_criteria_string (&s,r) &&
	     (*number = strtoul ((char *) s->text.data,&t,10)) && !*t) ?
	       T : NIL;
  if (s) mail_free_stringlist (&s);
  return ret;
}
Ejemplo n.º 3
0
SEARCHPGM *prune_criteria (char *criteria)
{
  SEARCHPGM *pgm = NIL;
  char *criterion,*r,tmp[MAILTMPLEN];
  int f;
  if (criteria) {		/* only if criteria defined */
				/* make writeable copy of criteria */
    criteria = cpystr (criteria);
				/* for each criterion */
    for (pgm = mail_newsearchpgm (), criterion = strtok_r (criteria," ",&r);
	 criterion; (criterion = strtok_r (NIL," ",&r))) {
      f = NIL;			/* init then scan the criterion */
      switch (*ucase (criterion)) {
      case 'A':			/* possible ALL, ANSWERED */
	if (!strcmp (criterion+1,"LL")) f = T;
	else if (!strcmp (criterion+1,"NSWERED")) f = pgm->answered = T;
	break;
      case 'B':			/* possible BCC, BEFORE, BODY */
	if (!strcmp (criterion+1,"CC"))
	  f = mail_criteria_string (&pgm->bcc,&r);
	else if (!strcmp (criterion+1,"EFORE"))
	  f = mail_criteria_date (&pgm->before,&r);
	else if (!strcmp (criterion+1,"ODY"))
	  f = mail_criteria_string (&pgm->body,&r);
	break;
      case 'C':			/* possible CC */
	if (!strcmp (criterion+1,"C")) f = mail_criteria_string (&pgm->cc,&r);
	break;
      case 'D':			/* possible DELETED, DRAFT */
	if (!strcmp (criterion+1,"ELETED")) f = pgm->deleted = T;
	else if (!strcmp (criterion+1,"RAFT")) f = pgm->draft = T;
	break;
      case 'F':			/* possible FLAGGED, FROM */
	if (!strcmp (criterion+1,"LAGGED")) f = pgm->flagged = T;
	else if (!strcmp (criterion+1,"ROM"))
	  f = mail_criteria_string (&pgm->from,&r);
	break;
      case 'K':			/* possible KEYWORD */
	if (!strcmp (criterion+1,"EYWORD"))
	  f = mail_criteria_string (&pgm->keyword,&r);
	break;
      case 'L':			/* possible LARGER */
	if (!strcmp (criterion+1,"ARGER"))
	  f = prune_criteria_number (&pgm->larger,&r);

      case 'N':			/* possible NEW */
	if (!strcmp (criterion+1,"EW")) f = pgm->recent = pgm->unseen = T;
	break;
      case 'O':			/* possible OLD, ON */
	if (!strcmp (criterion+1,"LD")) f = pgm->old = T;
	else if (!strcmp (criterion+1,"N"))
	  f = mail_criteria_date (&pgm->on,&r);
	break;
      case 'R':			/* possible RECENT */
	if (!strcmp (criterion+1,"ECENT")) f = pgm->recent = T;
	break;
      case 'S':			/* possible SEEN, SENT*, SINCE, SMALLER,
				   SUBJECT */
	if (!strcmp (criterion+1,"EEN")) f = pgm->seen = T;
	else if (!strncmp (criterion+1,"ENT",3)) {
	  if (!strcmp (criterion+4,"BEFORE"))
	    f = mail_criteria_date (&pgm->sentbefore,&r);
	  else if (!strcmp (criterion+4,"ON"))
	    f = mail_criteria_date (&pgm->senton,&r);
	  else if (!strcmp (criterion+4,"SINCE"))
	    f = mail_criteria_date (&pgm->sentsince,&r);
	}
	else if (!strcmp (criterion+1,"INCE"))
	  f = mail_criteria_date (&pgm->since,&r);
	else if (!strcmp (criterion+1,"MALLER"))
	  f = prune_criteria_number (&pgm->smaller,&r);
	else if (!strcmp (criterion+1,"UBJECT"))
	  f = mail_criteria_string (&pgm->subject,&r);
	break;
      case 'T':			/* possible TEXT, TO */
	if (!strcmp (criterion+1,"EXT"))
	  f = mail_criteria_string (&pgm->text,&r);
	else if (!strcmp (criterion+1,"O"))
	  f = mail_criteria_string (&pgm->to,&r);
	break;
      case 'U':			/* possible UN* */
	if (criterion[1] == 'N') {
	  if (!strcmp (criterion+2,"ANSWERED")) f = pgm->unanswered = T;
	  else if (!strcmp (criterion+2,"DELETED")) f = pgm->undeleted = T;
	  else if (!strcmp (criterion+2,"DRAFT")) f = pgm->undraft = T;
	  else if (!strcmp (criterion+2,"FLAGGED")) f = pgm->unflagged = T;
	  else if (!strcmp (criterion+2,"KEYWORD"))
	    f = mail_criteria_string (&pgm->unkeyword,&r);
	  else if (!strcmp (criterion+2,"SEEN")) f = pgm->unseen = T;
	}
	break;
      default:			/* we will barf below */
	break;
      }

      if (!f) {			/* if can't identify criterion */
	sprintf (tmp,"Unknown search criterion: %.30s",criterion);
	MM_LOG (tmp,ERROR);
	mail_free_searchpgm (&pgm);
	break;
      }
    }
				/* no longer need copy of criteria */
    fs_give ((void **) &criteria);
  }
  return pgm;
}