xref: /illumos-gate/usr/src/cmd/mail/add_recip.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*b7d62af5Sceastha /*
23*b7d62af5Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*b7d62af5Sceastha  * Use is subject to license terms.
25*b7d62af5Sceastha  */
26*b7d62af5Sceastha 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate     NAME
327c478bd9Sstevel@tonic-gate 	add_recip, madd_recip - add recipients to recipient list
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate     SYNOPSIS
357c478bd9Sstevel@tonic-gate 	int add_recip(reciplist *plist, char *name, int checkdups)
36*b7d62af5Sceastha 	void madd_recip(reciplist *plist, char *name, int checkdups)
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate     DESCRIPTION
397c478bd9Sstevel@tonic-gate 	add_recip() adds the name to the recipient linked list.
407c478bd9Sstevel@tonic-gate 	If checkdups is set, it first checks to make certain that
417c478bd9Sstevel@tonic-gate 	the name is not in the list.
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate 	madd_recips() is given a list of names separated by white
447c478bd9Sstevel@tonic-gate 	space. Each name is split off and passed to add_recips.
457c478bd9Sstevel@tonic-gate */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #include "mail.h"
487c478bd9Sstevel@tonic-gate 
49*b7d62af5Sceastha int
add_recip(reciplist * plist,char * name,int checkdups)50*b7d62af5Sceastha add_recip(reciplist *plist, char *name, int checkdups)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	char		*p;
537c478bd9Sstevel@tonic-gate 	static char	pn[] = "add_recip";
547c478bd9Sstevel@tonic-gate 	recip		*r = &plist->recip_list;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 	if ((name == (char *)NULL) || (*name == '\0')) {
577c478bd9Sstevel@tonic-gate 		Tout(pn, "translation to NULL name ignored\n");
587c478bd9Sstevel@tonic-gate 		return(0);
597c478bd9Sstevel@tonic-gate 	}
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	p = name;
627c478bd9Sstevel@tonic-gate 	while (*p && !isspace(*p)) {
637c478bd9Sstevel@tonic-gate 		p++;
647c478bd9Sstevel@tonic-gate 	}
657c478bd9Sstevel@tonic-gate 	if (*p != '\0') {
667c478bd9Sstevel@tonic-gate 	    Tout(pn, "'%s' not added due to imbedded spaces\n", name);
677c478bd9Sstevel@tonic-gate 	    return(0);
687c478bd9Sstevel@tonic-gate 	}
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	if (checkdups == TRUE) {
717c478bd9Sstevel@tonic-gate 	    while (r->next != (struct recip *)NULL) {
727c478bd9Sstevel@tonic-gate 		r = r->next;
737c478bd9Sstevel@tonic-gate 		if (strcmp(r->name, name) == 0) {
747c478bd9Sstevel@tonic-gate 			Tout(pn, "duplicate recipient '%s' not added to list\n",
757c478bd9Sstevel@tonic-gate 									name);
767c478bd9Sstevel@tonic-gate 			return(0);
777c478bd9Sstevel@tonic-gate 		}
787c478bd9Sstevel@tonic-gate 	    }
797c478bd9Sstevel@tonic-gate 	}
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	if ((p = malloc (sizeof(struct recip))) == (char *)NULL) {
827c478bd9Sstevel@tonic-gate 		errmsg(E_MEM,"first malloc failed in add_recip()");
837c478bd9Sstevel@tonic-gate 		done(1);
847c478bd9Sstevel@tonic-gate 	}
857c478bd9Sstevel@tonic-gate 	plist->last_recip->next = (struct recip *)p;
867c478bd9Sstevel@tonic-gate 	r = plist->last_recip = plist->last_recip->next;
877c478bd9Sstevel@tonic-gate 	if ((r->name = malloc (strlen(name)+1)) == (char *)NULL) {
887c478bd9Sstevel@tonic-gate 		errmsg(E_MEM,"second malloc failed in add_recip()");
897c478bd9Sstevel@tonic-gate 		done(1);
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 	strcpy (r->name, name);
927c478bd9Sstevel@tonic-gate 	r->next = (struct recip *)NULL;
937c478bd9Sstevel@tonic-gate 	Tout(pn, "'%s' added to recipient list\n", name);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	return(1);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate 
98*b7d62af5Sceastha void
madd_recip(reciplist * plist,char * namelist,int checkdups)99*b7d62af5Sceastha madd_recip(reciplist *plist, char *namelist, int checkdups)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	char	*name;
1027c478bd9Sstevel@tonic-gate 	for (name = strtok(namelist, " \t"); name; name = strtok((char*)0, " \t"))
1037c478bd9Sstevel@tonic-gate 		add_recip(plist, name, checkdups);
1047c478bd9Sstevel@tonic-gate }
105