Blame v7.local.c

Packit 272fb1
/*
Packit 272fb1
 * Heirloom mailx - a mail user agent derived from Berkeley Mail.
Packit 272fb1
 *
Packit 272fb1
 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
Packit 272fb1
 */
Packit 272fb1
/*
Packit 272fb1
 * Copyright (c) 1980, 1993
Packit 272fb1
 *	The Regents of the University of California.  All rights reserved.
Packit 272fb1
 *
Packit 272fb1
 * Redistribution and use in source and binary forms, with or without
Packit 272fb1
 * modification, are permitted provided that the following conditions
Packit 272fb1
 * are met:
Packit 272fb1
 * 1. Redistributions of source code must retain the above copyright
Packit 272fb1
 *    notice, this list of conditions and the following disclaimer.
Packit 272fb1
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 272fb1
 *    notice, this list of conditions and the following disclaimer in the
Packit 272fb1
 *    documentation and/or other materials provided with the distribution.
Packit 272fb1
 * 3. All advertising materials mentioning features or use of this software
Packit 272fb1
 *    must display the following acknowledgement:
Packit 272fb1
 *	This product includes software developed by the University of
Packit 272fb1
 *	California, Berkeley and its contributors.
Packit 272fb1
 * 4. Neither the name of the University nor the names of its contributors
Packit 272fb1
 *    may be used to endorse or promote products derived from this software
Packit 272fb1
 *    without specific prior written permission.
Packit 272fb1
 *
Packit 272fb1
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 272fb1
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 272fb1
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 272fb1
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 272fb1
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 272fb1
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 272fb1
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 272fb1
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 272fb1
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 272fb1
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 272fb1
 * SUCH DAMAGE.
Packit 272fb1
 */
Packit 272fb1
Packit 272fb1
#ifndef lint
Packit 272fb1
#ifdef	DOSCCS
Packit 272fb1
static char sccsid[] = "@(#)v7.local.c	2.10 (gritter) 3/4/06";
Packit 272fb1
#endif
Packit 272fb1
#endif /* not lint */
Packit 272fb1
Packit 272fb1
/*
Packit 272fb1
 * Mail -- a mail program
Packit 272fb1
 *
Packit 272fb1
 * Version 7
Packit 272fb1
 *
Packit 272fb1
 * Local routines that are installation dependent.
Packit 272fb1
 */
Packit 272fb1
Packit 272fb1
#include "rcv.h"
Packit 272fb1
#include "extern.h"
Packit 272fb1
#include <sys/stat.h>
Packit 272fb1
#include <fcntl.h>
Packit 272fb1
#include <unistd.h>
Packit 272fb1
Packit 272fb1
/*
Packit 272fb1
 * Locate the user's mailbox file (ie, the place where new, unread
Packit 272fb1
 * mail is queued).
Packit 272fb1
 */
Packit 272fb1
void
Packit 272fb1
findmail(char *user, int force, char *buf, int size)
Packit 272fb1
{
Packit 272fb1
	char *mbox, *cp;
Packit 272fb1
Packit 272fb1
	if (strcmp(user, myname) == 0 && !force &&
Packit 272fb1
			(cp = value("folder")) != NULL &&
Packit 272fb1
			which_protocol(cp) == PROTO_IMAP) {
Packit 272fb1
		snprintf(buf, size, "%s/INBOX", protbase(cp));
Packit 272fb1
	} else if (force || (mbox = value("MAIL")) == NULL) {
Packit 272fb1
		snprintf(buf, size, "%s/%s", MAILSPOOL, user);
Packit 272fb1
	} else {
Packit 272fb1
		strncpy(buf, mbox, size);
Packit 272fb1
		buf[size-1]='\0';
Packit 272fb1
	}
Packit 272fb1
}
Packit 272fb1
Packit 272fb1
/*
Packit 272fb1
 * Get rid of the queued mail.
Packit 272fb1
 */
Packit 272fb1
void 
Packit 272fb1
demail(void)
Packit 272fb1
{
Packit 272fb1
Packit 272fb1
	if (value("keep") != NULL || rm(mailname) < 0)
Packit 272fb1
		close(creat(mailname, 0600));
Packit 272fb1
}
Packit 272fb1
Packit 272fb1
/*
Packit 272fb1
 * Discover user login name.
Packit 272fb1
 */
Packit 272fb1
char *
Packit 272fb1
username(void)
Packit 272fb1
{
Packit 272fb1
	char *np;
Packit 272fb1
	uid_t uid;
Packit 272fb1
Packit 272fb1
	if ((np = getenv("USER")) != NULL)
Packit 272fb1
		return np;
Packit 272fb1
	if ((np = getname(uid = getuid())) != NULL)
Packit 272fb1
		return np;
Packit 272fb1
	printf(catgets(catd, CATSET, 201,
Packit 272fb1
		"Cannot associate a name with uid %d\n"), (int)uid);
Packit 272fb1
	return NULL;
Packit 272fb1
}