xref: /aoo4110/main/svl/inc/svl/adrparse.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _ADRPARSE_HXX
25 #define _ADRPARSE_HXX
26 
27 #include "svl/svldllapi.h"
28 #include <tools/list.hxx>
29 #include <tools/string.hxx>
30 
31 //============================================================================
32 struct SvAddressEntry_Impl
33 {
34 	UniString m_aAddrSpec;
35 	UniString m_aRealName;
36 
SvAddressEntry_ImplSvAddressEntry_Impl37 	SvAddressEntry_Impl() {};
SvAddressEntry_ImplSvAddressEntry_Impl38 	SvAddressEntry_Impl(UniString const & rTheAddrSpec,
39 						UniString const & rTheRealName):
40 		m_aAddrSpec(rTheAddrSpec), m_aRealName(rTheRealName) {}
41 };
42 
43 //============================================================================
44 DECLARE_LIST(SvAddressList_Impl, SvAddressEntry_Impl *)
45 
46 //============================================================================
47 class SVL_DLLPUBLIC SvAddressParser
48 {
49 	friend class SvAddressParser_Impl;
50 
51 	SvAddressEntry_Impl m_aFirst;
52 	SvAddressList_Impl m_aRest;
53 	bool m_bHasFirst;
54 
55 public:
56 	SvAddressParser(UniString const & rInput);
57 
58 	~SvAddressParser();
59 
Count() const60 	sal_Int32 Count() const { return m_bHasFirst ? m_aRest.Count() + 1 : 0; }
61 
62 	inline UniString const & GetEmailAddress(sal_Int32 nIndex) const;
63 
64 	inline UniString const &GetRealName(sal_Int32 nIndex) const;
65 
66 	/** Create an RFC 822 <mailbox> (i.e., 'e-mail address').
67 
68 		@param rPhrase  Either an empty string (the <mailbox> will have no
69 		<phrase> an will be of the form <addr-spec>), or some text that will
70 		become the <phrase> part of a <phrase route-addr> form <mailbox>.  Non
71 		US-ASCII characters within the text are put into a <qouted-string>
72 		verbatim, so the result may actually not be a valid RFC 822 <mailbox>,
73 		but a more human-readable representation.
74 
75 		@param rAddrSpec  A valid RFC 822 <addr-spec>.  (An RFC 822 <mailbox>
76 		including a <route> cannot be created by this method.)
77 
78 		@param rMailbox  If this method returns true, this parameter returns
79 		the created RFC 822 <mailbox> (rather, a more human-readable
80 		representation thereof).  Otherwise, this parameter is not modified.
81 
82 		@return  True, if rAddrSpec is a valid RFC 822 <addr-spec>.
83 	 */
84 	static bool createRFC822Mailbox(String const & rPhrase,
85 									String const & rAddrSpec,
86 									String & rMailbox);
87 };
88 
GetEmailAddress(sal_Int32 nIndex) const89 inline UniString const & SvAddressParser::GetEmailAddress(sal_Int32 nIndex)
90 	const
91 {
92 	return nIndex == 0 ? m_aFirst.m_aAddrSpec :
93 		                 m_aRest.GetObject(nIndex - 1)->m_aAddrSpec;
94 }
95 
GetRealName(sal_Int32 nIndex) const96 inline UniString const & SvAddressParser::GetRealName(sal_Int32 nIndex) const
97 {
98 	return nIndex == 0 ? m_aFirst.m_aRealName :
99 		                 m_aRest.GetObject(nIndex - 1)->m_aRealName;
100 }
101 
102 #endif // _ADRPARSE_HXX
103 
104