aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2004-12-16 10:23:45 +0000
committerVincent Richard <[email protected]>2004-12-16 10:23:45 +0000
commit62093084c5670d2ef71a1fbc85f3ffb23bd25c87 (patch)
tree9957af77615e8378fbc9c648e3ce3fa1da51fe27
parentAdded skip() method on inputStream. (diff)
downloadvmime-62093084c5670d2ef71a1fbc85f3ffb23bd25c87.tar.gz
vmime-62093084c5670d2ef71a1fbc85f3ffb23bd25c87.zip
Working on 'maildir' implementation.
-rw-r--r--src/messaging/maildirMessage.cpp81
-rw-r--r--src/messaging/maildirMessage.hpp2
2 files changed, 80 insertions, 3 deletions
diff --git a/src/messaging/maildirMessage.cpp b/src/messaging/maildirMessage.cpp
index e87b73ab..cd660fb9 100644
--- a/src/messaging/maildirMessage.cpp
+++ b/src/messaging/maildirMessage.cpp
@@ -67,6 +67,12 @@ public:
return (*(m_header = new header()));
}
+ const int getHeaderParsedOffset() const { return (m_headerParsedOffset); }
+ const int getHeaderParsedLength() const { return (m_headerParsedLength); }
+
+ const int getBodyParsedOffset() const { return (m_bodyParsedOffset); }
+ const int getBodyParsedLength() const { return (m_bodyParsedLength); }
+
private:
maildirStructure* m_structure;
@@ -270,20 +276,89 @@ void maildirMessage::setFlags(const int flags, const int mode)
void maildirMessage::extract(utility::outputStream& os,
progressionListener* progress, const int start, const int length) const
{
- // TODO
+ extractImpl(os, progress, 0, m_size, start, length);
}
void maildirMessage::extractPart(const part& p, utility::outputStream& os,
progressionListener* progress, const int start, const int length) const
{
- // TODO
+ const maildirPart& mp = dynamic_cast <const maildirPart&>(p);
+
+ extractImpl(os, progress, mp.getBodyParsedOffset(), mp.getBodyParsedLength(), start, length);
+}
+
+
+void maildirMessage::extractImpl(utility::outputStream& os, progressionListener* progress,
+ const int start, const int length, const int partialStart, const int partialLength) const
+{
+ utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
+
+ const utility::file::path path = m_folder->getMessageFSPath(m_num);
+ utility::auto_ptr <utility::file> file = fsf->create(path);
+
+ utility::auto_ptr <utility::fileReader> reader = file->getFileReader();
+ utility::auto_ptr <utility::inputStream> is = reader->getInputStream();
+
+ is->skip(start + partialStart);
+
+ utility::stream::value_type buffer[8192];
+ utility::stream::size_type remaining = (partialLength == -1 ? length
+ : std::min(partialLength, length));
+
+ const int total = remaining;
+ int current = 0;
+
+ progress->start(total);
+
+ while (!is->eof() && remaining > 0)
+ {
+ const utility::stream::size_type read =
+ is->read(buffer, std::min(remaining, sizeof(buffer)));
+
+ remaining -= read;
+ current += read;
+
+ os.write(buffer, read);
+
+ progress->progress(current, total);
+ }
+
+ progress->stop(total);
}
void maildirMessage::fetchPartHeader(part& p)
{
- // TODO
+ maildirPart& mp = dynamic_cast <maildirPart&>(p);
+
+ utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
+
+ const utility::file::path path = m_folder->getMessageFSPath(m_num);
+ utility::auto_ptr <utility::file> file = fsf->create(path);
+
+ utility::auto_ptr <utility::fileReader> reader = file->getFileReader();
+ utility::auto_ptr <utility::inputStream> is = reader->getInputStream();
+
+ is->skip(mp.getHeaderParsedOffset());
+
+ utility::stream::value_type buffer[1024];
+ utility::stream::size_type remaining = mp.getHeaderParsedLength();
+
+ string contents;
+ contents.reserve(remaining);
+
+ while (!is->eof() && remaining > 0)
+ {
+ const utility::stream::size_type read =
+ is->read(buffer, std::min(remaining, sizeof(buffer)));
+
+ remaining -= read;
+
+ contents.append(buffer, read);
+ }
+
+ mp.getOrCreateHeader().parse(contents);
}
diff --git a/src/messaging/maildirMessage.hpp b/src/messaging/maildirMessage.hpp
index f487b32d..11eae7f6 100644
--- a/src/messaging/maildirMessage.hpp
+++ b/src/messaging/maildirMessage.hpp
@@ -77,6 +77,8 @@ private:
header& getOrCreateHeader();
+ void extractImpl(utility::outputStream& os, progressionListener* progress, const int start, const int length, const int partialStart, const int partialLength) const;
+
maildirFolder* m_folder;