Diffstat (limited to 'kmicromail/libetpan/generic/pop3driver_message.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libetpan/generic/pop3driver_message.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/kmicromail/libetpan/generic/pop3driver_message.c b/kmicromail/libetpan/generic/pop3driver_message.c index 77bd94c..357bb2e 100644 --- a/kmicromail/libetpan/generic/pop3driver_message.c +++ b/kmicromail/libetpan/generic/pop3driver_message.c | |||
@@ -30,24 +30,26 @@ | |||
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "pop3driver_message.h" | 36 | #include "pop3driver_message.h" |
37 | 37 | ||
38 | #include "mailmessage_tools.h" | 38 | #include "mailmessage_tools.h" |
39 | #include "pop3driver_tools.h" | 39 | #include "pop3driver_tools.h" |
40 | #include "pop3driver.h" | 40 | #include "pop3driver.h" |
41 | #include "mailpop3.h" | 41 | #include "mailpop3.h" |
42 | #include <stdlib.h> | ||
43 | #include <string.h> | ||
42 | 44 | ||
43 | static int pop3_prefetch(mailmessage * msg_info); | 45 | static int pop3_prefetch(mailmessage * msg_info); |
44 | 46 | ||
45 | static void pop3_prefetch_free(struct generic_message_t * msg); | 47 | static void pop3_prefetch_free(struct generic_message_t * msg); |
46 | 48 | ||
47 | static int pop3_initialize(mailmessage * msg_info); | 49 | static int pop3_initialize(mailmessage * msg_info); |
48 | 50 | ||
49 | static int pop3_fetch_header(mailmessage * msg_info, | 51 | static int pop3_fetch_header(mailmessage * msg_info, |
50 | char ** result, | 52 | char ** result, |
51 | size_t * result_len); | 53 | size_t * result_len); |
52 | 54 | ||
53 | static int pop3_fetch_size(mailmessage * msg_info, | 55 | static int pop3_fetch_size(mailmessage * msg_info, |
@@ -71,24 +73,36 @@ static mailmessage_driver local_pop3_message_driver = { | |||
71 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, | 73 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, |
72 | .msg_fetch_section = mailmessage_generic_fetch_section, | 74 | .msg_fetch_section = mailmessage_generic_fetch_section, |
73 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, | 75 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, |
74 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, | 76 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, |
75 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, | 77 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, |
76 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, | 78 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, |
77 | 79 | ||
78 | .msg_get_flags = NULL, | 80 | .msg_get_flags = NULL, |
79 | }; | 81 | }; |
80 | 82 | ||
81 | mailmessage_driver * pop3_message_driver = &local_pop3_message_driver; | 83 | mailmessage_driver * pop3_message_driver = &local_pop3_message_driver; |
82 | 84 | ||
85 | static inline struct pop3_session_state_data * | ||
86 | get_data(mailsession * session) | ||
87 | { | ||
88 | return session->sess_data; | ||
89 | } | ||
90 | |||
91 | |||
92 | static mailpop3 * get_pop3_session(mailsession * session) | ||
93 | { | ||
94 | return get_data(session)->pop3_session; | ||
95 | } | ||
96 | |||
83 | 97 | ||
84 | static int pop3_prefetch(mailmessage * msg_info) | 98 | static int pop3_prefetch(mailmessage * msg_info) |
85 | { | 99 | { |
86 | char * msg_content; | 100 | char * msg_content; |
87 | size_t msg_length; | 101 | size_t msg_length; |
88 | struct generic_message_t * msg; | 102 | struct generic_message_t * msg; |
89 | int r; | 103 | int r; |
90 | 104 | ||
91 | r = pop3driver_retr(msg_info->msg_session, msg_info->msg_index, | 105 | r = pop3driver_retr(msg_info->msg_session, msg_info->msg_index, |
92 | &msg_content, &msg_length); | 106 | &msg_content, &msg_length); |
93 | if (r != MAIL_NO_ERROR) | 107 | if (r != MAIL_NO_ERROR) |
94 | return r; | 108 | return r; |
@@ -104,32 +118,52 @@ static int pop3_prefetch(mailmessage * msg_info) | |||
104 | static void pop3_prefetch_free(struct generic_message_t * msg) | 118 | static void pop3_prefetch_free(struct generic_message_t * msg) |
105 | { | 119 | { |
106 | if (msg->msg_message != NULL) { | 120 | if (msg->msg_message != NULL) { |
107 | mmap_string_unref(msg->msg_message); | 121 | mmap_string_unref(msg->msg_message); |
108 | msg->msg_message = NULL; | 122 | msg->msg_message = NULL; |
109 | } | 123 | } |
110 | } | 124 | } |
111 | 125 | ||
112 | static int pop3_initialize(mailmessage * msg_info) | 126 | static int pop3_initialize(mailmessage * msg_info) |
113 | { | 127 | { |
114 | struct generic_message_t * msg; | 128 | struct generic_message_t * msg; |
115 | int r; | 129 | int r; |
130 | char * uid; | ||
131 | struct mailpop3_msg_info * info; | ||
132 | mailpop3 * pop3; | ||
133 | |||
134 | pop3 = get_pop3_session(msg_info->msg_session); | ||
135 | |||
136 | r = mailpop3_get_msg_info(pop3, msg_info->msg_index, &info); | ||
137 | switch (r) { | ||
138 | case MAILPOP3_NO_ERROR: | ||
139 | break; | ||
140 | default: | ||
141 | return pop3driver_pop3_error_to_mail_error(r); | ||
142 | } | ||
143 | |||
144 | uid = strdup(info->msg_uidl); | ||
145 | if (uid == NULL) | ||
146 | return MAIL_ERROR_MEMORY; | ||
116 | 147 | ||
117 | r = mailmessage_generic_initialize(msg_info); | 148 | r = mailmessage_generic_initialize(msg_info); |
118 | if (r != MAIL_NO_ERROR) | 149 | if (r != MAIL_NO_ERROR) { |
150 | free(uid); | ||
119 | return r; | 151 | return r; |
152 | } | ||
120 | 153 | ||
121 | msg = msg_info->msg_data; | 154 | msg = msg_info->msg_data; |
122 | msg->msg_prefetch = pop3_prefetch; | 155 | msg->msg_prefetch = pop3_prefetch; |
123 | msg->msg_prefetch_free = pop3_prefetch_free; | 156 | msg->msg_prefetch_free = pop3_prefetch_free; |
157 | msg_info->msg_uid = uid; | ||
124 | 158 | ||
125 | return MAIL_NO_ERROR; | 159 | return MAIL_NO_ERROR; |
126 | } | 160 | } |
127 | 161 | ||
128 | 162 | ||
129 | static int pop3_fetch_header(mailmessage * msg_info, | 163 | static int pop3_fetch_header(mailmessage * msg_info, |
130 | char ** result, | 164 | char ** result, |
131 | size_t * result_len) | 165 | size_t * result_len) |
132 | { | 166 | { |
133 | struct generic_message_t * msg; | 167 | struct generic_message_t * msg; |
134 | char * headers; | 168 | char * headers; |
135 | size_t headers_length; | 169 | size_t headers_length; |