# /* mail_init.c * * Set up a .mail.init file for the user. The user's init file is * in .mail.init in his home directory; its structure is described * in init_rec.h. */ #include #include "rqfile.h" #include "init_rec.h" struct init_rec newrec = { /* default values */ FALSE, /* no default forwarding */ TRUE, /* blank screen */ FALSE, /* cc-include-me */ TRUE, /* reply-include-me */ ".mail", /* mailbox file */ "mbox", /* saved mail file */ "/bin/teco", /* editor */ FALSE, /* reply-to flag */ "" }; /* reply-to name */ struct passwd { char *pw_name; char *pw_passwd; int pw_uid; int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; }; main () { struct passwd *pwd; /* my password file entry */ char ans; /* answer field */ int infd; /* file descriptor */ pwd = getpwent (); chdir (pwd->pw_dir); if((infd = open (INITFILE, 2)) >= 0) { read (infd, &newrec, sizeof (newrec)); seek (infd, 0, 0); } else if ((infd = creat (INITFILE, 0644)) < 0) { printf ("init file open error\n"); exit (1); } do { /* loop til he gets it right */ printf ("Do you want your mail forwarded somewhere else? (%s) ", (newrec.in_frwrd ? "yes" : "no")); if (gettf (&newrec.in_frwrd)) { for (;;) { printf ("Who do you want your mail forwarded to? (%s) ", newrec.in_mail); getstr (newrec.in_mail); if (strcmp (newrec.in_mail, pwd->pw_name) == 0) printf ("That's illegal; try again\n"); else break; } } else { printf ("What file do you want messages delivered to? (%s) ", newrec.in_mail); getstr (newrec.in_mail); printf ("What file do you want messages saved in? (%s) ", newrec.in_mbox ); getstr (newrec.in_mbox); } printf ("Clear the screen when starting msg? (%s) ", (newrec.in_blkscr ? "yes" : "no")); gettf (&newrec.in_blkscr); printf ("Should cc's include you automatically? (%s) ", (newrec.in_ccme ? "yes" : "no")); gettf (&newrec.in_ccme); printf ("Should replies include you automatically? (%s) ", (newrec.in_repme ? "yes" : "no")); gettf (&newrec.in_repme); printf ("What editor will you use for editing mail? (%s) ", newrec.in_edit ); getstr (newrec.in_edit); printf ("Do you want replies to your mail sent somewhere else? (%s) ", (newrec.in_rflag ? "yes" : "no")); if (gettf (&newrec.in_rflag)) { printf ("Who do you want the replies to go to? (%s) ", newrec.in_repto); getstr (newrec.in_repto); } printf ("Is the above information correct? (yes) "); ans = TRUE; } while (!gettf (&ans)); write (infd, &newrec, sizeof (newrec)); close (infd); } gettf (pval) char *pval; { char line[NAMSIZ]; gets (line); if (line[0] != '\0') { if (strcmp (line, "y") == 0 || strcmp (line, "yes") == 0) *pval = TRUE; else *pval = FALSE; } return (*pval); } getstr (str) char *str; { char line[NAMSIZ]; gets (line); if (line[0] != '\0') strcpy (str, line); return; } getpwent() { register char *p; register c; static struct passwd passwd; static char line[100]; int myuid; myuid = getuid () & 0377; if (getpw (myuid, line)) { printf ("password file read error!\n"); exit (1); } p = line; passwd.pw_name = p; p = pwskip(p); passwd.pw_passwd = p; p = pwskip(p); passwd.pw_uid = atoi(p); p = pwskip(p); passwd.pw_gid = atoi(p); p = pwskip(p); passwd.pw_gecos = p; p = pwskip(p); passwd.pw_dir = p; p = pwskip(p); passwd.pw_shell = p; return(&passwd); } pwskip(ap) char *ap; { register char *p; p = ap; while(*p != ':') { if(*p == 0) return(p); p++; } *p++ = 0; return(p); }