Diffstat (limited to 'kmicromail/libetpan/generic/pop3driver_message.c') (more/less context) (show whitespace changes)
-rw-r--r-- | kmicromail/libetpan/generic/pop3driver_message.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/kmicromail/libetpan/generic/pop3driver_message.c b/kmicromail/libetpan/generic/pop3driver_message.c new file mode 100644 index 0000000..77bd94c --- a/dev/null +++ b/kmicromail/libetpan/generic/pop3driver_message.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | * libEtPan! -- a mail stuff library | ||
3 | * | ||
4 | * Copyright (C) 2001, 2002 - DINH Viet Hoa | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. Neither the name of the libEtPan! project nor the names of its | ||
16 | * contributors may be used to endorse or promote products derived | ||
17 | * from this software without specific prior written permission. | ||
18 | * | ||
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
29 | * SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * $Id$ | ||
34 | */ | ||
35 | |||
36 | #include "pop3driver_message.h" | ||
37 | |||
38 | #include "mailmessage_tools.h" | ||
39 | #include "pop3driver_tools.h" | ||
40 | #include "pop3driver.h" | ||
41 | #include "mailpop3.h" | ||
42 | |||
43 | static int pop3_prefetch(mailmessage * msg_info); | ||
44 | |||
45 | static void pop3_prefetch_free(struct generic_message_t * msg); | ||
46 | |||
47 | static int pop3_initialize(mailmessage * msg_info); | ||
48 | |||
49 | static int pop3_fetch_header(mailmessage * msg_info, | ||
50 | char ** result, | ||
51 | size_t * result_len); | ||
52 | |||
53 | static int pop3_fetch_size(mailmessage * msg_info, | ||
54 | size_t * result); | ||
55 | |||
56 | static mailmessage_driver local_pop3_message_driver = { | ||
57 | .msg_name = "pop3", | ||
58 | |||
59 | .msg_initialize = pop3_initialize, | ||
60 | .msg_uninitialize = mailmessage_generic_uninitialize, | ||
61 | |||
62 | .msg_flush = mailmessage_generic_flush, | ||
63 | .msg_check = NULL, | ||
64 | |||
65 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, | ||
66 | |||
67 | .msg_fetch = mailmessage_generic_fetch, | ||
68 | .msg_fetch_header = pop3_fetch_header, | ||
69 | .msg_fetch_body = mailmessage_generic_fetch_body, | ||
70 | .msg_fetch_size = pop3_fetch_size, | ||
71 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, | ||
72 | .msg_fetch_section = mailmessage_generic_fetch_section, | ||
73 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, | ||
74 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, | ||
75 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, | ||
76 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, | ||
77 | |||
78 | .msg_get_flags = NULL, | ||
79 | }; | ||
80 | |||
81 | mailmessage_driver * pop3_message_driver = &local_pop3_message_driver; | ||
82 | |||
83 | |||
84 | static int pop3_prefetch(mailmessage * msg_info) | ||
85 | { | ||
86 | char * msg_content; | ||
87 | size_t msg_length; | ||
88 | struct generic_message_t * msg; | ||
89 | int r; | ||
90 | |||
91 | r = pop3driver_retr(msg_info->msg_session, msg_info->msg_index, | ||
92 | &msg_content, &msg_length); | ||
93 | if (r != MAIL_NO_ERROR) | ||
94 | return r; | ||
95 | |||
96 | msg = msg_info->msg_data; | ||
97 | |||
98 | msg->msg_message = msg_content; | ||
99 | msg->msg_length = msg_length; | ||
100 | |||
101 | return MAIL_NO_ERROR; | ||
102 | } | ||
103 | |||
104 | static void pop3_prefetch_free(struct generic_message_t * msg) | ||
105 | { | ||
106 | if (msg->msg_message != NULL) { | ||
107 | mmap_string_unref(msg->msg_message); | ||
108 | msg->msg_message = NULL; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | static int pop3_initialize(mailmessage * msg_info) | ||
113 | { | ||
114 | struct generic_message_t * msg; | ||
115 | int r; | ||
116 | |||
117 | r = mailmessage_generic_initialize(msg_info); | ||
118 | if (r != MAIL_NO_ERROR) | ||
119 | return r; | ||
120 | |||
121 | msg = msg_info->msg_data; | ||
122 | msg->msg_prefetch = pop3_prefetch; | ||
123 | msg->msg_prefetch_free = pop3_prefetch_free; | ||
124 | |||
125 | return MAIL_NO_ERROR; | ||
126 | } | ||
127 | |||
128 | |||
129 | static int pop3_fetch_header(mailmessage * msg_info, | ||
130 | char ** result, | ||
131 | size_t * result_len) | ||
132 | { | ||
133 | struct generic_message_t * msg; | ||
134 | char * headers; | ||
135 | size_t headers_length; | ||
136 | int r; | ||
137 | |||
138 | msg = msg_info->msg_data; | ||
139 | |||
140 | if (msg->msg_message != NULL) | ||
141 | return mailmessage_generic_fetch_header(msg_info, | ||
142 | result, result_len); | ||
143 | |||
144 | r = pop3driver_header(msg_info->msg_session, msg_info->msg_index, | ||
145 | &headers, &headers_length); | ||
146 | if (r != MAIL_NO_ERROR) | ||
147 | return r; | ||
148 | |||
149 | * result = headers; | ||
150 | * result_len = headers_length; | ||
151 | |||
152 | return MAIL_NO_ERROR; | ||
153 | } | ||
154 | |||
155 | static int pop3_fetch_size(mailmessage * msg_info, | ||
156 | size_t * result) | ||
157 | { | ||
158 | return pop3driver_size(msg_info->msg_session, msg_info->msg_index, result); | ||
159 | } | ||