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

Diff of /imapfilter/request.c

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

revision 1.43 by lefcha, Sun Feb 23 00:16:02 2003 UTC revision 1.44 by lefcha, Thu Mar 6 15:00:46 2003 UTC
# Line 480  action_copy(char *mesgs, char *destmbox, Line 480  action_copy(char *mesgs, char *destmbox,
480  {  {
481          int r;          int r;
482          char *tok, *mcp, *m;          char *tok, *mcp, *m;
483            char dm[MBOX_NAME_LEN];
484    
485          r = 0;          r = 0;
486          tok = NULL;          tok = NULL;
487    
488          action_list(mesgs, args);          action_list(mesgs, args);
489    
490          m = mcp = convert_messages(mesgs);          if (strchr(destmbox, '@'))
491                    m = mcp = xstrdup(mesgs);
492            else
493                    m = mcp = convert_messages(mesgs);
494    
495          tok = strtok_r(m, " ", &m);          tok = strtok_r(m, " ", &m);
496          while (tok != NULL) {          while (tok != NULL) {
497                    xstrncpy(dm, destmbox, MBOX_NAME_LEN - 1);
498                    current_date(dm);
499                    message_date(tok, dm);
500    
501                  if ((r = copy_response(&sockpri, imap_copy(&sockpri, tok,                  if ((r = copy_response(&sockpri, imap_copy(&sockpri, tok,
502                                  destmbox))) == RESPONSE_TRYCREATE)                                  dm))) == RESPONSE_TRYCREATE)
503                          if (!server_response(&sockpri, imap_create(&sockpri,                          if (!server_response(&sockpri, imap_create(&sockpri,
504                                      destmbox))) {                                      dm))) {
505                                  if ((options & OPTION_SUBSCRIBE))                                  if ((options & OPTION_SUBSCRIBE))
506                                          server_response(&sockpri,                                          server_response(&sockpri,
507                                              imap_subscribe(&sockpri, destmbox));                                              imap_subscribe(&sockpri, dm));
508                                  r = copy_response(&sockpri,                                  r = copy_response(&sockpri,
509                                      imap_copy(&sockpri, tok, destmbox));                                      imap_copy(&sockpri, tok, dm));
510                          }                          }
511                  tok = strtok_r(NULL, " ", &m);                  tok = strtok_r(NULL, " ", &m);
512          }          }
# Line 811  convert_messages(char *mesgs) Line 819  convert_messages(char *mesgs)
819    
820          return cp;          return cp;
821  }  }
822    
823    
824    /*
825     * Substitute all occurences of the '@' character with the '%' character,
826     * and any double '@' characters with a signle '@' character, returning the
827     * number of replacements.
828     */
829    int
830    substitute_date(char *str)
831    {
832            int n;
833            char *r, *w, *s;
834    
835            n = 0;
836    
837            s = xstrdup(str);
838    
839            for (r = s, w = str; *r != '\0'; r++, w++) {
840                    if (*r == '%') {
841                            *w++ = '%';
842                            *w = '%';
843                    } else if (*r == '@') {
844                            if (*(r + 1) == '@') {
845                                    *w = *r++;
846                            } else {
847                                    *w = '%';
848                                    n++;
849                            }
850                    } else {
851                            *w = *r;
852                    }
853            }
854            *w = '\0';
855    
856            free(s);
857    
858            return n;
859    }
860    
861    
862    /*
863     * Format the destination mailbox according to the current date conversion
864     * specifiers.
865     */
866    void
867    current_date(char *destmbox)
868    {
869            char s[MBOX_NAME_LEN];
870            time_t te;
871            struct tm *tl;
872    
873            if (!strchr(destmbox, '%'))
874                    return;
875    
876            te = time(NULL);
877            tl = localtime(&te);
878    
879            if (strftime(s, MBOX_NAME_LEN - 1, destmbox, tl))
880                    xstrncpy(destmbox, s, MBOX_NAME_LEN - 1);
881    }
882    
883    
884    /*
885     * Format the destination mailbox according to the message date conversion
886     * specifiers.
887     */
888    void
889    message_date(char *mesg, char *destmbox)
890    {
891            unsigned int t;
892            char s[MBOX_NAME_LEN];
893            struct tm tl;
894            char dbuf[RESPONSE_BUF];
895    
896            if (!strchr(destmbox, '@'))
897                    return;
898    
899            substitute_date(destmbox);
900    
901            fetch_response(&sockpri, 0, 1, NULL);
902            t = imap_fetch(&sockpri, mesg, "BODY.PEEK[HEADER.FIELDS (DATE)]");
903    
904            while (fetch_response(&sockpri, t, 0, dbuf) == RESPONSE_NONE);
905    
906            if (strptime(dbuf, "Date: %a, %d %b %Y %H:%M:%S %z", &tl) &&
907                strftime(s, MBOX_NAME_LEN - 1, destmbox, &tl))
908                    xstrncpy(destmbox, s, MBOX_NAME_LEN - 1);
909    }

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.44

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26