*** test/courier-0.37.3.orig/imap/storeinfo.c Wed Nov 14 05:14:51 2001 --- courier-0.37.3/imap/storeinfo.c Sun Jul 27 23:11:51 2003 *************** *** 23,28 **** --- 23,29 ---- #include #include #include + #include #if HAVE_UTIME_H #include #endif *************** *** 150,155 **** --- 151,165 ---- int fd2; int rc; + //DAVE: just a few variable declarations + char *extprogram; + char *envvar; + char *syscall; + char *mailboxclean; + int ret; + int idx; + //EVAD + if (fstat(fd, &stat_buf) < 0) { return (-1); *************** *** 234,241 **** --- 244,308 ---- if ((rc=rename(tmpname, newname)) != 0) unlink(tmpname); + //DAVE: call an external program depending on the target mailbox + if( rc == 0 ) { + envvar=(char *)malloc(1024); + syscall=(char *)malloc(1024); + mailboxclean=(char *)malloc(1024); + + // if length of the mailbox string is 1, it is "." == INBOX + if( strlen(mailbox) == 1 ) { + extprogram=getenv("ON_COPY_TO_INBOX"); + strcpy(envvar, "ON_COPY_TO_INBOX"); + } else { + //we want to get the environment variable + //matching the target mailbox. + strcpy(envvar, "ON_COPY_TO_BOX_"); + strncpy(mailboxclean, (char *)(mailbox+1), 1000); + + //we need to convert all special chars to underscores, + //since an environment variable can only handle these + for( idx = 0; (mailboxclean[idx] != 0) && (idx<1000); idx++ ) { + if( ((mailboxclean[idx] < 'A') || + (mailboxclean[idx] > 'Z')) && + ((mailboxclean[idx] < 'a') || + (mailboxclean[idx] > 'z')) ) { + mailboxclean[idx] = '_'; + } + } + + //now get the env. var. + strncat(envvar, mailboxclean, 1000); + extprogram=getenv(envvar); + } + + //if env. var. not specified, get the fallback var. + if( extprogram == NULL ) { + extprogram=getenv("ON_COPY_TO_NOT_LISTED"); + strcpy(envvar, "ON_COPY_TO_NOT_LISTED"); + } + + //run the program in the env. var., but replace the %s + //with the filename first. + if( (extprogram != NULL) && (strlen(extprogram) > 0) ) { + snprintf(syscall, 1000, extprogram, newname); + fprintf(stderr, "INFO: option: %s, calling %s\n", envvar, syscall); + ret=system(syscall); + //we want a syslog if there were errors. + if( ret != 0 ) { + fprintf(stderr, "ERR: calling %s returned error code %d\n", syscall, ret); + } + } + + free(syscall); + free(mailboxclean); + free(envvar); + } + //EVAD + free(tmpname); free(newname); + return (rc); }