NAWA 0.9
Web Application Framework for C++
SimpleEmail.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2022 Tobias Flaig.
3 *
4 * This file is part of nawa.
5 *
6 * nawa is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License,
8 * version 3, as published by the Free Software Foundation.
9 *
10 * nawa is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with nawa. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25#include <nawa/util/encoding.h>
26#include <nawa/util/utils.h>
27#include <sstream>
28
29using namespace nawa;
30using namespace std;
31
32struct mail::SimpleEmail::Data {
33 std::string text;
34 bool quotedPrintableEncode = true;
35};
36
38
40
41NAWA_COPY_CONSTRUCTOR_DERIVED_IMPL_WITH_NS(mail, SimpleEmail, Email)
42
43NAWA_COPY_ASSIGNMENT_OPERATOR_DERIVED_IMPL(mail::SimpleEmail, Email)
44
45NAWA_MOVE_CONSTRUCTOR_DERIVED_IMPL_WITH_NS(mail, SimpleEmail, Email)
46
47NAWA_MOVE_ASSIGNMENT_OPERATOR_DERIVED_IMPL(mail::SimpleEmail, Email)
48
49NAWA_COMPLEX_DATA_ACCESSORS_IMPL(mail::SimpleEmail, text, string)
50
52
53std::string mail::SimpleEmail::getRaw(shared_ptr<ReplacementRules> const& replacementRules) const {
54 stringstream ret;
55
56 for (auto const& e : headers()) {
57 if (e.first == "MIME-Version" || (data->quotedPrintableEncode && e.first == "Content-Transfer-Encoding"))
58 continue;
59 ret << e.first << ": " << e.second << "\r\n";
60 }
61
62 ret << "MIME-Version: 1.0\r\n";
63 if (data->quotedPrintableEncode) {
64 ret << "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
66 replacementRules ? utils::stringReplace(data->text, *replacementRules) : data->text);
67 } else {
68 ret << "\r\n"
69 << (replacementRules ? utils::stringReplace(data->text, *replacementRules) : data->text);
70 }
71
72 return ret.str();
73}
Structure representing a basic email.
Namespace containing functions for text encoding and decoding.
#define NAWA_PRIMITIVE_DATA_ACCESSORS_IMPL(Class, Member, Type)
Definition: macros.h:137
#define NAWA_COMPLEX_DATA_ACCESSORS_IMPL(Class, Member, Type)
Definition: macros.h:144
#define NAWA_DEFAULT_CONSTRUCTOR_IMPL_WITH_NS(Namespace, Class)
Definition: macros.h:42
#define NAWA_MOVE_CONSTRUCTOR_DERIVED_IMPL_WITH_NS(Namespace, Class, Parent)
Definition: macros.h:94
#define NAWA_COPY_ASSIGNMENT_OPERATOR_DERIVED_IMPL(Class, Parent)
Definition: macros.h:70
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_DERIVED_IMPL(Class, Parent)
Definition: macros.h:112
#define NAWA_COPY_CONSTRUCTOR_DERIVED_IMPL_WITH_NS(Namespace, Class, Parent)
Definition: macros.h:52
#define NAWA_DEFAULT_DESTRUCTOR_IMPL_WITH_NS(Namespace, Class)
Definition: macros.h:37
std::string quotedPrintableEncode(std::string const &input, std::string const &lineEnding="\r\n", bool replaceCrlf=false, bool qEncoding=false)
Definition: encoding.cpp:290
std::unordered_map< std::string, std::string > ReplacementRules
Definition: Email.h:39
std::string stringReplace(std::string input, std::unordered_map< char, char > const &patterns)
Definition: utils.cpp:514
Definition: AppInit.h:31
Contains useful functions that improve the readability and facilitate maintenance of the NAWA code.