This is pop_bull.c in view mode; [Download] [Up]
/* * bullcopy * */ #include <stdio.h> #include <pwd.h> #if defined(PYRAMID) || defined(NEXT) #include <sys/types.h> #include <sys/dir.h> #else #include <dirent.h> #endif #include <ctype.h> #include "popper.h" /* * pop_bull: Append any new bulletins to the end of the user's * temporary maildrop. */ pop_bull (p, pwp) POP *p; struct passwd *pwp; { char popBullName[256]; FILE *popBull; DIR *dirp; #if defined(PYRAMID) || defined(NEXT) struct direct *dp; #else struct dirent *dp; #endif long maxBullNumber = 0; long bullNumber; long lastBullSent; char buffer[MAXMSGLINELEN]; /* Construct full path name of .popbull file. */ sprintf(popBullName, "%s/.popbull", pwp->pw_dir); /* Scan bulletin directory and compute the maximum current bulletin number. */ dirp = opendir(p->bulldir); if (dirp == NULL) { pop_log(p, POP_PRIORITY, "Unable to open bulletin directory."); return POP_FAILURE; } while ((dp = readdir(dirp)) != NULL) { if (!isdigit(*dp->d_name)) continue; bullNumber = atol(dp->d_name); if (bullNumber > maxBullNumber) maxBullNumber = bullNumber; } closedir(dirp); /* Open the user's .popbull file and read the number of the last bulletin sent to this user. If the file doesn't exist, create it and seed it with the current max bulletin number. Note that new users do not get sent old bulletins. */ popBull = fopen(popBullName, "r"); if (popBull == NULL) { popBull = fopen(popBullName, "w"); if (popBull == NULL) { pop_log(p, POP_PRIORITY, "Unable to create .popbull file"); return POP_FAILURE; } fprintf(popBull, "%ld\n", maxBullNumber); fclose(popBull); return POP_SUCCESS; } else { if (fgets(buffer, MAXMSGLINELEN, popBull) == NULL || !isdigit(*buffer)) { fclose(popBull); return POP_SUCCESS; } lastBullSent = atol(buffer); fclose(popBull); } /* If there aren't any new bulletins for this user, return. */ if (lastBullSent >= maxBullNumber) return POP_SUCCESS; /* Append the new bulletins to the end of the user's temporary mail drop. */ dirp = opendir(p->bulldir); if (dirp == NULL) { pop_log(p, POP_PRIORITY, "Unable to open bulletin direcotry."); return POP_FAILURE; } while ((dp = readdir(dirp)) != NULL) { if (!isdigit(*dp->d_name)) continue; bullNumber = atol(dp->d_name); if (bullNumber > lastBullSent) CopyOneBull(dp->d_name, p); } closedir(dirp); /* Update the user's .popbull file. */ popBull = fopen(popBullName, "w"); if (popBull == NULL) { pop_log(p, POP_PRIORITY, "Unable to open .popbull file."); return POP_FAILURE; } fprintf(popBull, "%ld\n", maxBullNumber); fclose(popBull); return POP_SUCCESS; } /* * CopyOneBull: Append a single bulletin file to the end of the * temporary maildrop file. */ CopyOneBull(name, p) char *name; POP *p; { FILE *bull; char buffer[MAXMSGLINELEN]; int doing_body = 0; int first_line = 1; char bullName[256]; sprintf(bullName, "%s/%s", p->bulldir, name); bull = fopen(bullName, "r"); if (bull == NULL) { pop_log(p, POP_PRIORITY, "Unable to open bulletin file %s", name); return POP_FAILURE; } while (fgets(buffer, MAXMSGLINELEN, bull) != NULL) { if (first_line == 1 && strncasecmp(buffer, "From ", 5) != 0) { pop_log(p, POP_PRIORITY, "Bulletin %s does not start with \"From \"", name); fclose(bull); return POP_FAILURE; } first_line = 0; if (doing_body == 0) { /* Header */ if (strncasecmp(buffer, "To:", 3) == 0) { fprintf(p->drop, "To: %s@%s\n", p->user, p->myhost); continue; } if (strncasecmp(buffer, "Status:", 7) == 0) { continue; } if (*buffer == '\n') doing_body == 1; } fputs(buffer, p->drop); } fclose(bull); return POP_SUCCESS; }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.