2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
27 * $XConsortium: AliasExpand.C /main/4 1996/04/21 19:49:19 drk $
29 * RESTRICTED CONFIDENTIAL INFORMATION:
31 * The information in this document is subject to special
32 * restrictions in a confidential disclosure agreement bertween
33 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
35 * Sun's specific written approval. This documment and all copies
36 * and derivative works thereof must be returned or destroyed at
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
46 #include "AliasExpand.hh"
49 AliasKey::AliasKey(const char * str)
50 : ObjectKey("AliasKey")
55 AliasKey::~AliasKey(void)
61 AliasKey::operator==(ObjectKey & other)
63 AliasKey * ok = (AliasKey *)&other;
65 return(strcmp(_str, ok->_str) == 0);
69 AliasKey::operator!=(ObjectKey & other)
71 AliasKey * ok = (AliasKey *)&other;
73 return(strcmp(_str, ok->_str) != 0);
77 AliasKey::operator<(ObjectKey & other)
79 AliasKey * ok = (AliasKey *)&other;
81 return(strcmp(_str, ok->_str) < 0);
85 AliasKey::operator<=(ObjectKey & other)
87 AliasKey * ok = (AliasKey *)&other;
89 return(strcmp(_str, ok->_str) <= 0);
93 AliasKey::operator>(ObjectKey & other)
95 AliasKey * ok = (AliasKey *)&other;
97 return(strcmp(_str, ok->_str) > 0);
101 AliasKey::operator>=(ObjectKey & other)
103 AliasKey * ok = (AliasKey *)&other;
105 return(strcmp(_str, ok->_str) >= 0);
109 AliasKey::hashValue(void)
111 return(genericHashValue(_str, strlen(_str)));
114 // deleteAllocatedKey: used to iterate through a hash table to remove
115 // all key values that are allocated during the duration of rfcAliasExpand
118 deleteAllocatedKey(ObjectKey & object, AliasKey *, void *) {
119 assert(&object != NULL);
126 rfcAliasExpand(DtMailEnv & error,
127 DtMail::MailRc & mailrc,
128 DtMailAddressSeq & addrs)
130 HashTable<DtMailBoolean> been_there(32);
134 // We will go through each item in the address table.
135 // For each address, we will look it up in the alias
136 // table. If it exists there, we will check to see if
137 // we have expanded before. If not, then we expand and
142 for (int naddr = 0; naddr < addrs.length(); naddr++) {
143 DtMailValueAddress * caddr = addrs[naddr];
145 const char * alias = mailrc.getAlias(lerror, caddr->dtm_address);
147 AliasKey * key = new AliasKey(caddr->dtm_address);
148 if (been_there.lookup(*key)) { // already visited address?
149 delete key; // yes: cleanup unneeded key
151 else { // no: expand the alias
152 DtMailAddressSeq exp_addrs(32);
153 RFCTransport::arpaPhrase(alias, exp_addrs);
155 for (int cp = 0; cp < exp_addrs.length(); cp++) {
156 DtMailValueAddress * new_addr = new DtMailValueAddress(*exp_addrs[cp]);
157 addrs.append(new_addr);
160 been_there.set(*key, DTM_TRUE);
163 addrs.remove(naddr); // no longer need this address
165 delete caddr; // or what it pointed to.
169 // Finally, as a courtesy to the recipients, we will throw away
170 // duplicates that have resulted from our expansion.
172 HashTable<DtMailBoolean> done_that(32);
173 for (int cur = 0; cur < addrs.length(); cur++) {
174 DtMailValueAddress * caddr = addrs[cur];
175 AliasKey * dup_key = new AliasKey(caddr->dtm_address);
177 if (done_that.lookup(*dup_key)) {
184 done_that.set(*dup_key, DTM_TRUE);