# 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-2011, 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         typedef Barry::UnknownsType                     UnknownsType;
    00049
    00050         uint8_t RecType;
    00051         uint32_t RecordId;
    00052
    00053         EmailAddressList From;
    00054         EmailAddressList To;
    00055         EmailAddressList Cc;
    00056         EmailAddressList Bcc;
    00057         EmailAddressList Sender;                //< not available for PINMessage?
    00058         EmailAddressList ReplyTo;               //< not available for PINMessage?
    00059         std::string Subject;
    00060         std::string Body;
    00061         std::string Attachment;                 //< not available for PINMessage?
    00062
    00063         uint32_t MessageRecordId;       // in PINMessage, this happens to be
    00064                                         // the same as RecordId in my (CDF)
    00065                                         // testing, but interestingly, it is
    00066                                         // stored  as a field *inside* the
    00067                                         // record, and not as part of the
    00068                                         // header... in effect, this record ID
    00069                                         // occurs twice in the protocol
    00070         uint32_t MessageReplyTo;
    00071         time_t MessageDateSent;
    00072         time_t MessageDateReceived;
    00073
    00074         // Message Flags
    00075         bool    MessageTruncated;
    00076         bool    MessageRead;
    00077         bool    MessageReply;
    00078         bool    MessageSaved;
    00079         bool    MessageSavedDeleted;
    00080
    00081         enum PriorityType {
    00082                 LowPriority = 0,
    00083                 NormalPriority,
    00084                 HighPriority,
    00085                 UnknownPriority
    00086         };
    00087         PriorityType Priority;
    00088
    00089         enum SensitivityType {
    00090                 NormalSensitivity = 0,
    00091                 Personal,
    00092                 Private,
    00093                 Confidential,
    00094                 UnknownSensitivity
    00095         };
    00096         SensitivityType Sensitivity;
    00097
    00098         UnknownsType Unknowns;
    00099
    00100 protected:
    00101         std::string SimpleFromAddress() const;
    00102
    00103 public:
    00104         const unsigned char* ParseField(const unsigned char *begin,
    00105                 const unsigned char *end, const IConverter *ic = 0);
    00106
    00107 protected:
    00108         MessageBase();
    00109         ~MessageBase();
    00110
    00111 public:
    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         // operations (common among record classes)
    00122         void Clear();
    00123         void Dump(std::ostream &os) const;
    00124         std::string GetDescription() const;
    00125
    00126         // sorting
    00127         bool operator<(const MessageBase &other) const;
    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