/* * This part was written by Harald Kipp * * Bug reports should be sent to * * harald@os2point.ping.de * harald@sesam.com * Fido: 2:2448/434 * * Purging articles by reading the history file. * */ #include #include #include #include #include #include "config.h" #include "expire.h" /************************************************************************/ /* */ /************************************************************************/ int get_histlist(char *hist_list[], char *list) { int histcount = 0; while(*list) { for (; *list == ' ' || *list == '\t'; list++) ; if (*list == '\0' || *list == '\n') break; if (histcount < 20) hist_list[histcount++] = list; for (; *list && *list != ',' && *list != '\n'; list++) ; if (*list) *list++ = '\0'; } hist_list[histcount] = (char *)NULL; return (histcount); } /************************************************************************/ /* */ /************************************************************************/ int del_history(char *name) { int result = 0; char *path = malloc(_MAX_PATH); strcat(strcpy(path, name), ".pag"); if(unlink(path) == 0) result++; strcat(strcpy(path, name), ".dir"); if(unlink(path) == 0) result++; free(path); return(result); } /************************************************************************/ /* */ /************************************************************************/ int rename_history(char *oldname, char *newname) { int result; char *oldpath = malloc(_MAX_PATH); char *newpath = malloc(_MAX_PATH); strcat(strcpy(oldpath, oldname), ".pag"); strcat(strcpy(newpath, newname), ".pag"); if((result = rename(oldpath, newpath)) != 0) lprintf("Failed renaming %s to %s", oldpath, newpath); else { strcat(strcpy(oldpath, oldname), ".dir"); strcat(strcpy(newpath, newname), ".dir"); if((result = rename(oldpath, newpath)) != 0) { lprintf("Failed renaming %s to %s", oldpath, newpath); strcat(strcpy(oldpath, oldname), ".pag"); strcat(strcpy(newpath, newname), ".pag"); if(rename(newpath, oldpath)) lprintf("Failed re-renaming %s to %s", oldpath, newpath); } } free(oldpath); free(newpath); return(result); } /************************************************************************/ /* */ /************************************************************************/ time_t get_id_expire(FILE *fp, char *msgid) { time_t result = 0; int gotex = 0; int gotid = (msgid == NULL); int max_len = 1024; char *line = malloc(max_len); char *cp; while(fgets(line, max_len, fp)) { if((cp = strchr(line, '\r')) == NULL) cp = strchr(line, '\n'); if(cp) *cp = '\0'; if(*line == '\0') break; if(!gotex && strnicmp(line, "Expires:", strlen("Expires:")) == 0) { result = getdate(line + strlen("Expires:")); if(gotid) break; else gotex = 1; } else if(!gotid && strnicmp(line, "Message-ID:", strlen("Message-ID:")) == 0) { cp = line + strlen("Message-ID:"); while(*cp == ' ' || *cp == '\t') cp++; while(*cp && *cp != ' ' && *cp != '\t') *msgid++ = *cp++; if(gotex) break; else gotid = 1; } } if(msgid) *msgid = '\0'; free(line); return(result); }