- }
-
- if (addr == NULL)
- addr = getusername ();
- if (user == NULL)
- user = (cp = strchr(addr, '.')) ? ++cp : addr;
- if ((pw = getpwnam (user)) == NULL)
- adios (NULL, "no such local user as %s", user);
-
- if (chdir (pw->pw_dir) == -1)
- chdir ("/");
- umask (0077);
-
- if (geteuid() == 0) {
- setgid (pw->pw_gid);
- initgroups (pw->pw_name, pw->pw_gid);
- setuid (pw->pw_uid);
- }
-
- if (info == NULL)
- info = "";
-
- setbuf (stdin, NULL);
-
- /* Record the delivery time */
- if ((now = dlocaltimenow ()) == NULL)
- adios (NULL, "unable to ascertain local time");
- snprintf (ddate, sizeof(ddate), "Delivery-Date: %s\n", dtimenow (0));
-
- /*
- * Copy the message to a temporary file
- */
- if (file) {
- int tempfd;
-
- /* getting message from file */
- if ((tempfd = open (file, O_RDONLY)) == -1)
- adios (file, "unable to open");
- if (debug)
- debug_printf ("retrieving message from file \"%s\"\n", file);
- if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
- adios (NULL, "unable to create temporary file");
- close (tempfd);
- } else {
- /* getting message from stdin */
- if (debug)
- debug_printf ("retrieving message from stdin\n");
- if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
- adios (NULL, "unable to create temporary file");
- }
- if (debug)
- debug_printf ("temporary file=\"%s\"\n", tmpfil);
- else
- unlink (tmpfil);
-
- if (!(fp = fdopen (fd, "r+")))
- adios (NULL, "unable to access temporary file");
-
- /*
- * If no sender given, extract it
- * from envelope information.
- */
- if (sender == NULL)
- get_sender (envelope, &sender);
-
- if (mbox == NULL) {
- snprintf (mailbox, sizeof(mailbox), "%s/%s",
- mmdfldir[0] ? mmdfldir : pw->pw_dir,
- mmdflfil[0] ? mmdflfil : pw->pw_name);
- mbox = mailbox;
- }
- if (home == NULL)
- home = pw->pw_dir;
-
- if (debug) {
- debug_printf ("addr=\"%s\"\n", trim(addr));
- debug_printf ("user=\"%s\"\n", trim(user));
- debug_printf ("info=\"%s\"\n", trim(info));
- debug_printf ("sender=\"%s\"\n", trim(sender));
- debug_printf ("envelope=\"%s\"\n", envelope ? trim(envelope) : "");
- debug_printf ("mbox=\"%s\"\n", trim(mbox));
- debug_printf ("home=\"%s\"\n", trim(home));
- debug_printf ("ddate=\"%s\"\n", trim(ddate));
- debug_printf ("now=%02d:%02d\n\n", now->tw_hour, now->tw_min);
- }
-
- /* deliver the message */
- status = localmail (fd, mdlvr);
-
- done (status != -1 ? RCV_MOK : RCV_MBX);
-}