Line |
Branch |
Exec |
Source |
1 |
|
|
/* GATE PROJECT LICENSE: |
2 |
|
|
+----------------------------------------------------------------------------+ |
3 |
|
|
| Copyright(c) 2018-2025, 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 |
|
|
|
29 |
|
|
#include "gate/net/pop3clients.hpp" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
namespace gate |
33 |
|
|
{ |
34 |
|
|
namespace net |
35 |
|
|
{ |
36 |
|
|
|
37 |
|
✗ |
Pop3Client::Pop3Client(Stream& pop3connection, String const& user, String const& pass) |
38 |
|
✗ |
: pop3stream(pop3connection) |
39 |
|
|
{ |
40 |
|
✗ |
result_t result = gate_pop3stream_init(this->pop3stream.c_impl()); |
41 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
42 |
|
|
|
43 |
|
✗ |
result = gate_pop3stream_login(this->pop3stream.c_impl(), user.c_impl(), pass.c_impl()); |
44 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
45 |
|
✗ |
} |
46 |
|
✗ |
Pop3Client::~Pop3Client() noexcept |
47 |
|
|
{ |
48 |
|
✗ |
gate_pop3stream_quit(this->pop3stream.c_impl()); |
49 |
|
✗ |
} |
50 |
|
|
|
51 |
|
✗ |
static void Pop3Client_listMessages_delegate(gate_int32_t id, gate_size_t length, void* param) |
52 |
|
|
{ |
53 |
|
✗ |
Delegate1<Pop3Client::MessageInfo const&> const* ptrCallback |
54 |
|
|
= reinterpret_cast<Delegate1<Pop3Client::MessageInfo const&> const*>(param); |
55 |
|
|
Pop3Client::MessageInfo info; |
56 |
|
✗ |
info.id = id; |
57 |
|
✗ |
info.length = static_cast<uint32_t>(length); |
58 |
|
✗ |
if (ptrCallback) |
59 |
|
|
{ |
60 |
|
✗ |
ptrCallback->tryInvoke(info); |
61 |
|
|
} |
62 |
|
✗ |
} |
63 |
|
|
|
64 |
|
✗ |
void Pop3Client::listMessages(Delegate1<MessageInfo const&>& callback) |
65 |
|
|
{ |
66 |
|
✗ |
result_t result = gate_pop3stream_list(this->pop3stream.c_impl(), &Pop3Client_listMessages_delegate, &callback); |
67 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
68 |
|
✗ |
} |
69 |
|
|
|
70 |
|
✗ |
static void Pop3Client_listMessages_array(gate_int32_t id, gate_size_t length, void* param) |
71 |
|
|
{ |
72 |
|
✗ |
ArrayList<Pop3Client::MessageInfo>* ptrList |
73 |
|
|
= reinterpret_cast<ArrayList<Pop3Client::MessageInfo>*>(param); |
74 |
|
|
Pop3Client::MessageInfo info; |
75 |
|
✗ |
info.id = id; |
76 |
|
✗ |
info.length = static_cast<uint32_t>(length); |
77 |
|
✗ |
if (ptrList) |
78 |
|
|
{ |
79 |
|
✗ |
ptrList->add(info); |
80 |
|
|
} |
81 |
|
✗ |
} |
82 |
|
|
|
83 |
|
✗ |
Array<Pop3Client::MessageInfo> Pop3Client::listMessages() |
84 |
|
|
{ |
85 |
|
✗ |
ArrayList<Pop3Client::MessageInfo> list; |
86 |
|
✗ |
result_t result = gate_pop3stream_list(this->pop3stream.c_impl(), &Pop3Client_listMessages_array, &list); |
87 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
88 |
|
✗ |
return list.toArray(); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
✗ |
void Pop3Client::retrieveMessage(int32_t id, Stream& mailoutstream) |
92 |
|
|
{ |
93 |
|
✗ |
result_t result = gate_pop3stream_retrieve(this->pop3stream.c_impl(), id, mailoutstream.c_impl()); |
94 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
95 |
|
✗ |
} |
96 |
|
|
|
97 |
|
✗ |
void Pop3Client::deleteMessage(int32_t id) |
98 |
|
|
{ |
99 |
|
✗ |
result_t result = gate_pop3stream_delete(this->pop3stream.c_impl(), id); |
100 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
101 |
|
✗ |
} |
102 |
|
|
|
103 |
|
✗ |
void Pop3Client::reset() |
104 |
|
|
{ |
105 |
|
✗ |
result_t result = gate_pop3stream_reset(this->pop3stream.c_impl()); |
106 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
107 |
|
✗ |
} |
108 |
|
|
|
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
} |
112 |
|
|
|