2
* Copyright (C) 2007 Tommi Maekitalo
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12
* NON-INFRINGEMENT. See the GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
friend std::ostream& operator<< (std::ostream& out, const Mimepart& mimePart);
32
enum ContentTransferEncoding {
38
typedef std::map<std::string, std::string> HeadersType;
40
ContentTransferEncoding contentTransferEncoding;
44
explicit Mimepart(const std::string& contentType_ = "text/plain, charset=UTF-8",
45
ContentTransferEncoding contentTransferEncoding_ = quotedPrintable);
47
void setData(const std::string& data) { body = data; }
48
void addData(const std::string& data) { body += data; }
49
void addData(std::istream& in);
50
const std::string& getBody() const { return body; }
51
void setHeader(const std::string& key, const std::string& value)
52
{ headers[key] = value; }
57
friend std::ostream& operator<< (std::ostream& out, const Mime& mime);
60
typedef Mimepart::ContentTransferEncoding ContentTransferEncoding;
63
typedef std::map<std::string, std::string> HeadersType;
66
typedef std::vector<Mimepart> PartsType;
70
/// Adds a header-line to the mime-object.
71
void setHeader(const std::string& key, const std::string& value)
72
{ headers[key] = value; }
74
/// Adds a part to the mime-object.
75
Mimepart& addPart(const Mimepart& part)
76
{ parts.push_back(part); return parts.back(); }
78
/// Adds a part to the mime-object. The data is passed as a std::string.
79
Mimepart& addPart(const std::string& data, const std::string& contentType = "text/plain",
80
ContentTransferEncoding contentTransferEncoding = Mimepart::quotedPrintable);
82
/// Adds a part to the mime-object. The data is read from a input stream.
83
Mimepart& addPart(std::istream& in, const std::string& contentType = "text/plain",
84
ContentTransferEncoding contentTransferEncoding = Mimepart::quotedPrintable);
86
/// Adds a text file. The data is passed as a std::string.
87
Mimepart& addTextFile(const std::string& contentType, const std::string& filename, const std::string& data)
89
Mimepart& part = addPart(data, contentType, Mimepart::quotedPrintable);
90
part.setHeader("Content-Disposition", "attachment; filename=" + filename);
94
/// Adds a text file. The data is read from a istream
95
Mimepart& addTextFile(const std::string& contentType, const std::string& filename, std::istream& in)
97
Mimepart& part = addPart(in, contentType, Mimepart::quotedPrintable);
98
part.setHeader("Content-Disposition", "attachment; filename=" + filename);
102
/// Adds a text file. The data is read from a file.
103
Mimepart& addTextFile(const std::string& contentType, const std::string& filename);
105
/// Adds a binary file. The data is passed as a std::string.
106
Mimepart& addBinaryFile(const std::string& contentType, const std::string& filename, const std::string& data)
108
Mimepart& part = addPart(data, contentType, Mimepart::base64);
109
part.setHeader("Content-Disposition", "attachment; filename=" + filename);
113
/// Adds a binary file. The data is read from a istream
114
Mimepart& addBinaryFile(const std::string& contentType, const std::string& filename, std::istream& in)
116
Mimepart& part = addPart(in, contentType, Mimepart::base64);
117
part.setHeader("Content-Disposition", "attachment; filename=" + filename);
121
/// Adds a binary file. The data is read from a file.
122
Mimepart& addBinaryFile(const std::string& contentType, const std::string& filename);
126
std::ostream& operator<< (std::ostream& out, const Mimepart& mimePart);
127
std::ostream& operator<< (std::ostream& out, const Mime& mime);