1 /* Copyright (C) 2004 J.F.Dockes
2  *   This program is free software; you can redistribute it and/or modify
3  *   it under the terms of the GNU General Public License as published by
4  *   the Free Software Foundation; either version 2 of the License, or
5  *   (at your option) any later version.
6  *
7  *   This program is distributed in the hope that it will be useful,
8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *   GNU General Public License for more details.
11  *
12  *   You should have received a copy of the GNU General Public License
13  *   along with this program; if not, write to the
14  *   Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 #ifndef _MAIL_H_INCLUDED_
18 #define _MAIL_H_INCLUDED_
19 
20 #include <sstream>
21 #include <vector>
22 #include <map>
23 
24 #include "mimehandler.h"
25 
26 namespace Binc {
27 class MimeDocument;
28 class MimePart;
29 }
30 
31 class MHMailAttach;
32 
33 /**
34  * Process a mail message (rfc822) into internal documents.
35  */
36 class MimeHandlerMail : public RecollFilter {
37 public:
38     MimeHandlerMail(RclConfig *cnf, const std::string &id);
39     virtual ~MimeHandlerMail();
is_data_input_ok(DataInput input)40     virtual bool is_data_input_ok(DataInput input) const override {
41         return (input == DOCUMENT_FILE_NAME || input == DOCUMENT_STRING);
42     }
43     virtual bool next_document() override;
44     virtual bool skip_to_document(const std::string& ipath) override;
45     virtual void clear_impl() override;
46 
47 protected:
48     virtual bool set_document_file_impl(const std::string& mt,
49                                         const std::string& file_path) override;
50     virtual bool set_document_string_impl(const std::string& mt,
51                                           const std::string& data) override;
52 
53 private:
54     bool processMsg(Binc::MimePart *doc, int depth);
55     void walkmime(Binc::MimePart* doc, int depth);
56     bool processAttach();
57     Binc::MimeDocument     *m_bincdoc;
58     int                     m_fd;
59     std::stringstream      *m_stream;
60 
61     // Current index in parts. starts at -1 for self, then index into
62     // attachments
63     int                     m_idx;
64     // Start of actual text (after the reprinted headers. This is for
65     // generating a semi-meaningful "abstract")
66     std::string::size_type       m_startoftext;
67     std::string                  m_subject;
68     std::vector<MHMailAttach *>  m_attachments;
69     // Additional headers to be processed as per config + field name translation
70     std::map<std::string, std::string>      m_addProcdHdrs;
71 };
72 
73 class MHMailAttach {
74 public:
75     std::string m_contentType;
76     std::string m_filename;
77     std::string m_charset;
78     std::string m_contentTransferEncoding;
79     Binc::MimePart *m_part;
80 };
81 
82 #endif /* _MAIL_H_INCLUDED_ */
83