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

Diff of /imapfilter/request.c

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

revision 1.17 by lefcha, Sat Nov 10 15:34:48 2001 UTC revision 1.17.2.3 by lefcha, Mon Jan 21 15:43:42 2002 UTC
# Line 9  Line 9 
9    
10    
11  extern unsigned int options;  extern unsigned int options;
12    extern unsigned int capabilities;
13    
14    static struct namespace_t namesp;
15    
16    
17  #ifdef DEBUG  #ifdef DEBUG
# Line 27  int test(void) Line 30  int test(void)
30   */   */
31  int check_capabilities(void)  int check_capabilities(void)
32  {  {
33        capabilities = CAPABILITY_NONE;
34    
35      return capability_response(imap_capability());      return capability_response(imap_capability());
36  }  }
37    
38    
39  /*  /*
40     * Get namespace of mail server's mailboxes.
41     */
42    int check_namespace(void)
43    {
44        namesp.prefix[0] = namesp.delim = 0;
45    
46        if (!(options & OPTION_NAMESPACE) ||
47            !(capabilities & CAPABILITY_NAMESPACE))
48            return 0;
49        else
50            return namespace_response(imap_namespace(), &namesp);
51    }
52    
53    
54    /*
55   * Login to server.   * Login to server.
56   */   */
57  int login(char *user, char *pass)  int login(char *user, char *pass)
# Line 41  int login(char *user, char *pass) Line 61  int login(char *user, char *pass)
61      return server_response(imap_login(user, pass));      return server_response(imap_login(user, pass));
62  }  }
63    
64    
65  /*  /*
66   * Open mailbox in read-write mode.   * Open mailbox in read-write mode.
67   */   */
# Line 52  int select_mailbox(char *mbox) Line 73  int select_mailbox(char *mbox)
73          return -2;              /* No messages exist. No filters need to          return -2;              /* No messages exist. No filters need to
74                                     be applied. */                                     be applied. */
75    
76      r = select_response(imap_select(mbox));      r = select_response(imap_select(apply_namespace(mbox, namesp.prefix,
77                                                        namesp.delim)));
78    
79      log_info(LOG_MAILBOX, mbox);      log_info(LOG_MAILBOX, mbox);
80    
# Line 65  int select_mailbox(char *mbox) Line 87  int select_mailbox(char *mbox)
87   */   */
88  int mailbox_status(char *mbox)  int mailbox_status(char *mbox)
89  {  {
90      return status_response(imap_status(mbox, "MESSAGES RECENT UNSEEN"), mbox);      return status_response(imap_status(apply_namespace(mbox, namesp.prefix,
91                                                           namesp.delim),
92                                           "MESSAGES RECENT UNSEEN"), mbox);
93    
94  }  }
95    
96    
# Line 104  int apply_filters(filter_t ** filters) Line 129  int apply_filters(filter_t ** filters)
129          log_info(LOG_FILTER, filters[i]->key);          log_info(LOG_FILTER, filters[i]->key);
130    
131          apply_action(mesgs, &(filters[i]->action.type),          apply_action(mesgs, &(filters[i]->action.type),
132                     filters[i]->action.destmbox, filters[i]->action.args);                       filters[i]->action.destmbox, filters[i]->action.args);
133    
134          free(mesgs);          free(mesgs);
135      }      }
# Line 340  int apply_action(char *mesgs, unsigned i Line 365  int apply_action(char *mesgs, unsigned i
365          action_delete(mesgs, args);          action_delete(mesgs, args);
366          break;          break;
367      case FILTER_ACTION_COPY:      case FILTER_ACTION_COPY:
368          info("%d message%s copied to mailbox %s.\n", cnt, plural(cnt),          info("%d message%s copied to mailbox \"%s\".\n", cnt, plural(cnt),
369               destmbox);               destmbox);
370          action_copy(mesgs, destmbox, args);          action_copy(mesgs, apply_namespace(destmbox, namesp.prefix,
371                                               namesp.delim), args);
372          break;          break;
373      case FILTER_ACTION_MOVE:      case FILTER_ACTION_MOVE:
374          info("%d message%s moved to mailbox %s.\n", cnt, plural(cnt),          info("%d message%s moved to mailbox \"%s\".\n", cnt, plural(cnt),
375               destmbox);               destmbox);
376          action_move(mesgs, destmbox, args);          action_move(mesgs, apply_namespace(destmbox, namesp.prefix,
377                                               namesp.delim), args);
378          break;          break;
379      case FILTER_ACTION_LIST:      case FILTER_ACTION_LIST:
380          info("%d message%s listed.\n", cnt, plural(cnt));          info("%d message%s listed.\n", cnt, plural(cnt));
# Line 398  int action_delete(char *mesgs, char *arg Line 425  int action_delete(char *mesgs, char *arg
425   */   */
426  int action_copy(char *mesgs, char *destmbox, char *args)  int action_copy(char *mesgs, char *destmbox, char *args)
427  {  {
428        int r = 0;
429      const char *delim = " ";      const char *delim = " ";
430      char *tok, *mcp, *m, *acp = NULL, *occur;      char *tok, *mcp, *m, *acp = NULL, *occur;
431    
# Line 413  int action_copy(char *mesgs, char *destm Line 441  int action_copy(char *mesgs, char *destm
441          if (*args)          if (*args)
442              fetch_response(imap_fetch(tok, acp, 0));              fetch_response(imap_fetch(tok, acp, 0));
443    
444          if (copy_response(imap_copy(tok, destmbox)) == RESPONSE_TRYCREATE)          if ((r = copy_response(imap_copy(tok, destmbox))) == RESPONSE_TRYCREATE)
445              if (!server_response(imap_create(destmbox)))              if (!server_response(imap_create(destmbox)))
446                  copy_response(imap_copy(tok, destmbox));                  r = copy_response(imap_copy(tok, destmbox));
447      }      }
448    
449      free(mcp);      free(mcp);
# Line 423  int action_copy(char *mesgs, char *destm Line 451  int action_copy(char *mesgs, char *destm
451      if (*args)      if (*args)
452          free(acp);          free(acp);
453    
454      return 0;      return r;
455  }  }
456    
457    
# Line 432  int action_copy(char *mesgs, char *destm Line 460  int action_copy(char *mesgs, char *destm
460   */   */
461  int action_move(char *mesgs, char *destmbox, char *args)  int action_move(char *mesgs, char *destmbox, char *args)
462  {  {
463      action_copy(mesgs, destmbox, args);      if (!action_copy(mesgs, destmbox, args))
464      action_delete(mesgs, "\0");          action_delete(mesgs, "\0");
465    
466      /* CLOSE -> SELECT much faster than EXPUNGE -> SELECT */      /* CLOSE -> SELECT much faster than EXPUNGE -> SELECT */
467      /* server_response(imap_expunge()); */      /* server_response(imap_expunge()); */

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.17.2.3

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26