1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: adrparse.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include "svtools/svldllapi.h"
35 #include <tools/list.hxx>
36 #include <tools/string.hxx>
38 //============================================================================
39 struct SvAddressEntry_Impl
41 UniString m_aAddrSpec
;
42 UniString m_aRealName
;
44 SvAddressEntry_Impl() {};
45 SvAddressEntry_Impl(UniString
const & rTheAddrSpec
,
46 UniString
const & rTheRealName
):
47 m_aAddrSpec(rTheAddrSpec
), m_aRealName(rTheRealName
) {}
50 //============================================================================
51 DECLARE_LIST(SvAddressList_Impl
, SvAddressEntry_Impl
*)
53 //============================================================================
54 class SVL_DLLPUBLIC SvAddressParser
56 friend class SvAddressParser_Impl
;
58 SvAddressEntry_Impl m_aFirst
;
59 SvAddressList_Impl m_aRest
;
63 SvAddressParser(UniString
const & rInput
);
67 sal_Int32
Count() const { return m_bHasFirst
? m_aRest
.Count() + 1 : 0; }
69 inline UniString
const & GetEmailAddress(sal_Int32 nIndex
) const;
71 inline UniString
const &GetRealName(sal_Int32 nIndex
) const;
73 /** Create an RFC 822 <mailbox> (i.e., 'e-mail address').
75 @param rPhrase Either an empty string (the <mailbox> will have no
76 <phrase> an will be of the form <addr-spec>), or some text that will
77 become the <phrase> part of a <phrase route-addr> form <mailbox>. Non
78 US-ASCII characters within the text are put into a <qouted-string>
79 verbatim, so the result may actually not be a valid RFC 822 <mailbox>,
80 but a more human-readable representation.
82 @param rAddrSpec A valid RFC 822 <addr-spec>. (An RFC 822 <mailbox>
83 including a <route> cannot be created by this method.)
85 @param rMailbox If this method returns true, this parameter returns
86 the created RFC 822 <mailbox> (rather, a more human-readable
87 representation thereof). Otherwise, this parameter is not modified.
89 @return True, if rAddrSpec is a valid RFC 822 <addr-spec>.
91 static bool createRFC822Mailbox(String
const & rPhrase
,
92 String
const & rAddrSpec
,
96 inline UniString
const & SvAddressParser::GetEmailAddress(sal_Int32 nIndex
)
99 return nIndex
== 0 ? m_aFirst
.m_aAddrSpec
:
100 m_aRest
.GetObject(nIndex
- 1)->m_aAddrSpec
;
103 inline UniString
const & SvAddressParser::GetRealName(sal_Int32 nIndex
) const
105 return nIndex
== 0 ? m_aFirst
.m_aRealName
:
106 m_aRest
.GetObject(nIndex
- 1)->m_aRealName
;
109 #endif // _ADRPARSE_HXX