3 /// Storage, parser, builder classes for MIME objects
4 /// (vcard, vevent, vtodo, vjournal)
8 Copyright (C) 2010, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
36 MimeBuilder::MimeBuilder(const std::string
&filename
)
37 : m_ifs( new std::ifstream(filename
.c_str()) )
42 MimeBuilder::MimeBuilder(std::istream
&is
)
47 bool MimeBuilder::BuildRecord(DBData
&data
, size_t &offset
,
51 while( ReadMimeRecord(m_is
, vrec
, type
) ) {
56 else if( strcasecmp(type
.c_str(), Sync::vCard::GetVName()) == 0 ) {
58 SetDBData(vcard
.ToBarry(vrec
.c_str(), 0),
62 else if( strcasecmp(type
.c_str(), Sync::vCalendar::GetVName()) == 0 ) {
63 Sync::vTimeConverter vtc
;
64 Sync::vCalendar
vcal(vtc
);
65 SetDBData(vcal
.ToBarry(vrec
.c_str(), 0),
69 else if( strcasecmp(type
.c_str(), Sync::vTodo::GetVName()) == 0 ) {
70 Sync::vTimeConverter vtc
;
71 Sync::vTodo
vtodo(vtc
);
72 SetDBData(vtodo
.ToBarry(vrec
.c_str(), 0),
76 else if( strcasecmp(type
.c_str(), Sync::vJournal::GetVName()) == 0 ) {
77 Sync::vJournal vjournal
;
78 SetDBData(vjournal
.ToBarry(vrec
.c_str(), 0),
91 bool MimeBuilder::FetchRecord(DBData
&data
, const IConverter
*ic
)
94 return BuildRecord(data
, offset
, ic
);
97 bool MimeBuilder::EndOfFile() const
102 // return false at end of file, true if a record was read
103 bool MimeBuilder::ReadMimeRecord(std::istream
&is
, std::string
&vrec
,
112 while( getline(is
, line
) ) {
113 if( strcasecmp(line
.substr(0, 6).c_str(), "BEGIN:") == 0 ) {
116 type
= line
.substr(6);
126 while( getline(is
, line
) ) {
127 // end on blank lines
134 // pick up innermost BEGIN line
135 if( strcasecmp(line
.substr(0, 6).c_str(), "BEGIN:") == 0 ) {
136 type
= line
.substr(6);
137 while( type
.size() && type
[type
.size()-1] == '\r' ) {
138 type
= type
.substr(0, type
.size()-1);
142 // place an upper limit on the number of lines...
143 // since a MIME data block shouldn't be more than
144 // a few pages of lines!
149 // assume that end of file is the same as "blank line"