GCC Code Coverage Report


Directory: src/gate/
File: src/gate/net/cxx_emails.cpp
Date: 2026-10-19 17:06:30
Exec Total Coverage
Lines: 83 85 97.6%
Functions: 23 23 100.0%
Branches: 28 52 53.8%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28 #include "gate/net/emails.hpp"
29 #include "gate/exceptions.hpp"
30 #include "gate/utilities.hpp"
31
32 namespace gate
33 {
34 namespace net
35 {
36
37 3 MailMessage::MailMessage()
38 {
39 3 result_t result = gate_mail_message_create(&this->impl);
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATEXX_CHECK_ERROR(result);
41 3 }
42
43 2 MailMessage::MailMessage(MailMessage const& src)
44 {
45 2 result_t result = gate_mail_message_copy(&this->impl, &src.impl);
46
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(result);
47 2 }
48
49 1 MailMessage& MailMessage::operator=(MailMessage const& src)
50 {
51
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 MailMessage that(src);
52 1 this->swap(that);
53 2 return *this;
54 }
55
56 10 MailMessage::~MailMessage() noexcept
57 {
58 5 gate_mail_message_destroy(&this->impl);
59 5 }
60
61 1 void MailMessage::swap(MailMessage& that) noexcept
62 {
63 1 gate::swapRefsNoExcept(this->impl, that.impl);
64 1 }
65
66 1 gate_mail_message_t* MailMessage::c_impl() noexcept
67 {
68 1 return &this->impl;
69 }
70
71 1 gate_mail_message_t const* MailMessage::c_impl() const noexcept
72 {
73 1 return &this->impl;
74 }
75
76 4 MailMessage& MailMessage::setRecipient(String const& value, RecipientTypeEnum recipientType)
77 {
78 4 gate_mail_message_clear_recipients(&this->impl, static_cast<enumint_t>(recipientType));
79 4 return this->addRecipient(value, recipientType);
80 }
81
82 7 MailMessage& MailMessage::addRecipient(String const& value, RecipientTypeEnum recipientType)
83 {
84 7 const result_t result = gate_mail_message_add_recipient(&this->impl, value.c_impl(), static_cast<enumint_t>(recipientType));
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 GATEXX_CHECK_ERROR(result);
86 7 return *this;
87 }
88
89 9 void MailMessage::clearRecipients(RecipientTypeEnum recipientType)
90 {
91 9 const result_t result = gate_mail_message_clear_recipients(&this->impl, static_cast<enumint_t>(recipientType));
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 GATEXX_CHECK_ERROR(result);
93 9 }
94
95 3 MailMessage& MailMessage::setRecipients(Array<String> const& value, RecipientTypeEnum recipientType)
96 {
97 3 this->clearRecipients(recipientType);
98
2/2
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
6 GATEXX_ENUMERATE(String const, entry, value.enumerate())
99 {
100
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 const result_t result = gate_mail_message_add_recipient(&this->impl, entry->c_impl(), static_cast<enumint_t>(recipientType));
101
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
3 GATEXX_CHECK_ERROR(result);
102 }
103 3 return *this;
104 }
105
106 2 MailMessage& MailMessage::setSender(String const& value)
107 {
108 2 String::assign(this->impl.sender, value);
109 2 return *this;
110 }
111
112 2 MailMessage& MailMessage::setSubject(String const& value)
113 {
114 2 String::assign(this->impl.subject, value);
115 2 return *this;
116 }
117
118 2 MailMessage& MailMessage::setTextBody(String const& value)
119 {
120 2 String::assign(this->impl.text_body, value);
121 2 return *this;
122 }
123
124 2 MailMessage& MailMessage::setHtmlBody(String const& value)
125 {
126 2 String::assign(this->impl.html_body, value);
127 2 return *this;
128 }
129
130 1 String MailMessage::getSender() const
131 {
132 1 return String::clone(this->impl.sender);
133 }
134
135 1 String MailMessage::getSubject() const
136 {
137 1 return String::clone(this->impl.subject);
138 }
139
140 1 String MailMessage::getTextBody() const
141 {
142 1 return String::clone(this->impl.text_body);
143 }
144
145 1 String MailMessage::getHtmlBody() const
146 {
147 1 return String::clone(this->impl.html_body);
148 }
149
150 15 Array<String> MailMessage::getRecipients(RecipientTypeEnum recipientType) const
151 {
152 gate_arraylist_t const* ptr_lst;
153
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
15 switch(recipientType)
154 {
155 5 case Recipient_To: ptr_lst = &this->impl.recipients; break;
156 5 case Recipient_Cc: ptr_lst = &this->impl.recipients_cc; break;
157 5 case Recipient_Bcc: ptr_lst = &this->impl.recipients_bcc; break;
158 ✗ default: GATEXX_RAISE_ERROR(results::InvalidArg);
159 }
160
1/2
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
15 return util::convertStringArray(*ptr_lst).toArray();
161 }
162
163 2 MailMessage& MailMessage::addAttachment(String const& name, Stream& stream)
164 {
165 2 const result_t result = gate_mail_message_add_attachment(&this->impl, name.c_impl(), stream.c_impl());
166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(result);
167 2 return *this;
168 }
169
170 1 void MailMessage::clearAttachments()
171 {
172 1 gate_mail_message_clear_attachments(&this->impl);
173 1 }
174
175 3 Map<String, Stream> MailMessage::getAttachments()
176 {
177 3 Map<String, Stream> ret;
178 gate_map_iterator_t iter;
179
5/8
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 3 times.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
4 GATE_MAP_FOREACH(iter, &this->impl.attachments)
180 {
181
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_string_t const* ptr_name = (gate_string_t const*)gate_map_iterator_key(iter);
182
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_stream_t** ptr_stream = (gate_stream_t**)gate_map_iterator_value(iter);
183
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!ptr_name || !ptr_stream)
184 {
185 ✗ continue;
186 }
187
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 String name(*ptr_name);
188
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Stream stream(*ptr_stream);
189
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_object_retain(*ptr_stream);
190
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ret.add(name, stream);
191 }
192 3 return ret;
193 }
194
195
196 } // end of namespace net
197 } // end of namespace gate
198