1 ///###////////////////////////////////////////////////////////////////////////
2 //
3 // Burton Computer Corporation
4 // http://www.burton-computer.com
5 // http://www.cooldevtools.com
6 // $Id: StreamMailMessageReader.cc 272 2007-01-06 19:37:27Z brian $
7 //
8 // Copyright (C) 2007 Burton Computer Corporation
9 // ALL RIGHTS RESERVED
10 //
11 // This program is open source software; you can redistribute it
12 // and/or modify it under the terms of the Q Public License (QPL)
13 // version 1.0. Use of this software in whole or in part, including
14 // linking it (modified or unmodified) into other programs is
15 // subject to the terms of the QPL.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // Q Public License for more details.
21 //
22 // You should have received a copy of the Q Public License
23 // along with this program; see the file LICENSE.txt. If not, visit
24 // the Burton Computer Corporation or CoolDevTools web site
25 // QPL pages at:
26 //
27 // http://www.burton-computer.com/qpl.html
28 // http://www.cooldevtools.com/qpl.html
29 //
30
31 #include "IstreamCharReader.h"
32 #include "LineReader.h"
33 #include "MbxMailMessageReader.h"
34 #include "MBoxMailMessageReader.h"
35 #include "StreamMailMessageReader.h"
36
StreamMailMessageReader()37 StreamMailMessageReader::StreamMailMessageReader()
38 : m_stream(0)
39 {
40 }
41
~StreamMailMessageReader()42 StreamMailMessageReader::~StreamMailMessageReader()
43 {
44 close();
45 }
46
close()47 void StreamMailMessageReader::close()
48 {
49 m_mailReader.clear();
50 m_lineReader.clear();
51 m_charReader.clear();
52 m_stream = 0;
53 }
54
setStream(istream * in_stream,bool can_seek,bool ignore_from,bool ignore_content_length)55 void StreamMailMessageReader::setStream(istream *in_stream,
56 bool can_seek,
57 bool ignore_from,
58 bool ignore_content_length)
59 {
60 close();
61 m_stream = in_stream;
62 m_charReader.set(new IstreamCharReader(in_stream, can_seek));
63 m_lineReader.set(new LineReader(m_charReader.get()));
64 if (MbxMailMessageReader::isMbxFile(m_charReader.get())) {
65 m_mailReader.set(new MbxMailMessageReader());
66 } else if (ignore_from) {
67 m_mailReader.set(new MailMessageReader());
68 } else {
69 m_mailReader.set(new MBoxMailMessageReader(!ignore_content_length));
70 }
71 m_mailReader->setLineReader(m_lineReader.get());
72 m_lineReader->forward();
73 }
74
readMessage()75 OWNED MailMessage *StreamMailMessageReader::readMessage()
76 {
77 assert(m_mailReader.isNotNull());
78 return m_mailReader->readMessage();
79 }
80