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 #pragma ident "%Z%%M% %I% %E% SMI"
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate NAME
347c478bd9Sstevel@tonic-gate add_recip, madd_recip - add recipients to recipient list
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate SYNOPSIS
377c478bd9Sstevel@tonic-gate int add_recip(reciplist *plist, char *name, int checkdups)
38*b7d62af5Sceastha void madd_recip(reciplist *plist, char *name, int checkdups)
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate DESCRIPTION
417c478bd9Sstevel@tonic-gate add_recip() adds the name to the recipient linked list.
427c478bd9Sstevel@tonic-gate If checkdups is set, it first checks to make certain that
437c478bd9Sstevel@tonic-gate the name is not in the list.
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate madd_recips() is given a list of names separated by white
467c478bd9Sstevel@tonic-gate space. Each name is split off and passed to add_recips.
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate #include "mail.h"
507c478bd9Sstevel@tonic-gate
51*b7d62af5Sceastha int
add_recip(reciplist * plist,char * name,int checkdups)52*b7d62af5Sceastha add_recip(reciplist *plist, char *name, int checkdups)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate char *p;
557c478bd9Sstevel@tonic-gate static char pn[] = "add_recip";
567c478bd9Sstevel@tonic-gate recip *r = &plist->recip_list;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate if ((name == (char *)NULL) || (*name == '\0')) {
597c478bd9Sstevel@tonic-gate Tout(pn, "translation to NULL name ignored\n");
607c478bd9Sstevel@tonic-gate return(0);
617c478bd9Sstevel@tonic-gate }
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate p = name;
647c478bd9Sstevel@tonic-gate while (*p && !isspace(*p)) {
657c478bd9Sstevel@tonic-gate p++;
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate if (*p != '\0') {
687c478bd9Sstevel@tonic-gate Tout(pn, "'%s' not added due to imbedded spaces\n", name);
697c478bd9Sstevel@tonic-gate return(0);
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate if (checkdups == TRUE) {
737c478bd9Sstevel@tonic-gate while (r->next != (struct recip *)NULL) {
747c478bd9Sstevel@tonic-gate r = r->next;
757c478bd9Sstevel@tonic-gate if (strcmp(r->name, name) == 0) {
767c478bd9Sstevel@tonic-gate Tout(pn, "duplicate recipient '%s' not added to list\n",
777c478bd9Sstevel@tonic-gate name);
787c478bd9Sstevel@tonic-gate return(0);
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate if ((p = malloc (sizeof(struct recip))) == (char *)NULL) {
847c478bd9Sstevel@tonic-gate errmsg(E_MEM,"first malloc failed in add_recip()");
857c478bd9Sstevel@tonic-gate done(1);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate plist->last_recip->next = (struct recip *)p;
887c478bd9Sstevel@tonic-gate r = plist->last_recip = plist->last_recip->next;
897c478bd9Sstevel@tonic-gate if ((r->name = malloc (strlen(name)+1)) == (char *)NULL) {
907c478bd9Sstevel@tonic-gate errmsg(E_MEM,"second malloc failed in add_recip()");
917c478bd9Sstevel@tonic-gate done(1);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate strcpy (r->name, name);
947c478bd9Sstevel@tonic-gate r->next = (struct recip *)NULL;
957c478bd9Sstevel@tonic-gate Tout(pn, "'%s' added to recipient list\n", name);
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate return(1);
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate
100*b7d62af5Sceastha void
madd_recip(reciplist * plist,char * namelist,int checkdups)101*b7d62af5Sceastha madd_recip(reciplist *plist, char *namelist, int checkdups)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate char *name;
1047c478bd9Sstevel@tonic-gate for (name = strtok(namelist, " \t"); name; name = strtok((char*)0, " \t"))
1057c478bd9Sstevel@tonic-gate add_recip(plist, name, checkdups);
1067c478bd9Sstevel@tonic-gate }
107