r_message_base.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_message_base.h
00003 ///             Base class for email-oriented Blackberry database records
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
00008     Copyright (C) 2007, Brian Edginton (edge@edginton.net)
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 #ifndef __BARRY_RECORD_MESSAGE_BASE_H__
00024 #define __BARRY_RECORD_MESSAGE_BASE_H__
00025 
00026 #include "dll.h"
00027 #include "record.h"
00028 #include <iosfwd>
00029 #include <string>
00030 #include <vector>
00031 #include <map>
00032 #include <stdint.h>
00033 
00034 
00035 namespace Barry {
00036 
00037 // forward declarations
00038 class IConverter;
00039 
00040 //
00041 // NOTE:  All classes here must be container-safe!  Perhaps add sorting
00042 //        operators in the future.
00043 //
00044 
00045 /// \addtogroup RecordParserClasses
00046 /// @{
00047 
00048 class BXEXPORT MessageBase
00049 {
00050 public:
00051         uint8_t RecType;
00052         uint32_t RecordId;
00053 
00054         EmailAddressList From;
00055         EmailAddressList To;
00056         EmailAddressList Cc;
00057         EmailAddressList Bcc;
00058         EmailAddressList Sender;                //< not available for PINMessage?
00059         EmailAddressList ReplyTo;               //< not available for PINMessage?
00060         std::string Subject;
00061         std::string Body;
00062         std::string Attachment;                 //< not available for PINMessage?
00063 
00064         uint32_t MessageRecordId;       // in PINMessage, this happens to be
00065                                         // the same as RecordId in my (CDF)
00066                                         // testing, but interestingly, it is
00067                                         // stored  as a field *inside* the
00068                                         // record, and not as part of the
00069                                         // header... in effect, this record ID
00070                                         // occurs twice in the protocol
00071         uint32_t MessageReplyTo;
00072         time_t MessageDateSent;
00073         time_t MessageDateReceived;
00074 
00075         // Message Flags
00076         bool    MessageTruncated;
00077         bool    MessageRead;
00078         bool    MessageReply;
00079         bool    MessageSaved;
00080         bool    MessageSavedDeleted;
00081 
00082         enum MessagePriorityType {
00083                 LowPriority = 0,
00084                 NormalPriority,
00085                 HighPriority,
00086                 UnknownPriority
00087         };
00088         MessagePriorityType MessagePriority;
00089 
00090         enum MessageSensitivityType {
00091                 NormalSensitivity = 0,
00092                 Personal,
00093                 Private,
00094                 Confidential,
00095                 UnknownSensitivity
00096         };
00097         MessageSensitivityType MessageSensitivity;
00098 
00099         std::vector<UnknownField> Unknowns;
00100 
00101 protected:
00102         std::string SimpleFromAddress() const;
00103 
00104 public:
00105         const unsigned char* ParseField(const unsigned char *begin,
00106                 const unsigned char *end, const IConverter *ic = 0);
00107 
00108 public:
00109         MessageBase();
00110         ~MessageBase();
00111 
00112         // Parser / Builder API (see parser.h / builder.h)
00113         uint8_t GetRecType() const;
00114         uint32_t GetUniqueId() const;   // empty API, not required by protocol
00115         void SetIds(uint8_t Type, uint32_t Id){ RecType = Type; RecordId = Id; }
00116         void ParseHeader(const Data &data, size_t &offset);
00117         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00118         void BuildHeader(Data &data, size_t &offset) const;
00119         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00120 
00121         void Clear();
00122 
00123         void Dump(std::ostream &os) const;
00124 
00125         // sorting
00126         bool operator<(const MessageBase &other) const
00127         {
00128                 return Subject < other.Subject;
00129         }
00130 };
00131 
00132 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const MessageBase &msg) {
00133         msg.Dump(os);
00134         return os;
00135 }
00136 
00137 /// @}
00138 
00139 } // namespace Barry
00140 
00141 #endif
00142 

Generated on Mon Jan 12 10:51:13 2009 for Barry by  doxygen 1.5.7.1