home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * MAIN.C
- *
- * $Header: Beta:src/uucp/src/dmail/RCS/main.c,v 1.1 90/02/02 12:03:43 dillon Exp Locker: dillon $
- *
- * (C) Copyright 1985-1990 by Matthew Dillon, All Rights Reserved.
- *
- * Global Routines: MAIN()
- * INIT()
- * SIG_HANDLE()
- *
- * Static Routines: none.
- *
- * 23 Aug 90: Changed sendmail.c for use with my new sendmail prg.
- * Ingo Feulner
- */
-
- #include <pwd.h>
- #include <stdio.h>
- #include <signal.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <config.h>
- #include "version.h"
-
- #include "dmail.h"
-
- IDENT(".04");
- char *dillon_cpr = DCOPYRIGHT;
- static char *version20 = "$VER: dmail 1.05 (23 Aug 90)\n\r";
-
- #define MAILHOME MakeConfigPath(UUMAIL, "")
- #define MBOX MakeConfigPath(UUMAIL, "mbox")
- #define ALT_MBOX MakeConfigPath(UUMAIL, ".mbox")
- #define MAILRC MakeConfigPath(UULIB, ".dmailrc")
- #define VISUAL GetConfig(EDITOR, "dme")
-
- void init();
-
- main(argc, argv)
- char *argv[];
- {
- int i, next, Retry;
- int fop = 0, oop = 0;
- int rcload = 1;
- int options = 1;
- int no_mail_overide = 0;
- int nc = 0;
- static int nameslist[128];
- char *rcname;
-
- if (push_base())
- done (1);
-
- init();
- rcname = malloc (strlen(home_dir) + strlen(MAILRC) + 2);
- #ifdef AMIGA
- rcname[0] = 0;
- #else
- strcpy (rcname, home_dir);
- strcat (rcname, "/");
- #endif
- strcat (rcname, MAILRC);
- for (i = 1; i < argc; ++i) {
- next = 0;
- if ((*argv[i] == '-') && options) {
- if (*(argv[i] + 1) == '\0') {
- options = 0;
- continue;
- }
- while (*++argv[i]) {
- switch (*argv[i]) {
- case 'S':
- lmessage_overide = 1;
- break;
- case 'O':
- no_mail_overide = 1;
- break;
- case 'l':
- rcload = 1;
- if (i + 1 < argc && *argv[i + 1] != '-') {
- xfree (rcname);
- oop = 1;
- ++i;
- ++next;
- rcname = malloc (strlen (argv[i]) + 1);
- strcpy (rcname, argv[i]);
- }
- break;
- case 'L':
- rcload = 0;
- break;
- case 'D':
- XDebug = 1;
- break;
- case 'F':
- if (++i < argc) {
- add_extra (argv[i]);
- } else {
- puts (" -F Requires Field argument");
- exit (1);
- }
- ++next;
- break;
- case 'v':
- set_var (LEVEL_SET, "verbose", "");
- break;
- case 'o':
- xfree (output_file);
- if (i + 1 < argc && *argv[i + 1] != '-') {
- oop = 1;
- ++i;
- ++next;
- output_file = malloc (strlen (argv[i]) + 1);
- strcpy (output_file, argv[i]);
- } else {
- oop = -1;
- output_file = malloc (strlen(home_dir) +
- strlen(ALT_MBOX) + 2);
- #ifdef AMIGA
- strcpy (output_file, ALT_MBOX);
- #else
- sprintf (output_file, "%s/%s", home_dir, ALT_MBOX);
- #endif
- }
- break;
- case 'f':
- if (i + 1 < argc && *argv[i + 1] != '-') {
- fop = 1;
- ++i;
- ++next;
- mail_file = realloc (mail_file, strlen (argv[i]) + 1);
- strcpy (mail_file, argv[i]);
- } else {
- fop = -1;
- mail_file = realloc (mail_file,
- strlen(home_dir) + strlen(MBOX) + 2);
- #ifdef AMIGA
- strcpy (mail_file, MBOX);
- #else
- sprintf (mail_file, "%s/%s", home_dir, MBOX);
- #endif
- }
- break;
- default:
- puts ("dmail: Bad argument");
- puts ("dmail -O then 'help' for help.");
- done (1);
- }
- if (next)
- break;
- }
- } else {
- No_load_mail = 1;
- nameslist[nc++] = i;
- }
- }
- if (oop == -1 && fop == -1) {
- mail_file = realloc (mail_file, strlen(output_file) + 1);
- strcpy (mail_file, output_file);
- }
- ends:
- initial_load_mail();
- m_select (Nulav, M_RESET);
- Current = indexof (1);
- if (nc)
- set_var (LEVEL_SET, "comlinemail", "");
- if (rcload) {
- ac = 2;
- av[1] = rcname;
- do_source(rcname, 1);
- }
- if (nc) {
- av[0] = "mail";
- for (i = 0; i < nc; ++i)
- av[i + 1] = argv[nameslist[i]];
- ac = nc + 1;
- do_reply ("", R_MAIL);
- done (0);
- }
- if (Entries + no_mail_overide == 0) {
- printf ("\nNO MAIL for %s\n\n", user_name);
- return;
- }
- printf ("\nRF %-20s WF %-20s\n", mail_file, output_file);
- do {
- Retry = 20;
- pop_base();
- loop:
- if (push_base()) {
- pop_base();
- if (XDebug)
- printf ("TOP LEVEL INTR, Level: %d\n", Longstack);
- if (--Retry == 0)
- done (1);
- puts ("");
- goto loop;
- }
- check_new_mail();
- } while (do_command() > 0);
-
- return(0);
- }
-
- void
- init()
- {
- char *str;
- struct passwd *passwd;
- extern int sig_handle();
-
- Entry = (struct ENTRY *)malloc (sizeof(*Entry));
- Entry->status = Entry->no = Entry->fpos = 0;
- passwd = getpwuid(getuid());
- if (passwd == NULL) {
- printf("DMail, unable to get passwd entry for uid %d\n", getuid());
- exit(1);
- }
- user_name = malloc (strlen(passwd->pw_name) + 1);
- home_dir = malloc (strlen(passwd->pw_dir) + 1);
- visual = malloc (strlen(VISUAL) + 1);
- strcpy (visual , VISUAL);
- strcpy (user_name, passwd->pw_name);
- strcpy (home_dir , passwd->pw_dir);
- #ifdef AMIGA
- if (str = FindConfig(HOME))
- strcpy ((home_dir = realloc (home_dir, strlen(str) + 1)), str);
- if (str = FindConfig(USERNAME))
- strcpy ((user_name = realloc (user_name, strlen(str) + 1)), str);
- if (str = FindConfig(EDITOR))
- strcpy ((visual = realloc (visual, strlen(str) + 1)), str);
-
- if (str = MallocEnviro("USER"))
- user_name = str;
-
- #else
- if ((str = getenv ("HOME")) != NULL)
- strcpy ((home_dir = realloc (home_dir, strlen(str) + 1)), str);
- if ((str = getenv ("USER")) != NULL)
- strcpy ((user_name = realloc (user_name, strlen(str) + 1)), str);
- if ((str = getenv ("VISUAL")) != NULL)
- strcpy ((visual = realloc (visual, strlen(str) + 1)), str);
- #endif
- mail_file = malloc (strlen(MAILHOME) + strlen(user_name) + 1);
- sprintf (mail_file , "%s%s", MAILHOME, user_name);
- output_file = malloc (strlen(home_dir) + 2 + strlen(MBOX) + 1);
- #ifdef AMIGA
- strcpy(output_file, MBOX);
- #else
- sprintf (output_file, "%s/%s", home_dir, MBOX);
- #endif
- fix_globals();
- #ifdef UNIX
- signal (SIGHUP, sig_handle);
- signal (SIGINT, sig_handle);
- signal (SIGPIPE, SIG_IGN);
- #endif
- #ifdef AMIGA
- signal (SIGINT, sig_handle);
- #endif
- }
-
- sig_handle()
- {
- #ifdef UNIX
- int mask = sigblock (0);
-
- sigsetmask (mask & ~((1 << SIGHUP) | (1 << SIGINT)));
- #endif
- #ifdef AMIGA
- signal (SIGINT, sig_handle); /* reload signal */
- #endif
- if (Longstack && !Breakstack)
- longjmp (env[Longstack], 1);
- return(0);
- }
-
- get_inode(file)
- char *file;
- {
- struct stat stats;
-
- if (stat (file, &stats) < 0)
- return (-1);
- return (stats.st_ino);
- }
-
-