This adds Saved Email Messages and actually has the patch attached (duh). -edge
Index: src/s11n-boost.h
===================================================================
RCS file: /cvsroot/barry/barry/src/s11n-boost.h,v
retrieving revision 1.8
diff -u -r1.8 s11n-boost.h
--- src/s11n-boost.h 6 Jun 2007 20:52:55 -0000 1.8
+++ src/s11n-boost.h 7 Jun 2007 23:09:30 -0000
@@ -234,6 +234,24 @@
}
}
+template <class ArchiveT>
+void serialize(ArchiveT &ar, Barry::SavedMessage &m, const unsigned int ver)
+{
+ ar & make_nvp("From", m.From);
+ ar & make_nvp("To", m.To);
+ ar & make_nvp("Cc", m.Cc);
+ ar & make_nvp("Bcc", m.Bcc);
+ ar & make_nvp("Sender", m.Sender);
+ ar & make_nvp("ReplyTo", m.ReplyTo);
+ ar & make_nvp("Subject", m.Subject);
+ ar & make_nvp("Body", m.Body);
+ ar & make_nvp("Attachment", m.Attachment);
+
+ if( ver < BARRY_POD_MAP_VERSION ) {
+ ar & make_nvp("Unknowns", m.Unknowns);
+ }
+}
+
}} // namespace boost::serialization
#endif
Index: src/record.h
===================================================================
RCS file: /cvsroot/barry/barry/src/record.h,v
retrieving revision 1.25
diff -u -r1.25 record.h
--- src/record.h 6 Jun 2007 20:52:55 -0000 1.25
+++ src/record.h 7 Jun 2007 23:09:29 -0000
@@ -205,6 +205,7 @@
#include "r_servicebook.h"
#include "r_task.h"
#include "r_pin_message.h"
+#include "r_saved_message.h"
#endif
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/barry/barry/src/Makefile.am,v
retrieving revision 1.17
diff -u -r1.17 Makefile.am
--- src/Makefile.am 6 Jun 2007 20:52:55 -0000 1.17
+++ src/Makefile.am 7 Jun 2007 23:09:29 -0000
@@ -67,6 +67,7 @@
r_memo.h \
r_message.h \
r_pin_message.h \
+ r_saved_message.h \
r_servicebook.h \
r_task.h \
socket.h \
@@ -94,6 +95,7 @@
r_message.cc \
r_pin_message.cc \
r_servicebook.cc \
+ r_saved_message.cc \
r_task.cc \
packet.cc packet.h \
controller.cc \
Index: tools/btool.cc
===================================================================
RCS file: /cvsroot/barry/barry/tools/btool.cc,v
retrieving revision 1.18
diff -u -r1.18 btool.cc
--- tools/btool.cc 6 Jun 2007 20:52:55 -0000 1.18
+++ tools/btool.cc 7 Jun 2007 23:09:30 -0000
@@ -234,6 +234,11 @@
new RecordParser<PINMessage, Store<PINMessage> > (
new Store<PINMessage>(filename, false)));
}
+ else if( name == "Saved Email Messages" ) {
+ return auto_ptr<Parser>(
+ new RecordParser<SavedMessage, Store<SavedMessage> > (
+ new Store<SavedMessage>(filename, false)));
+ }
else {
// unknown database, use null parser
return auto_ptr<Parser>( new DataDumpParser );
Index: src/r_saved_message.cc
===================================================================
RCS file: src/r_saved_message.cc
diff -N src/r_saved_message.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/r_saved_message.cc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,239 @@
+///
+/// \file r_saved_message.cc
+/// Blackberry database record parser class for email records.
+///
+
+/*
+ Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
+ Copyright (C) 2005-2007, Brian Edginton ([EMAIL PROTECTED])
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ See the GNU General Public License in the COPYING file at the
+ root directory of this project for more details.
+*/
+
+#include "r_saved_message.h"
+#include "record-internal.h"
+#include "protocol.h"
+#include "protostructs.h"
+#include "data.h"
+#include "time.h"
+#include "error.h"
+#include "endian.h"
+#include <ostream>
+#include <iomanip>
+#include <time.h>
+#include <stdexcept>
+
+#define __DEBUG_MODE__
+#include "debug.h"
+
+using namespace std;
+using namespace Barry::Protocol;
+
+namespace Barry {
+
+///////////////////////////////////////////////////////////////////////////////
+// Message class
+
+
+// Email / message field codes
+#define SEMFC_TO 0x01 // can occur multiple times
+#define SEMFC_CC 0x02 // ditto
+#define SEMFC_BCC 0x03 // ditto
+#define SEMFC_SENDER 0x04
+#define SEMFC_FROM 0x05
+#define SEMFC_REPLY_TO 0x06
+#define SEMFC_SUBJECT 0x0b
+#define SEMFC_BODY 0x0c
+#define SEMFC_ATTACHMENT 0x16
+#define SEMFC_RECORDID 0x4b
+#define SEMFC_END 0xffff
+
+FieldLink<SavedMessage> SavedMessageFieldLinks[] = {
+ { SEMFC_TO, "To", 0, 0, 0, &SavedMessage::To, 0 },
+ { SEMFC_CC, "Cc", 0, 0, 0, &SavedMessage::Cc, 0 },
+ { SEMFC_BCC, "Bcc", 0, 0, 0, &SavedMessage::Bcc, 0 },
+ { SEMFC_SENDER, "Sender", 0, 0, 0, &SavedMessage::Sender, 0 },
+ { SEMFC_FROM, "From", 0, 0, 0, &SavedMessage::From, 0 },
+ { SEMFC_REPLY_TO, "ReplyTo", 0, 0, 0, &SavedMessage::ReplyTo, 0 },
+ { SEMFC_SUBJECT, "Subject", 0, 0, &SavedMessage::Subject, 0, 0 },
+ { SEMFC_BODY, "Body", 0, 0, &SavedMessage::Body, 0, 0 },
+ { SEMFC_ATTACHMENT, "Attachment", 0, 0, &SavedMessage::Attachment, 0, 0 },
+ { SEMFC_END, "End of List", 0, 0, 0, 0, 0 }
+};
+
+SavedMessage::SavedMessage()
+{
+ Clear();
+}
+
+SavedMessage::~SavedMessage()
+{
+}
+
+const unsigned char* SavedMessage::ParseField(const unsigned char *begin,
+ const unsigned char *end)
+{
+ const CommonField *field = (const CommonField *) begin;
+
+ // advance and check size
+ begin += COMMON_FIELD_HEADER_SIZE + btohs(field->size);
+ if( begin > end ) // if begin==end, we are ok
+ return begin;
+
+ if( !btohs(field->size) ) // if field has no size, something's up
+ return begin;
+
+ // cycle through the type table
+ for( FieldLink<SavedMessage> *b = SavedMessageFieldLinks;
+ b->type != SEMFC_END;
+ b++ )
+ {
+ if( b->type == field->type ) {
+ if( b->strMember ) {
+ // parse regular string
+ std::string &s = this->*(b->strMember);
+ s.assign((const char *)field->u.raw, btohs(field->size)-1);
+ return begin; // done!
+ }
+ else if( b->addrMember ) {
+ // parse email address
+ // get dual name+addr string first
+ const char *fa = (const char*)field->u.addr.addr;
+ std::string dual(fa, btohs(field->size) - sizeof(field->u.addr.unknown));
+
+ // assign first string, using null terminator...letting std::string add it for us if it doesn't exist
+ Address &a = this->*(b->addrMember);
+ a.Name = dual.c_str();
+
+ // assign second string, using first size as starting point
+ a.Email = dual.c_str() + a.Name.size() + 1;
+ return begin;
+ }
+ }
+ }
+ // handle special cases
+ switch( field->type ) {
+ case SEMFC_RECORDID:
+ MessageRecordId = field->u.uint32;
+ return begin;
+ }
+ // if still not handled, add to the Unknowns list
+ UnknownField uf;
+ uf.type = field->type;
+ uf.data.assign((const char*)field->u.raw, btohs(field->size));
+ Unknowns.push_back(uf);
+
+ return begin;
+}
+
+uint8_t SavedMessage::GetRecType() const
+{
+ throw std::logic_error("SavedMessage::GetRecType() called, and not supported by the USB protocol. Should never get called.");
+}
+
+// empty API, not required by protocol
+uint32_t SavedMessage::GetUniqueId() const
+{
+ throw std::logic_error("SavedMessage::GetUniqueId() called, and not supported by the USB protocol. Should never get called.");
+}
+
+void SavedMessage::ParseHeader(const Data &data, size_t &offset)
+{
+ // we skip the "header" since we don't know what to do with it yet
+ offset += MESSAGE_RECORD_HEADER_SIZE;
+}
+
+void SavedMessage::ParseFields(const Data &data, size_t &offset)
+{
+ const unsigned char *finish = ParseCommonFields(*this,
+ data.GetData() + offset, data.GetData() + data.GetSize());
+ offset += finish - (data.GetData() + offset);
+}
+
+void SavedMessage::BuildHeader(Data &data, size_t &offset) const
+{
+ throw std::logic_error("SavedMessage::BuildHeader not yet implemented");
+}
+
+void SavedMessage::BuildFields(Data &data, size_t &offset) const
+{
+ throw std::logic_error("SavedMessage::BuildFields not yet implemented");
+}
+
+void SavedMessage::Clear()
+{
+ From.Name.clear();
+ From.Email.clear();
+ To.Name.clear();
+ To.Email.clear();
+ Cc.Name.clear();
+ Cc.Email.clear();
+ Bcc.Email.clear();
+ Bcc.Name.clear();
+ Sender.Name.clear();
+ Sender.Email.clear();
+ ReplyTo.Name.clear();
+ ReplyTo.Email.clear();
+ Subject.clear();
+ Body.clear();
+ Attachment.clear();
+
+ MessageRecordId = 0;
+
+ Unknowns.clear();
+}
+
+// dump message in mbox format
+void SavedMessage::Dump(std::ostream &os) const
+{
+ // FIXME - use current time until we figure out the date headers
+ time_t fixme = time(NULL);
+
+ os << "Record ID (0x" << MessageRecordId << ")\n";
+ os << "From " << (From.Email.size() ? From.Email.c_str() : "unknown")
+ << " " << ctime(&fixme);
+ os << "Date: " << ctime(&fixme);
+ os << "From: " << From << "\n";
+ if( To.Email.size() )
+ os << "To: " << To << "\n";
+ if( Cc.Email.size() )
+ os << "Cc: " << Cc << "\n";
+ if( Bcc.Email.size() )
+ os << "Bcc: " << Bcc << "\n";
+ if( Sender.Email.size() )
+ os << "Sender: " << Sender << "\n";
+ if( ReplyTo.Email.size())
+ os << "Reply To: " << ReplyTo << "\n";
+ if( Subject.size() )
+ os << "Subject: " << Subject << "\n";
+ os << "\n";
+ for( std::string::const_iterator i = Body.begin();
+ i != Body.end() && *i;
+ i++)
+ {
+ if( *i == '\r' )
+ os << '\n';
+ else
+ os << *i;
+ }
+ os << "\n";
+ if( Attachment.size() )
+ os << "Attachments: " << Attachment << "\n";
+
+ os << Unknowns;
+ os << "\n\n";
+}
+
+
+} // namespace Barry
+
Index: src/r_saved_message.h
===================================================================
RCS file: src/r_saved_message.h
diff -N src/r_saved_message.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/r_saved_message.h 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,102 @@
+///
+/// \file r_save_message.h
+/// Blackberry database record parser class for saved email message records.
+///
+
+/*
+ Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
+ Copyright (C) 2007, Brian Edginton ([EMAIL PROTECTED])
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ See the GNU General Public License in the COPYING file at the
+ root directory of this project for more details.
+*/
+
+#ifndef __BARRY_RECORD_SAVED_MESSAGE_H__
+#define __BARRY_RECORD_SAVED_MESSAGE_H__
+
+#include "record.h"
+#include <iosfwd>
+#include <string>
+#include <vector>
+#include <map>
+#include <stdint.h>
+
+namespace Barry {
+
+//
+// NOTE: All classes here must be container-safe! Perhaps add sorting
+// operators in the future.
+//
+
+/// \addtogroup RecordParserClasses
+/// @{
+
+class SavedMessage
+{
+public:
+ uint8_t RecType;
+ uint32_t RecordId;
+
+ Address From;
+ Address To;
+ Address Cc;
+ Address Bcc;
+ Address Sender;
+ Address ReplyTo;
+ std::string Subject;
+ std::string Body;
+ std::string Attachment;
+ uint32_t MessageRecordId;
+ std::vector<UnknownField> Unknowns;
+
+public:
+ const unsigned char* ParseField(const unsigned char *begin,
+ const unsigned char *end);
+
+public:
+ SavedMessage();
+ ~SavedMessage();
+
+ // Parser / Builder API (see parser.h / builder.h)
+ uint8_t GetRecType() const;
+ uint32_t GetUniqueId() const; // empty API, not required by protocol
+ void SetIds(uint8_t Type, uint32_t Id){ RecType = Type; RecordId = Id; }
+ void ParseHeader(const Data &data, size_t &offset);
+ void ParseFields(const Data &data, size_t &offset);
+ void BuildHeader(Data &data, size_t &offset) const;
+ void BuildFields(Data &data, size_t &offset) const;
+ void Clear();
+ void Dump(std::ostream &os) const;
+
+ // sorting
+ bool operator<(const SavedMessage &other) const { return Subject < other.Subject; }
+
+ // database name
+ static const char * GetDBName() { return "Saved Email Messages"; }
+ static uint8_t GetDefaultRecType() { return 3; }
+};
+
+inline std::ostream& operator<<(std::ostream &os, const SavedMessage &msg) {
+ msg.Dump(os);
+ return os;
+}
+
+std::ostream& operator<<(std::ostream &os, const Address &msga);
+
+
+/// @}
+
+} // namespace Barry
+
+#endif // __BARRY_RECORD_SAVED_MESSAGE_H__
+
+
pgpriBTP1vXnb.pgp
Description: PGP signature
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Barry-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/barry-devel
