r_message.h

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

Generated on Wed Sep 24 21:27:32 2008 for Barry by  doxygen 1.5.1