/[imapfilter]/imapfilter/request.c
ViewVC logotype

Diff of /imapfilter/request.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.46 by lefcha, Fri Mar 7 14:28:56 2003 UTC revision 1.47 by lefcha, Sat Mar 15 16:05:03 2003 UTC
# Line 137  logout(int *sock) Line 137  logout(int *sock)
137   * Match and apply filters assigned to a mailbox.   * Match and apply filters assigned to a mailbox.
138   */   */
139  int  int
140  apply_filters(filter_t ** filters)  apply_filters(char *mbox, filter_t ** filters)
141  {  {
142          int i;          int i;
143          char *mesgs;          char *mesgs;
# Line 150  apply_filters(filter_t ** filters) Line 150  apply_filters(filter_t ** filters)
150    
151                  log_info(LOG_FILTER, filters[i]->key);                  log_info(LOG_FILTER, filters[i]->key);
152    
153                  apply_action(mesgs, &(filters[i]->action.type),                  apply_action(mbox, mesgs, &(filters[i]->action.type),
154                      filters[i]->action.raccount, filters[i]->action.destmbox,                      filters[i]->action.raccount, filters[i]->action.destmbox,
155                      &filters[i]->action.msgflags, filters[i]->action.args);                      &filters[i]->action.msgflags, filters[i]->action.args);
156    
# Line 383  generate_filter_or(mask_t * mask, unsign Line 383  generate_filter_or(mask_t * mask, unsign
383   * Apply the appropriate action.   * Apply the appropriate action.
384   */   */
385  int  int
386  apply_action(char *mesgs, unsigned int *type, account_t * raccount,  apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * raccount,
387      char *destmbox, unsigned int *msgflags, char *args)      char *destmbox, unsigned int *msgflags, char *args)
388  {  {
389          unsigned int cnt;          unsigned int cnt;
# Line 405  apply_action(char *mesgs, unsigned int * Line 405  apply_action(char *mesgs, unsigned int *
405          case FILTER_ACTION_COPY:          case FILTER_ACTION_COPY:
406                  info("%d message%s copied to mailbox \"%s\".\n", cnt,                  info("%d message%s copied to mailbox \"%s\".\n", cnt,
407                      plural(cnt), destmbox);                      plural(cnt), destmbox);
408                  action_copy(mesgs, apply_namespace(destmbox, nsppri.prefix,                  action_copy(mbox, mesgs, apply_namespace(destmbox,
409                          nsppri.delim), args);                          nsppri.prefix, nsppri.delim), args);
410                  break;                  break;
411          case FILTER_ACTION_MOVE:          case FILTER_ACTION_MOVE:
412                  info("%d message%s moved to mailbox \"%s\".\n", cnt,                  info("%d message%s moved to mailbox \"%s\".\n", cnt,
413                      plural(cnt), destmbox);                      plural(cnt), destmbox);
414                  action_move(mesgs, apply_namespace(destmbox, nsppri.prefix,                  action_move(mbox, mesgs, apply_namespace(destmbox,
415                          nsppri.delim), args);                          nsppri.prefix, nsppri.delim), args);
416                  break;                  break;
417          case FILTER_ACTION_RCOPY:          case FILTER_ACTION_RCOPY:
418                  info("%d message%s copied to mailbox \"%s\" at account %s.\n",                  info("%d message%s copied to mailbox \"%s\" at account %s.\n",
419                      cnt, plural(cnt), destmbox, raccount->key);                      cnt, plural(cnt), destmbox, raccount->key);
420                  action_rcopy(mesgs, raccount, destmbox, args);                  action_rcopy(mbox, mesgs, raccount, destmbox, args);
421                  break;                  break;
422          case FILTER_ACTION_RMOVE:          case FILTER_ACTION_RMOVE:
423                  info("%d message%s moved to mailbox \"%s\" at account %s.\n",                  info("%d message%s moved to mailbox \"%s\" at account %s.\n",
424                      cnt, plural(cnt), destmbox, raccount->key);                      cnt, plural(cnt), destmbox, raccount->key);
425                  action_rmove(mesgs, raccount, destmbox, args);                  action_rmove(mbox, mesgs, raccount, destmbox, args);
426                  break;                  break;
427          case FILTER_ACTION_FLAG_REPLACE:          case FILTER_ACTION_FLAG_REPLACE:
428          case FILTER_ACTION_FLAG_ADD:          case FILTER_ACTION_FLAG_ADD:
# Line 476  action_delete(char *mesgs, char *args) Line 476  action_delete(char *mesgs, char *args)
476   * Copy messages to specified mailbox.   * Copy messages to specified mailbox.
477   */   */
478  int  int
479  action_copy(char *mesgs, char *destmbox, char *args)  action_copy(char *mbox, char *mesgs, char *destmbox, char *args)
480  {  {
481          int r;          int r;
482          char *tok, *mcp, *m;          char *tok, *mcp, *m;
# Line 493  action_copy(char *mesgs, char *destmbox, Line 493  action_copy(char *mesgs, char *destmbox,
493                  m = mcp = convert_messages(mesgs);                  m = mcp = convert_messages(mesgs);
494    
495          xstrncpy(dm[0], destmbox, MBOX_NAME_LEN - 1);          xstrncpy(dm[0], destmbox, MBOX_NAME_LEN - 1);
496            default_variables(mbox, dm[0]);
497          current_date(dm[0]);          current_date(dm[0]);
498          tok = strtok_r(m, " ", &m);          tok = strtok_r(m, " ", &m);
499          while (tok != NULL) {          while (tok != NULL) {
# Line 522  action_copy(char *mesgs, char *destmbox, Line 523  action_copy(char *mesgs, char *destmbox,
523   * Move messages to specified mailbox.   * Move messages to specified mailbox.
524   */   */
525  int  int
526  action_move(char *mesgs, char *destmbox, char *args)  action_move(char *mbox, char *mesgs, char *destmbox, char *args)
527  {  {
528          if (!action_copy(mesgs, destmbox, args))          if (!action_copy(mbox, mesgs, destmbox, args))
529                  action_delete(mesgs, "\0");                  action_delete(mesgs, "\0");
530    
531          return 0;          return 0;
# Line 535  action_move(char *mesgs, char *destmbox, Line 536  action_move(char *mesgs, char *destmbox,
536   * Copy messages to the specified mailbox of another mail server.   * Copy messages to the specified mailbox of another mail server.
537   */   */
538  int  int
539  action_rcopy(char *mesgs, account_t * destacc, char *destmbox, char *args)  action_rcopy(char *mbox, char *mesgs, account_t * destacc, char *destmbox,
540        char *args)
541  {  {
542          int r, ta, tf;          int r, ta, tf;
543          char *tok, *m, *mcp, *ndm;          char *tok, *m, *mcp, *ndm;
# Line 646  action_rcopy(char *mesgs, account_t * de Line 648  action_rcopy(char *mesgs, account_t * de
648   * Move messages to the specified mailbox of another mail server.   * Move messages to the specified mailbox of another mail server.
649   */   */
650  int  int
651  action_rmove(char *mesgs, account_t * destacc, char *destmbox, char *args)  action_rmove(char *mbox, char *mesgs, account_t * destacc, char *destmbox,
652        char *args)
653  {  {
654          if (!action_rcopy(mesgs, destacc, destmbox, args))          if (!action_rcopy(mbox, mesgs, destacc, destmbox, args))
655                  action_delete(mesgs, "\0");                  action_delete(mesgs, "\0");
656    
657          return 0;          return 0;
# Line 866  substitute_date(char *str) Line 869  substitute_date(char *str)
869          }          }
870          *w = '\0';          *w = '\0';
871    
872          free(s);          xfree(s);
873    
874          return n;          return n;
875  }  }
# Line 920  message_date(char *mesg, char *destmbox) Line 923  message_date(char *mesg, char *destmbox)
923              strftime(s, MBOX_NAME_LEN - 1, destmbox, &tl))              strftime(s, MBOX_NAME_LEN - 1, destmbox, &tl))
924                  xstrncpy(destmbox, s, MBOX_NAME_LEN - 1);                  xstrncpy(destmbox, s, MBOX_NAME_LEN - 1);
925  }  }
926    
927    
928    /*
929     * Format the destination mailbox according to "default variables" specifiers.
930     */
931    void
932    default_variables(char *mbox, char *destmbox)
933    {
934            char *m, *r, *w, *s;
935    
936            if (!strchr(destmbox, '$'))
937                    return;
938    
939            s = xstrdup(destmbox);
940    
941            for (r = s, w = destmbox; *r != '\0';) {
942                    if (w - destmbox >= MBOX_NAME_LEN - 1)
943                            break;
944                    if (*r == '$') {
945                            switch (*(r + 1)) {
946                            case '_':
947                                    if (w + strlen(mbox) - destmbox >
948                                        MBOX_NAME_LEN - 1) {
949                                            r += 2;
950                                            break;
951                                    }
952                                    for (m = mbox; *m != '\0'; m++, w++)
953                                            *w = *m;
954                                    r += 2;
955                                    break;
956                            case '$':
957                                    *w++ = '$';
958                                    r += 2;
959                                    break;
960                            default:
961                                    *w++ = *r++;
962                                    break;
963                            }
964                    } else {
965                            *w++ = *r++;
966                    }
967            }
968            *w = '\0';
969    
970            xfree(s);
971    }

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.47

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26