xref: /illumos-gate/usr/src/cmd/mail/add_recip.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 	 	/* SVr4.0 1.5	*/
28 /*
29     NAME
30 	add_recip, madd_recip - add recipients to recipient list
31 
32     SYNOPSIS
33 	int add_recip(reciplist *plist, char *name, int checkdups)
34 	int madd_recip(reciplist *plist, char *name, int checkdups)
35 
36     DESCRIPTION
37 	add_recip() adds the name to the recipient linked list.
38 	If checkdups is set, it first checks to make certain that
39 	the name is not in the list.
40 
41 	madd_recips() is given a list of names separated by white
42 	space. Each name is split off and passed to add_recips.
43 */
44 
45 #include "mail.h"
46 
47 add_recip (plist, name, checkdups)
48 reciplist	*plist;
49 char		*name;
50 int		checkdups;
51 {
52 	char		*p;
53 	static char	pn[] = "add_recip";
54 	recip		*r = &plist->recip_list;
55 
56 	if ((name == (char *)NULL) || (*name == '\0')) {
57 		Tout(pn, "translation to NULL name ignored\n");
58 		return(0);
59 	}
60 
61 	p = name;
62 	while (*p && !isspace(*p)) {
63 		p++;
64 	}
65 	if (*p != '\0') {
66 	    Tout(pn, "'%s' not added due to imbedded spaces\n", name);
67 	    return(0);
68 	}
69 
70 	if (checkdups == TRUE) {
71 	    while (r->next != (struct recip *)NULL) {
72 		r = r->next;
73 		if (strcmp(r->name, name) == 0) {
74 			Tout(pn, "duplicate recipient '%s' not added to list\n",
75 									name);
76 			return(0);
77 		}
78 	    }
79 	}
80 
81 	if ((p = malloc (sizeof(struct recip))) == (char *)NULL) {
82 		errmsg(E_MEM,"first malloc failed in add_recip()");
83 		done(1);
84 	}
85 	plist->last_recip->next = (struct recip *)p;
86 	r = plist->last_recip = plist->last_recip->next;
87 	if ((r->name = malloc (strlen(name)+1)) == (char *)NULL) {
88 		errmsg(E_MEM,"second malloc failed in add_recip()");
89 		done(1);
90 	}
91 	strcpy (r->name, name);
92 	r->next = (struct recip *)NULL;
93 	Tout(pn, "'%s' added to recipient list\n", name);
94 
95 	return(1);
96 }
97 
98 madd_recip (plist, namelist, checkdups)
99 reciplist	*plist;
100 char		*namelist;
101 int		checkdups;
102 {
103 	char	*name;
104 	for (name = strtok(namelist, " \t"); name; name = strtok((char*)0, " \t"))
105 		add_recip(plist, name, checkdups);
106 }
107