From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- mimelib/group.cpp | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 mimelib/group.cpp (limited to 'mimelib/group.cpp') diff --git a/mimelib/group.cpp b/mimelib/group.cpp new file mode 100644 index 000000000..319e78449 --- /dev/null +++ b/mimelib/group.cpp @@ -0,0 +1,254 @@ +//============================================================================= +// File: group.cpp +// Contents: Definitions for DwGroup +// Maintainer: Doug Sauder +// WWW: http://www.fwb.gulf.net/~dwsauder/mimepp.html +// +// Copyright (c) 1996, 1997 Douglas W. Sauder +// All rights reserved. +// +// IN NO EVENT SHALL DOUGLAS W. SAUDER BE LIABLE TO ANY PARTY FOR DIRECT, +// INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF +// THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF DOUGLAS W. SAUDER +// HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// DOUGLAS W. SAUDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT +// NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" +// BASIS, AND DOUGLAS W. SAUDER HAS NO OBLIGATION TO PROVIDE MAINTENANCE, +// SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. +// +//============================================================================= + +#define DW_IMPLEMENTATION + +#include +#include +#include +#include +#include +#include +#include + +const char* const DwGroup::sClassName = "DwGroup"; + + +DwGroup* (*DwGroup::sNewGroup)(const DwString&, DwMessageComponent*) = 0; + + +DwGroup* DwGroup::NewGroup(const DwString& aStr, DwMessageComponent* aParent) +{ + if (sNewGroup) { + return sNewGroup(aStr, aParent); + } + else { + return new DwGroup(aStr, aParent); + } +} + + +DwGroup::DwGroup() +{ + mMailboxList = + DwMailboxList::NewMailboxList("", this); + mClassId = kCidGroup; + mClassName = sClassName; +} + + +DwGroup::DwGroup(const DwGroup& aGroup) + : DwAddress(aGroup), + mGroupName(aGroup.mGroupName) +{ + mMailboxList = (DwMailboxList*) aGroup.mMailboxList->Clone(); + mMailboxList->SetParent(this); + mClassId = kCidGroup; + mClassName = sClassName; +} + + +DwGroup::DwGroup(const DwString& aStr, DwMessageComponent* aParent) + : DwAddress(aStr, aParent) +{ + mMailboxList = + DwMailboxList::NewMailboxList("", this); + mClassId = kCidGroup; + mClassName = sClassName; +} + + +DwGroup::~DwGroup() +{ + delete mMailboxList; +} + + +const DwGroup& DwGroup::operator = (const DwGroup& aGroup) +{ + if (this == &aGroup) return *this; + DwAddress::operator = (aGroup); + mGroupName = aGroup.mGroupName; + delete mMailboxList; + mMailboxList = (DwMailboxList*) aGroup.mMailboxList->Clone(); + // *mMailboxList = *aGroup.mMailboxList; + return *this; +} + + +const DwString& DwGroup::GroupName() const +{ + return mGroupName; +} + + +const DwString& DwGroup::Phrase() const +{ + return mGroupName; +} + + +void DwGroup::SetGroupName(const DwString& aName) +{ + mGroupName = aName; +} + + +void DwGroup::SetPhrase(const DwString& aPhrase) +{ + mGroupName = aPhrase; +} + + +DwMailboxList& DwGroup::MailboxList() const +{ + return *mMailboxList; +} + + +void DwGroup::Parse() +{ + mIsModified = 0; + mGroupName = ""; + int isGroupNameNull = 1; + if (mMailboxList) { + delete mMailboxList; + } + mMailboxList = DwMailboxList::NewMailboxList("", this); + mIsValid = 0; + DwRfc822Tokenizer tokenizer(mString); + int type = tokenizer.Type(); + int ch; + + // Everything up to the first ':' is the group name + int done = 0; + while (!done && type != eTkNull) { + switch (type) { + case eTkSpecial: + ch = tokenizer.Token()[0]; + switch (ch) { + case ':': + done = 1; + } + break; + case eTkQuotedString: + case eTkAtom: + if (isGroupNameNull) { + isGroupNameNull = 0; + } + else { + mGroupName += " "; + } + mGroupName += tokenizer.Token(); + break; + } + ++tokenizer; + type = tokenizer.Type(); + } + + // Find mailbox list, which ends with ';' + DwTokenString tokenString(mString); + tokenString.SetFirst(tokenizer); + done = 0; + while (!done && type != eTkNull) { + if (type == eTkSpecial && tokenizer.Token()[0] == ';') { + tokenString.ExtendTo(tokenizer); + break; + } + ++tokenizer; + type = tokenizer.Type(); + } + if (mMailboxList) { + delete mMailboxList; + } + mMailboxList = DwMailboxList::NewMailboxList(tokenString.Tokens(), this); + mMailboxList->Parse(); + if (mGroupName.length() > 0) { + mIsValid = 1; + } + else { + mIsValid = 0; + } +} + + +void DwGroup::Assemble() +{ + if (!mIsModified) return; + if (mGroupName.length() == 0) { + mIsValid = 0; + mString = ""; + return; + } + mMailboxList->Assemble(); + mString = ""; + mString += mGroupName; + mString += ":"; + mString += mMailboxList->AsString(); + mString += ";"; + mIsModified = 0; +} + + +DwMessageComponent* DwGroup::Clone() const +{ + return new DwGroup(*this); +} + + +#if defined (DW_DEBUG_VERSION) +void DwGroup::PrintDebugInfo(std::ostream& aStrm, int aDepth) const +{ + aStrm << "------------ Debug info for DwGroup class ------------\n"; + _PrintDebugInfo(aStrm); + int depth = aDepth - 1; + depth = (depth >= 0) ? depth : 0; + if (aDepth == 0 || depth > 0) { + mMailboxList->PrintDebugInfo(aStrm, depth); + } +} +#else +void DwGroup::PrintDebugInfo(std::ostream&, int) const {} +#endif // defined (DW_DEBUG_VERSION) + + +#if defined (DW_DEBUG_VERSION) +void DwGroup::_PrintDebugInfo(std::ostream& aStrm) const +{ + DwAddress::_PrintDebugInfo(aStrm); + aStrm << "Group name: " << mGroupName << '\n'; + aStrm << "Mailbox list: " << mMailboxList->ObjectId() << '\n'; +} +#else +void DwGroup::_PrintDebugInfo(std::ostream& ) const {} +#endif // defined (DW_DEBUG_VERSION) + + +void DwGroup::CheckInvariants() const +{ +#if defined (DW_DEBUG_VERSION) + DwAddress::CheckInvariants(); + mGroupName.CheckInvariants(); + mMailboxList->CheckInvariants(); + assert((DwMessageComponent*) this == mMailboxList->Parent()); +#endif // defined (DW_DEBUG_VERSION) +} -- cgit v1.2.1