comparison 3rdparty/vmime/tests/utility/encoder/encoderTestUtils.hpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 //
2 // VMime library (http://www.vmime.org)
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3 of
8 // the License, or (at your option) any later version.
9 //
10 // This program 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 GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Linking this library statically or dynamically with other modules is making
20 // a combined work based on this library. Thus, the terms and conditions of
21 // the GNU General Public License cover the whole combination.
22 //
23
24
25 // Helper function to obtain an encoder given its name
26 static vmime::shared_ptr <vmime::utility::encoder::encoder> getEncoder(const vmime::string& name,
27 int maxLineLength = 0, const vmime::propertySet props = vmime::propertySet())
28 {
29 vmime::shared_ptr <vmime::utility::encoder::encoder> enc =
30 vmime::utility::encoder::encoderFactory::getInstance()->create(name);
31
32 enc->getProperties() = props;
33
34 if (maxLineLength != 0)
35 enc->getProperties()["maxlinelength"] = maxLineLength;
36
37 return enc;
38 }
39
40
41 // Encoding helper function
42 static const vmime::string encode(const vmime::string& name, const vmime::string& in,
43 int maxLineLength = 0, const vmime::propertySet props = vmime::propertySet())
44 {
45 vmime::shared_ptr <vmime::utility::encoder::encoder> enc = getEncoder(name, maxLineLength, props);
46
47 vmime::utility::inputStreamStringAdapter vin(in);
48
49 std::ostringstream out;
50 vmime::utility::outputStreamAdapter vout(out);
51
52 enc->encode(vin, vout);
53
54 return (out.str());
55 }
56
57
58 // Decoding helper function
59 static const vmime::string decode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0)
60 {
61 vmime::shared_ptr <vmime::utility::encoder::encoder> enc = getEncoder(name, maxLineLength);
62
63 vmime::utility::inputStreamStringAdapter vin(in);
64
65 std::ostringstream out;
66 vmime::utility::outputStreamAdapter vout(out);
67
68 enc->decode(vin, vout);
69
70 return (out.str());
71 }