xref: /titanic_51/usr/src/cmd/mail/add_recip.c (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
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 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 /*
33     NAME
34 	add_recip, madd_recip - add recipients to recipient list
35 
36     SYNOPSIS
37 	int add_recip(reciplist *plist, char *name, int checkdups)
38 	void madd_recip(reciplist *plist, char *name, int checkdups)
39 
40     DESCRIPTION
41 	add_recip() adds the name to the recipient linked list.
42 	If checkdups is set, it first checks to make certain that
43 	the name is not in the list.
44 
45 	madd_recips() is given a list of names separated by white
46 	space. Each name is split off and passed to add_recips.
47 */
48 
49 #include "mail.h"
50 
51 int
52 add_recip(reciplist *plist, char *name, int checkdups)
53 {
54 	char		*p;
55 	static char	pn[] = "add_recip";
56 	recip		*r = &plist->recip_list;
57 
58 	if ((name == (char *)NULL) || (*name == '\0')) {
59 		Tout(pn, "translation to NULL name ignored\n");
60 		return(0);
61 	}
62 
63 	p = name;
64 	while (*p && !isspace(*p)) {
65 		p++;
66 	}
67 	if (*p != '\0') {
68 	    Tout(pn, "'%s' not added due to imbedded spaces\n", name);
69 	    return(0);
70 	}
71 
72 	if (checkdups == TRUE) {
73 	    while (r->next != (struct recip *)NULL) {
74 		r = r->next;
75 		if (strcmp(r->name, name) == 0) {
76 			Tout(pn, "duplicate recipient '%s' not added to list\n",
77 									name);
78 			return(0);
79 		}
80 	    }
81 	}
82 
83 	if ((p = malloc (sizeof(struct recip))) == (char *)NULL) {
84 		errmsg(E_MEM,"first malloc failed in add_recip()");
85 		done(1);
86 	}
87 	plist->last_recip->next = (struct recip *)p;
88 	r = plist->last_recip = plist->last_recip->next;
89 	if ((r->name = malloc (strlen(name)+1)) == (char *)NULL) {
90 		errmsg(E_MEM,"second malloc failed in add_recip()");
91 		done(1);
92 	}
93 	strcpy (r->name, name);
94 	r->next = (struct recip *)NULL;
95 	Tout(pn, "'%s' added to recipient list\n", name);
96 
97 	return(1);
98 }
99 
100 void
101 madd_recip(reciplist *plist, char *namelist, 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