xref: /onnv-gate/usr/src/cmd/mail/add_recip.c (revision 373:5de22f2b7283)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*373Sceastha /*
23*373Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*373Sceastha  * Use is subject to license terms.
25*373Sceastha  */
26*373Sceastha 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate     NAME
340Sstevel@tonic-gate 	add_recip, madd_recip - add recipients to recipient list
350Sstevel@tonic-gate 
360Sstevel@tonic-gate     SYNOPSIS
370Sstevel@tonic-gate 	int add_recip(reciplist *plist, char *name, int checkdups)
38*373Sceastha 	void madd_recip(reciplist *plist, char *name, int checkdups)
390Sstevel@tonic-gate 
400Sstevel@tonic-gate     DESCRIPTION
410Sstevel@tonic-gate 	add_recip() adds the name to the recipient linked list.
420Sstevel@tonic-gate 	If checkdups is set, it first checks to make certain that
430Sstevel@tonic-gate 	the name is not in the list.
440Sstevel@tonic-gate 
450Sstevel@tonic-gate 	madd_recips() is given a list of names separated by white
460Sstevel@tonic-gate 	space. Each name is split off and passed to add_recips.
470Sstevel@tonic-gate */
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #include "mail.h"
500Sstevel@tonic-gate 
51*373Sceastha int
add_recip(reciplist * plist,char * name,int checkdups)52*373Sceastha add_recip(reciplist *plist, char *name, int checkdups)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate 	char		*p;
550Sstevel@tonic-gate 	static char	pn[] = "add_recip";
560Sstevel@tonic-gate 	recip		*r = &plist->recip_list;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	if ((name == (char *)NULL) || (*name == '\0')) {
590Sstevel@tonic-gate 		Tout(pn, "translation to NULL name ignored\n");
600Sstevel@tonic-gate 		return(0);
610Sstevel@tonic-gate 	}
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 	p = name;
640Sstevel@tonic-gate 	while (*p && !isspace(*p)) {
650Sstevel@tonic-gate 		p++;
660Sstevel@tonic-gate 	}
670Sstevel@tonic-gate 	if (*p != '\0') {
680Sstevel@tonic-gate 	    Tout(pn, "'%s' not added due to imbedded spaces\n", name);
690Sstevel@tonic-gate 	    return(0);
700Sstevel@tonic-gate 	}
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	if (checkdups == TRUE) {
730Sstevel@tonic-gate 	    while (r->next != (struct recip *)NULL) {
740Sstevel@tonic-gate 		r = r->next;
750Sstevel@tonic-gate 		if (strcmp(r->name, name) == 0) {
760Sstevel@tonic-gate 			Tout(pn, "duplicate recipient '%s' not added to list\n",
770Sstevel@tonic-gate 									name);
780Sstevel@tonic-gate 			return(0);
790Sstevel@tonic-gate 		}
800Sstevel@tonic-gate 	    }
810Sstevel@tonic-gate 	}
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	if ((p = malloc (sizeof(struct recip))) == (char *)NULL) {
840Sstevel@tonic-gate 		errmsg(E_MEM,"first malloc failed in add_recip()");
850Sstevel@tonic-gate 		done(1);
860Sstevel@tonic-gate 	}
870Sstevel@tonic-gate 	plist->last_recip->next = (struct recip *)p;
880Sstevel@tonic-gate 	r = plist->last_recip = plist->last_recip->next;
890Sstevel@tonic-gate 	if ((r->name = malloc (strlen(name)+1)) == (char *)NULL) {
900Sstevel@tonic-gate 		errmsg(E_MEM,"second malloc failed in add_recip()");
910Sstevel@tonic-gate 		done(1);
920Sstevel@tonic-gate 	}
930Sstevel@tonic-gate 	strcpy (r->name, name);
940Sstevel@tonic-gate 	r->next = (struct recip *)NULL;
950Sstevel@tonic-gate 	Tout(pn, "'%s' added to recipient list\n", name);
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	return(1);
980Sstevel@tonic-gate }
990Sstevel@tonic-gate 
100*373Sceastha void
madd_recip(reciplist * plist,char * namelist,int checkdups)101*373Sceastha madd_recip(reciplist *plist, char *namelist, int checkdups)
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate 	char	*name;
1040Sstevel@tonic-gate 	for (name = strtok(namelist, " \t"); name; name = strtok((char*)0, " \t"))
1050Sstevel@tonic-gate 		add_recip(plist, name, checkdups);
1060Sstevel@tonic-gate }
107