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-2010, 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 class BXEXPORT MessageBase
00046 {
00047 public:
00048         uint8_t RecType;
00049         uint32_t RecordId;
00050 
00051         EmailAddressList From;
00052         EmailAddressList To;
00053         EmailAddressList Cc;
00054         EmailAddressList Bcc;
00055         EmailAddressList Sender;                //< not available for PINMessage?
00056         EmailAddressList ReplyTo;               //< not available for PINMessage?
00057         std::string Subject;
00058         std::string Body;
00059         std::string Attachment;                 //< not available for PINMessage?
00060 
00061         uint32_t MessageRecordId;       // in PINMessage, this happens to be
00062                                         // the same as RecordId in my (CDF)
00063                                         // testing, but interestingly, it is
00064                                         // stored  as a field *inside* the
00065                                         // record, and not as part of the
00066                                         // header... in effect, this record ID
00067                                         // occurs twice in the protocol
00068         uint32_t MessageReplyTo;
00069         time_t MessageDateSent;
00070         time_t MessageDateReceived;
00071 
00072         // Message Flags
00073         bool    MessageTruncated;
00074         bool    MessageRead;
00075         bool    MessageReply;
00076         bool    MessageSaved;
00077         bool    MessageSavedDeleted;
00078 
00079         enum PriorityType {
00080                 LowPriority = 0,
00081                 NormalPriority,
00082                 HighPriority,
00083                 UnknownPriority
00084         };
00085         PriorityType Priority;
00086 
00087         enum SensitivityType {
00088                 NormalSensitivity = 0,
00089                 Personal,
00090                 Private,
00091                 Confidential,
00092                 UnknownSensitivity
00093         };
00094         SensitivityType Sensitivity;
00095 
00096         std::vector<UnknownField> Unknowns;
00097 
00098 protected:
00099         std::string SimpleFromAddress() const;
00100 
00101 public:
00102         const unsigned char* ParseField(const unsigned char *begin,
00103                 const unsigned char *end, const IConverter *ic = 0);
00104 
00105 protected:
00106         MessageBase();
00107         ~MessageBase();
00108 
00109 public:
00110         // Parser / Builder API (see parser.h / builder.h)
00111         uint8_t GetRecType() const;
00112         uint32_t GetUniqueId() const;   // empty API, not required by protocol
00113         void SetIds(uint8_t Type, uint32_t Id){ RecType = Type; RecordId = Id; }
00114         void ParseHeader(const Data &data, size_t &offset);
00115         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00116         void BuildHeader(Data &data, size_t &offset) const;
00117         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00118 
00119         void Clear();
00120 
00121         void Dump(std::ostream &os) const;
00122 
00123         // sorting
00124         bool operator<(const MessageBase &other) const
00125         {
00126                 return Subject < other.Subject;
00127         }
00128 };
00129 
00130 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const MessageBase &msg) {
00131         msg.Dump(os);
00132         return os;
00133 }
00134 
00135 } // namespace Barry
00136 
00137 #endif
00138 

Generated on 29 Mar 2010 for Barry by  doxygen 1.6.1