68 files changed, 1025 insertions, 112 deletions
diff --git a/kmicromail/libetpan/generic/imapdriver.c b/kmicromail/libetpan/generic/imapdriver.c index 0d63319..b3e5982 100644 --- a/kmicromail/libetpan/generic/imapdriver.c +++ b/kmicromail/libetpan/generic/imapdriver.c | |||
@@ -71,121 +71,124 @@ static int imapdriver_delete_folder(mailsession * session, char * mb); | |||
71 | 71 | ||
72 | static int imapdriver_rename_folder(mailsession * session, char * mb, | 72 | static int imapdriver_rename_folder(mailsession * session, char * mb, |
73 | char * new_name); | 73 | char * new_name); |
74 | 74 | ||
75 | static int imapdriver_check_folder(mailsession * session); | 75 | static int imapdriver_check_folder(mailsession * session); |
76 | 76 | ||
77 | static int imapdriver_examine_folder(mailsession * session, char * mb); | 77 | static int imapdriver_examine_folder(mailsession * session, char * mb); |
78 | 78 | ||
79 | static int imapdriver_select_folder(mailsession * session, char * mb); | 79 | static int imapdriver_select_folder(mailsession * session, char * mb); |
80 | static int imapdriver_expunge_folder(mailsession * session); | 80 | static int imapdriver_expunge_folder(mailsession * session); |
81 | 81 | ||
82 | static int imapdriver_status_folder(mailsession * session, char * mb, | 82 | static int imapdriver_status_folder(mailsession * session, char * mb, |
83 | uint32_t * result_messages, uint32_t * result_recent, | 83 | uint32_t * result_messages, uint32_t * result_recent, |
84 | uint32_t * result_unseen); | 84 | uint32_t * result_unseen); |
85 | 85 | ||
86 | static int imapdriver_messages_number(mailsession * session, char * mb, | 86 | static int imapdriver_messages_number(mailsession * session, char * mb, |
87 | uint32_t * result); | 87 | uint32_t * result); |
88 | 88 | ||
89 | static int imapdriver_recent_number(mailsession * session, char * mb, | 89 | static int imapdriver_recent_number(mailsession * session, char * mb, |
90 | uint32_t * result); | 90 | uint32_t * result); |
91 | 91 | ||
92 | static int imapdriver_unseen_number(mailsession * session, char * mb, | 92 | static int imapdriver_unseen_number(mailsession * session, char * mb, |
93 | uint32_t * result); | 93 | uint32_t * result); |
94 | 94 | ||
95 | static int imapdriver_list_folders(mailsession * session, char * mb, | 95 | static int imapdriver_list_folders(mailsession * session, char * mb, |
96 | struct mail_list ** result); | 96 | struct mail_list ** result); |
97 | static int imapdriver_lsub_folders(mailsession * session, char * mb, | 97 | static int imapdriver_lsub_folders(mailsession * session, char * mb, |
98 | struct mail_list ** result); | 98 | struct mail_list ** result); |
99 | static int imapdriver_subscribe_folder(mailsession * session, char * mb); | 99 | static int imapdriver_subscribe_folder(mailsession * session, char * mb); |
100 | static int imapdriver_unsubscribe_folder(mailsession * session, char * mb); | 100 | static int imapdriver_unsubscribe_folder(mailsession * session, char * mb); |
101 | static int imapdriver_append_message(mailsession * session, | 101 | static int imapdriver_append_message(mailsession * session, |
102 | char * message, size_t size); | 102 | char * message, size_t size); |
103 | static int imapdriver_append_message_flags(mailsession * session, | ||
104 | char * message, size_t size, struct mail_flags * flags); | ||
103 | static int imapdriver_copy_message(mailsession * session, | 105 | static int imapdriver_copy_message(mailsession * session, |
104 | uint32_t num, char * mb); | 106 | uint32_t num, char * mb); |
105 | 107 | ||
106 | static int imapdriver_get_messages_list(mailsession * session, | 108 | static int imapdriver_get_messages_list(mailsession * session, |
107 | struct mailmessage_list ** result); | 109 | struct mailmessage_list ** result); |
108 | 110 | ||
109 | static int | 111 | static int |
110 | imapdriver_get_envelopes_list(mailsession * session, | 112 | imapdriver_get_envelopes_list(mailsession * session, |
111 | struct mailmessage_list * env_list); | 113 | struct mailmessage_list * env_list); |
112 | 114 | ||
113 | 115 | ||
114 | #if 0 | 116 | #if 0 |
115 | static int imapdriver_search_messages(mailsession * session, char * charset, | 117 | static int imapdriver_search_messages(mailsession * session, char * charset, |
116 | struct mail_search_key * key, | 118 | struct mail_search_key * key, |
117 | struct mail_search_result ** result); | 119 | struct mail_search_result ** result); |
118 | #endif | 120 | #endif |
119 | 121 | ||
120 | static int imapdriver_get_message(mailsession * session, | 122 | static int imapdriver_get_message(mailsession * session, |
121 | uint32_t num, mailmessage ** result); | 123 | uint32_t num, mailmessage ** result); |
122 | 124 | ||
123 | static int imapdriver_get_message_by_uid(mailsession * session, | 125 | static int imapdriver_get_message_by_uid(mailsession * session, |
124 | const char * uid, | 126 | const char * uid, |
125 | mailmessage ** result); | 127 | mailmessage ** result); |
126 | 128 | ||
127 | static mailsession_driver local_imap_session_driver = { | 129 | static mailsession_driver local_imap_session_driver = { |
128 | .sess_name = "imap", | 130 | .sess_name = "imap", |
129 | 131 | ||
130 | .sess_initialize = imapdriver_initialize, | 132 | .sess_initialize = imapdriver_initialize, |
131 | .sess_uninitialize = imapdriver_uninitialize, | 133 | .sess_uninitialize = imapdriver_uninitialize, |
132 | 134 | ||
133 | .sess_parameters = NULL, | 135 | .sess_parameters = NULL, |
134 | 136 | ||
135 | .sess_connect_stream = imapdriver_connect_stream, | 137 | .sess_connect_stream = imapdriver_connect_stream, |
136 | .sess_connect_path = NULL, | 138 | .sess_connect_path = NULL, |
137 | .sess_starttls = imapdriver_starttls, | 139 | .sess_starttls = imapdriver_starttls, |
138 | .sess_login = imapdriver_login, | 140 | .sess_login = imapdriver_login, |
139 | .sess_logout = imapdriver_logout, | 141 | .sess_logout = imapdriver_logout, |
140 | .sess_noop = imapdriver_noop, | 142 | .sess_noop = imapdriver_noop, |
141 | 143 | ||
142 | .sess_build_folder_name = imapdriver_build_folder_name, | 144 | .sess_build_folder_name = imapdriver_build_folder_name, |
143 | .sess_create_folder = imapdriver_create_folder, | 145 | .sess_create_folder = imapdriver_create_folder, |
144 | .sess_delete_folder = imapdriver_delete_folder, | 146 | .sess_delete_folder = imapdriver_delete_folder, |
145 | .sess_rename_folder = imapdriver_rename_folder, | 147 | .sess_rename_folder = imapdriver_rename_folder, |
146 | .sess_check_folder = imapdriver_check_folder, | 148 | .sess_check_folder = imapdriver_check_folder, |
147 | .sess_examine_folder = imapdriver_examine_folder, | 149 | .sess_examine_folder = imapdriver_examine_folder, |
148 | .sess_select_folder = imapdriver_select_folder, | 150 | .sess_select_folder = imapdriver_select_folder, |
149 | .sess_expunge_folder = imapdriver_expunge_folder, | 151 | .sess_expunge_folder = imapdriver_expunge_folder, |
150 | .sess_status_folder = imapdriver_status_folder, | 152 | .sess_status_folder = imapdriver_status_folder, |
151 | .sess_messages_number = imapdriver_messages_number, | 153 | .sess_messages_number = imapdriver_messages_number, |
152 | .sess_recent_number = imapdriver_recent_number, | 154 | .sess_recent_number = imapdriver_recent_number, |
153 | .sess_unseen_number = imapdriver_unseen_number, | 155 | .sess_unseen_number = imapdriver_unseen_number, |
154 | .sess_list_folders = imapdriver_list_folders, | 156 | .sess_list_folders = imapdriver_list_folders, |
155 | .sess_lsub_folders = imapdriver_lsub_folders, | 157 | .sess_lsub_folders = imapdriver_lsub_folders, |
156 | .sess_subscribe_folder = imapdriver_subscribe_folder, | 158 | .sess_subscribe_folder = imapdriver_subscribe_folder, |
157 | .sess_unsubscribe_folder = imapdriver_unsubscribe_folder, | 159 | .sess_unsubscribe_folder = imapdriver_unsubscribe_folder, |
158 | 160 | ||
159 | .sess_append_message = imapdriver_append_message, | 161 | .sess_append_message = imapdriver_append_message, |
162 | .sess_append_message_flags = imapdriver_append_message_flags, | ||
160 | .sess_copy_message = imapdriver_copy_message, | 163 | .sess_copy_message = imapdriver_copy_message, |
161 | .sess_move_message = NULL, | 164 | .sess_move_message = NULL, |
162 | 165 | ||
163 | .sess_get_messages_list = imapdriver_get_messages_list, | 166 | .sess_get_messages_list = imapdriver_get_messages_list, |
164 | .sess_get_envelopes_list = imapdriver_get_envelopes_list, | 167 | .sess_get_envelopes_list = imapdriver_get_envelopes_list, |
165 | .sess_remove_message = NULL, | 168 | .sess_remove_message = NULL, |
166 | #if 0 | 169 | #if 0 |
167 | .sess_search_messages = imapdriver_search_messages, | 170 | .sess_search_messages = imapdriver_search_messages, |
168 | #endif | 171 | #endif |
169 | 172 | ||
170 | .sess_get_message = imapdriver_get_message, | 173 | .sess_get_message = imapdriver_get_message, |
171 | .sess_get_message_by_uid = imapdriver_get_message_by_uid, | 174 | .sess_get_message_by_uid = imapdriver_get_message_by_uid, |
172 | }; | 175 | }; |
173 | 176 | ||
174 | mailsession_driver * imap_session_driver = &local_imap_session_driver; | 177 | mailsession_driver * imap_session_driver = &local_imap_session_driver; |
175 | 178 | ||
176 | static inline struct imap_session_state_data * get_data(mailsession * session) | 179 | static inline struct imap_session_state_data * get_data(mailsession * session) |
177 | { | 180 | { |
178 | return session->sess_data; | 181 | return session->sess_data; |
179 | } | 182 | } |
180 | 183 | ||
181 | static mailimap * get_imap_session(mailsession * session) | 184 | static mailimap * get_imap_session(mailsession * session) |
182 | { | 185 | { |
183 | return get_data(session)->imap_session; | 186 | return get_data(session)->imap_session; |
184 | } | 187 | } |
185 | 188 | ||
186 | static int imapdriver_initialize(mailsession * session) | 189 | static int imapdriver_initialize(mailsession * session) |
187 | { | 190 | { |
188 | struct imap_session_state_data * data; | 191 | struct imap_session_state_data * data; |
189 | mailimap * imap; | 192 | mailimap * imap; |
190 | struct mail_flags_store * flags_store; | 193 | struct mail_flags_store * flags_store; |
191 | 194 | ||
@@ -742,64 +745,89 @@ static int imapdriver_lsub_folders(mailsession * session, char * mb, | |||
742 | static int imapdriver_subscribe_folder(mailsession * session, char * mb) | 745 | static int imapdriver_subscribe_folder(mailsession * session, char * mb) |
743 | { | 746 | { |
744 | int r; | 747 | int r; |
745 | 748 | ||
746 | r = mailimap_subscribe(get_imap_session(session), mb); | 749 | r = mailimap_subscribe(get_imap_session(session), mb); |
747 | 750 | ||
748 | return imap_error_to_mail_error(r); | 751 | return imap_error_to_mail_error(r); |
749 | } | 752 | } |
750 | 753 | ||
751 | static int imapdriver_unsubscribe_folder(mailsession * session, char * mb) | 754 | static int imapdriver_unsubscribe_folder(mailsession * session, char * mb) |
752 | { | 755 | { |
753 | int r; | 756 | int r; |
754 | 757 | ||
755 | r = mailimap_unsubscribe(get_imap_session(session), mb); | 758 | r = mailimap_unsubscribe(get_imap_session(session), mb); |
756 | 759 | ||
757 | return imap_error_to_mail_error(r); | 760 | return imap_error_to_mail_error(r); |
758 | } | 761 | } |
759 | 762 | ||
760 | /* messages operations */ | 763 | /* messages operations */ |
761 | 764 | ||
762 | static int imapdriver_append_message(mailsession * session, | 765 | static int imapdriver_append_message(mailsession * session, |
763 | char * message, size_t size) | 766 | char * message, size_t size) |
764 | { | 767 | { |
765 | int r; | 768 | int r; |
766 | 769 | ||
767 | r = mailimap_append_simple(get_imap_session(session), | 770 | r = mailimap_append_simple(get_imap_session(session), |
768 | get_data(session)->imap_mailbox, | 771 | get_data(session)->imap_mailbox, |
769 | message, size); | 772 | message, size); |
770 | 773 | ||
771 | return imap_error_to_mail_error(r); | 774 | return imap_error_to_mail_error(r); |
772 | } | 775 | } |
773 | 776 | ||
777 | static int imapdriver_append_message_flags(mailsession * session, | ||
778 | char * message, size_t size, struct mail_flags * flags) | ||
779 | { | ||
780 | struct mailimap_flag_list * flag_list; | ||
781 | int r; | ||
782 | |||
783 | if (flags != NULL) { | ||
784 | r = imap_flags_to_imap_flags(flags, &flag_list); | ||
785 | if (r != MAIL_NO_ERROR) | ||
786 | return r; | ||
787 | } | ||
788 | else { | ||
789 | flag_list = NULL; | ||
790 | } | ||
791 | |||
792 | r = mailimap_append(get_imap_session(session), | ||
793 | get_data(session)->imap_mailbox, | ||
794 | flag_list, NULL, message, size); | ||
795 | |||
796 | if (flag_list != NULL) | ||
797 | mailimap_flag_list_free(flag_list); | ||
798 | |||
799 | return imap_error_to_mail_error(r); | ||
800 | } | ||
801 | |||
774 | static int imapdriver_copy_message(mailsession * session, | 802 | static int imapdriver_copy_message(mailsession * session, |
775 | uint32_t num, char * mb) | 803 | uint32_t num, char * mb) |
776 | { | 804 | { |
777 | int r; | 805 | int r; |
778 | struct mailimap_set * set; | 806 | struct mailimap_set * set; |
779 | int res; | 807 | int res; |
780 | 808 | ||
781 | set = mailimap_set_new_single(num); | 809 | set = mailimap_set_new_single(num); |
782 | if (set == NULL) { | 810 | if (set == NULL) { |
783 | res = MAIL_ERROR_MEMORY; | 811 | res = MAIL_ERROR_MEMORY; |
784 | goto err; | 812 | goto err; |
785 | } | 813 | } |
786 | 814 | ||
787 | r = mailimap_uid_copy(get_imap_session(session), set, mb); | 815 | r = mailimap_uid_copy(get_imap_session(session), set, mb); |
788 | 816 | ||
789 | mailimap_set_free(set); | 817 | mailimap_set_free(set); |
790 | 818 | ||
791 | return imap_error_to_mail_error(r); | 819 | return imap_error_to_mail_error(r); |
792 | 820 | ||
793 | err: | 821 | err: |
794 | return res; | 822 | return res; |
795 | } | 823 | } |
796 | 824 | ||
797 | static int imapdriver_get_messages_list(mailsession * session, | 825 | static int imapdriver_get_messages_list(mailsession * session, |
798 | struct mailmessage_list ** result) | 826 | struct mailmessage_list ** result) |
799 | { | 827 | { |
800 | return imap_get_messages_list(get_imap_session(session), | 828 | return imap_get_messages_list(get_imap_session(session), |
801 | session, imap_message_driver, 1, | 829 | session, imap_message_driver, 1, |
802 | result); | 830 | result); |
803 | } | 831 | } |
804 | 832 | ||
805 | 833 | ||
diff --git a/kmicromail/libetpan/generic/imapdriver_cached.c b/kmicromail/libetpan/generic/imapdriver_cached.c index e6af8e8..04044ae 100644 --- a/kmicromail/libetpan/generic/imapdriver_cached.c +++ b/kmicromail/libetpan/generic/imapdriver_cached.c | |||
@@ -76,124 +76,127 @@ static int imapdriver_cached_build_folder_name(mailsession * session, | |||
76 | char * mb, | 76 | char * mb, |
77 | char * name, char ** result); | 77 | char * name, char ** result); |
78 | static int imapdriver_cached_create_folder(mailsession * session, char * mb); | 78 | static int imapdriver_cached_create_folder(mailsession * session, char * mb); |
79 | static int imapdriver_cached_delete_folder(mailsession * session, char * mb); | 79 | static int imapdriver_cached_delete_folder(mailsession * session, char * mb); |
80 | static int imapdriver_cached_rename_folder(mailsession * session, char * mb, | 80 | static int imapdriver_cached_rename_folder(mailsession * session, char * mb, |
81 | char * new_name); | 81 | char * new_name); |
82 | static int imapdriver_cached_check_folder(mailsession * session); | 82 | static int imapdriver_cached_check_folder(mailsession * session); |
83 | static int imapdriver_cached_examine_folder(mailsession * session, | 83 | static int imapdriver_cached_examine_folder(mailsession * session, |
84 | char * mb); | 84 | char * mb); |
85 | static int imapdriver_cached_select_folder(mailsession * session, char * mb); | 85 | static int imapdriver_cached_select_folder(mailsession * session, char * mb); |
86 | static int imapdriver_cached_expunge_folder(mailsession * session); | 86 | static int imapdriver_cached_expunge_folder(mailsession * session); |
87 | static int imapdriver_cached_status_folder(mailsession * session, char * mb, | 87 | static int imapdriver_cached_status_folder(mailsession * session, char * mb, |
88 | uint32_t * result_messages, | 88 | uint32_t * result_messages, |
89 | uint32_t * result_recent, | 89 | uint32_t * result_recent, |
90 | uint32_t * result_unseen); | 90 | uint32_t * result_unseen); |
91 | static int imapdriver_cached_messages_number(mailsession * session, | 91 | static int imapdriver_cached_messages_number(mailsession * session, |
92 | char * mb, | 92 | char * mb, |
93 | uint32_t * result); | 93 | uint32_t * result); |
94 | static int imapdriver_cached_recent_number(mailsession * session, char * mb, | 94 | static int imapdriver_cached_recent_number(mailsession * session, char * mb, |
95 | uint32_t * result); | 95 | uint32_t * result); |
96 | static int imapdriver_cached_unseen_number(mailsession * session, char * mb, | 96 | static int imapdriver_cached_unseen_number(mailsession * session, char * mb, |
97 | uint32_t * result); | 97 | uint32_t * result); |
98 | static int imapdriver_cached_list_folders(mailsession * session, char * mb, | 98 | static int imapdriver_cached_list_folders(mailsession * session, char * mb, |
99 | struct mail_list ** result); | 99 | struct mail_list ** result); |
100 | static int imapdriver_cached_lsub_folders(mailsession * session, char * mb, | 100 | static int imapdriver_cached_lsub_folders(mailsession * session, char * mb, |
101 | struct mail_list ** result); | 101 | struct mail_list ** result); |
102 | static int imapdriver_cached_subscribe_folder(mailsession * session, | 102 | static int imapdriver_cached_subscribe_folder(mailsession * session, |
103 | char * mb); | 103 | char * mb); |
104 | static int imapdriver_cached_unsubscribe_folder(mailsession * session, | 104 | static int imapdriver_cached_unsubscribe_folder(mailsession * session, |
105 | char * mb); | 105 | char * mb); |
106 | static int imapdriver_cached_append_message(mailsession * session, | 106 | static int imapdriver_cached_append_message(mailsession * session, |
107 | char * message, size_t size); | 107 | char * message, size_t size); |
108 | static int imapdriver_cached_append_message_flags(mailsession * session, | ||
109 | char * message, size_t size, struct mail_flags * flags); | ||
108 | static int imapdriver_cached_copy_message(mailsession * session, | 110 | static int imapdriver_cached_copy_message(mailsession * session, |
109 | uint32_t num, char * mb); | 111 | uint32_t num, char * mb); |
110 | 112 | ||
111 | static int imapdriver_cached_get_messages_list(mailsession * session, | 113 | static int imapdriver_cached_get_messages_list(mailsession * session, |
112 | struct mailmessage_list ** | 114 | struct mailmessage_list ** |
113 | result); | 115 | result); |
114 | static int | 116 | static int |
115 | imapdriver_cached_get_envelopes_list(mailsession * session, | 117 | imapdriver_cached_get_envelopes_list(mailsession * session, |
116 | struct mailmessage_list * env_list); | 118 | struct mailmessage_list * env_list); |
117 | static int imapdriver_cached_remove_message(mailsession * session, | 119 | static int imapdriver_cached_remove_message(mailsession * session, |
118 | uint32_t num); | 120 | uint32_t num); |
119 | 121 | ||
120 | #if 0 | 122 | #if 0 |
121 | static int imapdriver_cached_search_messages(mailsession * session, | 123 | static int imapdriver_cached_search_messages(mailsession * session, |
122 | char * charset, | 124 | char * charset, |
123 | struct mail_search_key * key, | 125 | struct mail_search_key * key, |
124 | struct mail_search_result ** | 126 | struct mail_search_result ** |
125 | result); | 127 | result); |
126 | #endif | 128 | #endif |
127 | 129 | ||
128 | static int imapdriver_cached_get_message(mailsession * session, | 130 | static int imapdriver_cached_get_message(mailsession * session, |
129 | uint32_t num, mailmessage ** result); | 131 | uint32_t num, mailmessage ** result); |
130 | 132 | ||
131 | static int imapdriver_cached_get_message_by_uid(mailsession * session, | 133 | static int imapdriver_cached_get_message_by_uid(mailsession * session, |
132 | const char * uid, | 134 | const char * uid, |
133 | mailmessage ** result); | 135 | mailmessage ** result); |
134 | 136 | ||
135 | static mailsession_driver local_imap_cached_session_driver = { | 137 | static mailsession_driver local_imap_cached_session_driver = { |
136 | .sess_name = "imap-cached", | 138 | .sess_name = "imap-cached", |
137 | 139 | ||
138 | .sess_initialize = imapdriver_cached_initialize, | 140 | .sess_initialize = imapdriver_cached_initialize, |
139 | .sess_uninitialize = imapdriver_cached_uninitialize, | 141 | .sess_uninitialize = imapdriver_cached_uninitialize, |
140 | 142 | ||
141 | .sess_parameters = imapdriver_cached_parameters, | 143 | .sess_parameters = imapdriver_cached_parameters, |
142 | 144 | ||
143 | .sess_connect_stream = imapdriver_cached_connect_stream, | 145 | .sess_connect_stream = imapdriver_cached_connect_stream, |
144 | .sess_connect_path = NULL, | 146 | .sess_connect_path = NULL, |
145 | .sess_starttls = imapdriver_cached_starttls, | 147 | .sess_starttls = imapdriver_cached_starttls, |
146 | .sess_login = imapdriver_cached_login, | 148 | .sess_login = imapdriver_cached_login, |
147 | .sess_logout = imapdriver_cached_logout, | 149 | .sess_logout = imapdriver_cached_logout, |
148 | .sess_noop = imapdriver_cached_noop, | 150 | .sess_noop = imapdriver_cached_noop, |
149 | 151 | ||
150 | .sess_build_folder_name = imapdriver_cached_build_folder_name, | 152 | .sess_build_folder_name = imapdriver_cached_build_folder_name, |
151 | .sess_create_folder = imapdriver_cached_create_folder, | 153 | .sess_create_folder = imapdriver_cached_create_folder, |
152 | .sess_delete_folder = imapdriver_cached_delete_folder, | 154 | .sess_delete_folder = imapdriver_cached_delete_folder, |
153 | .sess_rename_folder = imapdriver_cached_rename_folder, | 155 | .sess_rename_folder = imapdriver_cached_rename_folder, |
154 | .sess_check_folder = imapdriver_cached_check_folder, | 156 | .sess_check_folder = imapdriver_cached_check_folder, |
155 | .sess_examine_folder = imapdriver_cached_examine_folder, | 157 | .sess_examine_folder = imapdriver_cached_examine_folder, |
156 | .sess_select_folder = imapdriver_cached_select_folder, | 158 | .sess_select_folder = imapdriver_cached_select_folder, |
157 | .sess_expunge_folder = imapdriver_cached_expunge_folder, | 159 | .sess_expunge_folder = imapdriver_cached_expunge_folder, |
158 | .sess_status_folder = imapdriver_cached_status_folder, | 160 | .sess_status_folder = imapdriver_cached_status_folder, |
159 | .sess_messages_number = imapdriver_cached_messages_number, | 161 | .sess_messages_number = imapdriver_cached_messages_number, |
160 | .sess_recent_number = imapdriver_cached_recent_number, | 162 | .sess_recent_number = imapdriver_cached_recent_number, |
161 | .sess_unseen_number = imapdriver_cached_unseen_number, | 163 | .sess_unseen_number = imapdriver_cached_unseen_number, |
162 | .sess_list_folders = imapdriver_cached_list_folders, | 164 | .sess_list_folders = imapdriver_cached_list_folders, |
163 | .sess_lsub_folders = imapdriver_cached_lsub_folders, | 165 | .sess_lsub_folders = imapdriver_cached_lsub_folders, |
164 | .sess_subscribe_folder = imapdriver_cached_subscribe_folder, | 166 | .sess_subscribe_folder = imapdriver_cached_subscribe_folder, |
165 | .sess_unsubscribe_folder = imapdriver_cached_unsubscribe_folder, | 167 | .sess_unsubscribe_folder = imapdriver_cached_unsubscribe_folder, |
166 | 168 | ||
167 | .sess_append_message = imapdriver_cached_append_message, | 169 | .sess_append_message = imapdriver_cached_append_message, |
170 | .sess_append_message_flags = imapdriver_cached_append_message_flags, | ||
168 | .sess_copy_message = imapdriver_cached_copy_message, | 171 | .sess_copy_message = imapdriver_cached_copy_message, |
169 | .sess_move_message = NULL, | 172 | .sess_move_message = NULL, |
170 | 173 | ||
171 | .sess_get_messages_list = imapdriver_cached_get_messages_list, | 174 | .sess_get_messages_list = imapdriver_cached_get_messages_list, |
172 | .sess_get_envelopes_list = imapdriver_cached_get_envelopes_list, | 175 | .sess_get_envelopes_list = imapdriver_cached_get_envelopes_list, |
173 | .sess_remove_message = imapdriver_cached_remove_message, | 176 | .sess_remove_message = imapdriver_cached_remove_message, |
174 | #if 0 | 177 | #if 0 |
175 | .sess_search_messages = imapdriver_cached_search_messages, | 178 | .sess_search_messages = imapdriver_cached_search_messages, |
176 | #endif | 179 | #endif |
177 | 180 | ||
178 | .sess_get_message = imapdriver_cached_get_message, | 181 | .sess_get_message = imapdriver_cached_get_message, |
179 | .sess_get_message_by_uid = imapdriver_cached_get_message_by_uid, | 182 | .sess_get_message_by_uid = imapdriver_cached_get_message_by_uid, |
180 | }; | 183 | }; |
181 | 184 | ||
182 | mailsession_driver * imap_cached_session_driver = | 185 | mailsession_driver * imap_cached_session_driver = |
183 | &local_imap_cached_session_driver; | 186 | &local_imap_cached_session_driver; |
184 | 187 | ||
185 | #define CACHE_MESSAGE_LIST | 188 | #define CACHE_MESSAGE_LIST |
186 | 189 | ||
187 | static inline struct imap_cached_session_state_data * | 190 | static inline struct imap_cached_session_state_data * |
188 | get_cached_data(mailsession * session) | 191 | get_cached_data(mailsession * session) |
189 | { | 192 | { |
190 | return session->sess_data; | 193 | return session->sess_data; |
191 | } | 194 | } |
192 | 195 | ||
193 | static inline mailsession * get_ancestor(mailsession * s) | 196 | static inline mailsession * get_ancestor(mailsession * s) |
194 | { | 197 | { |
195 | return get_cached_data(s)->imap_ancestor; | 198 | return get_cached_data(s)->imap_ancestor; |
196 | } | 199 | } |
197 | 200 | ||
198 | static inline | 201 | static inline |
199 | struct imap_session_state_data * get_ancestor_data(mailsession * s) | 202 | struct imap_session_state_data * get_ancestor_data(mailsession * s) |
@@ -747,64 +750,77 @@ static int imapdriver_cached_subscribe_folder(mailsession * session, | |||
747 | 750 | ||
748 | r = mailsession_subscribe_folder(get_ancestor(session), mb); | 751 | r = mailsession_subscribe_folder(get_ancestor(session), mb); |
749 | 752 | ||
750 | check_for_uid_cache(session); | 753 | check_for_uid_cache(session); |
751 | 754 | ||
752 | return r; | 755 | return r; |
753 | } | 756 | } |
754 | 757 | ||
755 | static int imapdriver_cached_unsubscribe_folder(mailsession * session, | 758 | static int imapdriver_cached_unsubscribe_folder(mailsession * session, |
756 | char * mb) | 759 | char * mb) |
757 | { | 760 | { |
758 | int r; | 761 | int r; |
759 | 762 | ||
760 | r = mailsession_unsubscribe_folder(get_ancestor(session), mb); | 763 | r = mailsession_unsubscribe_folder(get_ancestor(session), mb); |
761 | 764 | ||
762 | check_for_uid_cache(session); | 765 | check_for_uid_cache(session); |
763 | 766 | ||
764 | return r; | 767 | return r; |
765 | } | 768 | } |
766 | 769 | ||
767 | static int imapdriver_cached_append_message(mailsession * session, | 770 | static int imapdriver_cached_append_message(mailsession * session, |
768 | char * message, size_t size) | 771 | char * message, size_t size) |
769 | { | 772 | { |
770 | int r; | 773 | int r; |
771 | 774 | ||
772 | r = mailsession_append_message(get_ancestor(session), message, size); | 775 | r = mailsession_append_message(get_ancestor(session), message, size); |
773 | 776 | ||
774 | check_for_uid_cache(session); | 777 | check_for_uid_cache(session); |
775 | 778 | ||
776 | return r; | 779 | return r; |
777 | } | 780 | } |
778 | 781 | ||
782 | static int imapdriver_cached_append_message_flags(mailsession * session, | ||
783 | char * message, size_t size, struct mail_flags * flags) | ||
784 | { | ||
785 | int r; | ||
786 | |||
787 | r = mailsession_append_message_flags(get_ancestor(session), | ||
788 | message, size, flags); | ||
789 | |||
790 | check_for_uid_cache(session); | ||
791 | |||
792 | return r; | ||
793 | } | ||
794 | |||
779 | static int imapdriver_cached_copy_message(mailsession * session, | 795 | static int imapdriver_cached_copy_message(mailsession * session, |
780 | uint32_t num, char * mb) | 796 | uint32_t num, char * mb) |
781 | { | 797 | { |
782 | int r; | 798 | int r; |
783 | 799 | ||
784 | r = mailsession_copy_message(get_ancestor(session), num, mb); | 800 | r = mailsession_copy_message(get_ancestor(session), num, mb); |
785 | 801 | ||
786 | check_for_uid_cache(session); | 802 | check_for_uid_cache(session); |
787 | 803 | ||
788 | return r; | 804 | return r; |
789 | } | 805 | } |
790 | 806 | ||
791 | static int cmp_uid(uint32_t ** pa, uint32_t ** pb) | 807 | static int cmp_uid(uint32_t ** pa, uint32_t ** pb) |
792 | { | 808 | { |
793 | uint32_t * a; | 809 | uint32_t * a; |
794 | uint32_t * b; | 810 | uint32_t * b; |
795 | 811 | ||
796 | a = * pa; | 812 | a = * pa; |
797 | b = * pb; | 813 | b = * pb; |
798 | 814 | ||
799 | return * a - * b; | 815 | return * a - * b; |
800 | } | 816 | } |
801 | 817 | ||
802 | 818 | ||
803 | static int imapdriver_cached_get_messages_list(mailsession * session, | 819 | static int imapdriver_cached_get_messages_list(mailsession * session, |
804 | struct mailmessage_list ** | 820 | struct mailmessage_list ** |
805 | result) | 821 | result) |
806 | { | 822 | { |
807 | #if 0 | 823 | #if 0 |
808 | mailsession * imap_session; | 824 | mailsession * imap_session; |
809 | #endif | 825 | #endif |
810 | mailimap * imap; | 826 | mailimap * imap; |
diff --git a/kmicromail/libetpan/generic/imapdriver_cached_message.c b/kmicromail/libetpan/generic/imapdriver_cached_message.c index c0542a3..c4357a3 100644 --- a/kmicromail/libetpan/generic/imapdriver_cached_message.c +++ b/kmicromail/libetpan/generic/imapdriver_cached_message.c | |||
@@ -183,65 +183,65 @@ static void generate_key_from_mime_section(char * key, size_t size, | |||
183 | int r; | 183 | int r; |
184 | 184 | ||
185 | snprintf(key, size, "unvalid"); | 185 | snprintf(key, size, "unvalid"); |
186 | 186 | ||
187 | r = mailmime_get_section_id(mime, &part); | 187 | r = mailmime_get_section_id(mime, &part); |
188 | if (r != MAILIMF_NO_ERROR) | 188 | if (r != MAILIMF_NO_ERROR) |
189 | goto err; | 189 | goto err; |
190 | 190 | ||
191 | gstr = mmap_string_new("part"); | 191 | gstr = mmap_string_new("part"); |
192 | if (gstr == NULL) | 192 | if (gstr == NULL) |
193 | goto free_section; | 193 | goto free_section; |
194 | 194 | ||
195 | for(cur = clist_begin(part->sec_list) ; | 195 | for(cur = clist_begin(part->sec_list) ; |
196 | cur != NULL ; cur = clist_next(cur)) { | 196 | cur != NULL ; cur = clist_next(cur)) { |
197 | char s[20]; | 197 | char s[20]; |
198 | 198 | ||
199 | snprintf(s, 20, ".%u", * (uint32_t *) clist_content(cur)); | 199 | snprintf(s, 20, ".%u", * (uint32_t *) clist_content(cur)); |
200 | if (mmap_string_append(gstr, s) == NULL) | 200 | if (mmap_string_append(gstr, s) == NULL) |
201 | goto free_str; | 201 | goto free_str; |
202 | } | 202 | } |
203 | 203 | ||
204 | snprintf(key, size, "%s", gstr->str); | 204 | snprintf(key, size, "%s", gstr->str); |
205 | 205 | ||
206 | mmap_string_free(gstr); | 206 | mmap_string_free(gstr); |
207 | mailmime_section_free(part); | 207 | mailmime_section_free(part); |
208 | 208 | ||
209 | return; | 209 | return; |
210 | 210 | ||
211 | free_str: | 211 | free_str: |
212 | mmap_string_free(gstr); | 212 | mmap_string_free(gstr); |
213 | free_section: | 213 | free_section: |
214 | mailmime_section_free(part); | 214 | mailmime_section_free(part); |
215 | err: | 215 | err:; |
216 | } | 216 | } |
217 | 217 | ||
218 | static void generate_key_from_section(char * key, size_t size, | 218 | static void generate_key_from_section(char * key, size_t size, |
219 | mailmessage * msg_info, | 219 | mailmessage * msg_info, |
220 | struct mailmime * mime, int type) | 220 | struct mailmime * mime, int type) |
221 | { | 221 | { |
222 | char section_str[PATH_MAX]; | 222 | char section_str[PATH_MAX]; |
223 | 223 | ||
224 | generate_key_from_mime_section(section_str, PATH_MAX, mime); | 224 | generate_key_from_mime_section(section_str, PATH_MAX, mime); |
225 | 225 | ||
226 | switch (type) { | 226 | switch (type) { |
227 | case IMAP_SECTION_MESSAGE: | 227 | case IMAP_SECTION_MESSAGE: |
228 | snprintf(key, size, "%s-%s", msg_info->msg_uid, section_str); | 228 | snprintf(key, size, "%s-%s", msg_info->msg_uid, section_str); |
229 | break; | 229 | break; |
230 | case IMAP_SECTION_HEADER: | 230 | case IMAP_SECTION_HEADER: |
231 | snprintf(key, size, "%s-%s-header", msg_info->msg_uid, section_str); | 231 | snprintf(key, size, "%s-%s-header", msg_info->msg_uid, section_str); |
232 | break; | 232 | break; |
233 | case IMAP_SECTION_MIME: | 233 | case IMAP_SECTION_MIME: |
234 | snprintf(key, size, "%s-%s-mime", msg_info->msg_uid, section_str); | 234 | snprintf(key, size, "%s-%s-mime", msg_info->msg_uid, section_str); |
235 | break; | 235 | break; |
236 | case IMAP_SECTION_BODY: | 236 | case IMAP_SECTION_BODY: |
237 | snprintf(key, size, "%s-%s-text", msg_info->msg_uid, section_str); | 237 | snprintf(key, size, "%s-%s-text", msg_info->msg_uid, section_str); |
238 | break; | 238 | break; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | static void generate_key_from_message(char * key, size_t size, | 242 | static void generate_key_from_message(char * key, size_t size, |
243 | mailmessage * msg_info, | 243 | mailmessage * msg_info, |
244 | int type) | 244 | int type) |
245 | { | 245 | { |
246 | switch (type) { | 246 | switch (type) { |
247 | case MAILIMAP_MSG_ATT_RFC822: | 247 | case MAILIMAP_MSG_ATT_RFC822: |
diff --git a/kmicromail/libetpan/generic/imapdriver_tools.c b/kmicromail/libetpan/generic/imapdriver_tools.c index 3d737f3..de4008f 100644 --- a/kmicromail/libetpan/generic/imapdriver_tools.c +++ b/kmicromail/libetpan/generic/imapdriver_tools.c | |||
@@ -3078,74 +3078,73 @@ static int imap_flags_to_flags(struct mailimap_msg_att_dynamic * att_dyn, | |||
3078 | r = clist_append(flags->fl_extension, keyword); | 3078 | r = clist_append(flags->fl_extension, keyword); |
3079 | if (r < 0) { | 3079 | if (r < 0) { |
3080 | free(keyword); | 3080 | free(keyword); |
3081 | goto free; | 3081 | goto free; |
3082 | } | 3082 | } |
3083 | } | 3083 | } |
3084 | break; | 3084 | break; |
3085 | case MAILIMAP_FLAG_EXTENSION: | 3085 | case MAILIMAP_FLAG_EXTENSION: |
3086 | /* do nothing */ | 3086 | /* do nothing */ |
3087 | break; | 3087 | break; |
3088 | } | 3088 | } |
3089 | } | 3089 | } |
3090 | } | 3090 | } |
3091 | /* | 3091 | /* |
3092 | MAIL_FLAG_NEW was set for \Recent messages. | 3092 | MAIL_FLAG_NEW was set for \Recent messages. |
3093 | Correct this flag for \Seen messages by unsetting it. | 3093 | Correct this flag for \Seen messages by unsetting it. |
3094 | */ | 3094 | */ |
3095 | if ((flags->fl_flags & MAIL_FLAG_SEEN) && (flags->fl_flags & MAIL_FLAG_NEW)) { | 3095 | if ((flags->fl_flags & MAIL_FLAG_SEEN) && (flags->fl_flags & MAIL_FLAG_NEW)) { |
3096 | flags->fl_flags &= ~MAIL_FLAG_NEW; | 3096 | flags->fl_flags &= ~MAIL_FLAG_NEW; |
3097 | } | 3097 | } |
3098 | } | 3098 | } |
3099 | 3099 | ||
3100 | * result = flags; | 3100 | * result = flags; |
3101 | 3101 | ||
3102 | return MAIL_NO_ERROR; | 3102 | return MAIL_NO_ERROR; |
3103 | 3103 | ||
3104 | free: | 3104 | free: |
3105 | mail_flags_free(flags); | 3105 | mail_flags_free(flags); |
3106 | err: | 3106 | err: |
3107 | return MAIL_ERROR_MEMORY; | 3107 | return MAIL_ERROR_MEMORY; |
3108 | } | 3108 | } |
3109 | 3109 | ||
3110 | static int flags_to_imap_flags(struct mail_flags * flags, | 3110 | int imap_flags_to_imap_flags(struct mail_flags * flags, |
3111 | struct mailimap_store_att_flags ** result) | 3111 | struct mailimap_flag_list ** result) |
3112 | { | 3112 | { |
3113 | struct mailimap_flag * flag; | 3113 | struct mailimap_flag * flag; |
3114 | struct mailimap_flag_list * flag_list; | 3114 | struct mailimap_flag_list * flag_list; |
3115 | struct mailimap_store_att_flags * att_flags; | ||
3116 | int res; | 3115 | int res; |
3117 | clistiter * cur; | 3116 | clistiter * cur; |
3118 | int r; | 3117 | int r; |
3119 | 3118 | ||
3120 | flag_list = mailimap_flag_list_new_empty(); | 3119 | flag_list = mailimap_flag_list_new_empty(); |
3121 | if (flag_list == NULL) { | 3120 | if (flag_list == NULL) { |
3122 | res = MAIL_ERROR_MEMORY; | 3121 | res = MAIL_ERROR_MEMORY; |
3123 | goto err; | 3122 | goto err; |
3124 | } | 3123 | } |
3125 | 3124 | ||
3126 | if ((flags->fl_flags & MAIL_FLAG_DELETED) != 0) { | 3125 | if ((flags->fl_flags & MAIL_FLAG_DELETED) != 0) { |
3127 | flag = mailimap_flag_new_deleted(); | 3126 | flag = mailimap_flag_new_deleted(); |
3128 | if (flag == NULL) { | 3127 | if (flag == NULL) { |
3129 | res = MAIL_ERROR_MEMORY; | 3128 | res = MAIL_ERROR_MEMORY; |
3130 | goto free_flag_list; | 3129 | goto free_flag_list; |
3131 | } | 3130 | } |
3132 | r = mailimap_flag_list_add(flag_list, flag); | 3131 | r = mailimap_flag_list_add(flag_list, flag); |
3133 | if (r != MAILIMAP_NO_ERROR) { | 3132 | if (r != MAILIMAP_NO_ERROR) { |
3134 | mailimap_flag_free(flag); | 3133 | mailimap_flag_free(flag); |
3135 | res = MAIL_ERROR_MEMORY; | 3134 | res = MAIL_ERROR_MEMORY; |
3136 | goto free_flag_list; | 3135 | goto free_flag_list; |
3137 | } | 3136 | } |
3138 | } | 3137 | } |
3139 | 3138 | ||
3140 | if ((flags->fl_flags & MAIL_FLAG_FLAGGED) != 0) { | 3139 | if ((flags->fl_flags & MAIL_FLAG_FLAGGED) != 0) { |
3141 | flag = mailimap_flag_new_flagged(); | 3140 | flag = mailimap_flag_new_flagged(); |
3142 | if (flag == NULL) { | 3141 | if (flag == NULL) { |
3143 | res = MAIL_ERROR_MEMORY; | 3142 | res = MAIL_ERROR_MEMORY; |
3144 | goto free_flag_list; | 3143 | goto free_flag_list; |
3145 | } | 3144 | } |
3146 | r = mailimap_flag_list_add(flag_list, flag); | 3145 | r = mailimap_flag_list_add(flag_list, flag); |
3147 | if (r != MAILIMAP_NO_ERROR) { | 3146 | if (r != MAILIMAP_NO_ERROR) { |
3148 | mailimap_flag_free(flag); | 3147 | mailimap_flag_free(flag); |
3149 | res = MAIL_ERROR_MEMORY; | 3148 | res = MAIL_ERROR_MEMORY; |
3150 | goto free_flag_list; | 3149 | goto free_flag_list; |
3151 | } | 3150 | } |
@@ -3210,75 +3209,100 @@ static int flags_to_imap_flags(struct mail_flags * flags, | |||
3210 | flag = mailimap_flag_new_draft(); | 3209 | flag = mailimap_flag_new_draft(); |
3211 | if (flag == NULL) { | 3210 | if (flag == NULL) { |
3212 | res = MAIL_ERROR_MEMORY; | 3211 | res = MAIL_ERROR_MEMORY; |
3213 | goto free_flag_list; | 3212 | goto free_flag_list; |
3214 | } | 3213 | } |
3215 | r = mailimap_flag_list_add(flag_list, flag); | 3214 | r = mailimap_flag_list_add(flag_list, flag); |
3216 | if (r != MAILIMAP_NO_ERROR) { | 3215 | if (r != MAILIMAP_NO_ERROR) { |
3217 | mailimap_flag_free(flag); | 3216 | mailimap_flag_free(flag); |
3218 | res = MAIL_ERROR_MEMORY; | 3217 | res = MAIL_ERROR_MEMORY; |
3219 | goto free_flag_list; | 3218 | goto free_flag_list; |
3220 | } | 3219 | } |
3221 | } | 3220 | } |
3222 | else { | 3221 | else { |
3223 | flag_str = strdup(flag_str); | 3222 | flag_str = strdup(flag_str); |
3224 | if (flag_str == NULL) { | 3223 | if (flag_str == NULL) { |
3225 | res = MAIL_ERROR_MEMORY; | 3224 | res = MAIL_ERROR_MEMORY; |
3226 | goto free_flag_list; | 3225 | goto free_flag_list; |
3227 | } | 3226 | } |
3228 | flag = mailimap_flag_new_flag_keyword(flag_str); | 3227 | flag = mailimap_flag_new_flag_keyword(flag_str); |
3229 | if (flag == NULL) { | 3228 | if (flag == NULL) { |
3230 | free(flag_str); | 3229 | free(flag_str); |
3231 | res = MAIL_ERROR_MEMORY; | 3230 | res = MAIL_ERROR_MEMORY; |
3232 | goto free_flag_list; | 3231 | goto free_flag_list; |
3233 | } | 3232 | } |
3234 | r = mailimap_flag_list_add(flag_list, flag); | 3233 | r = mailimap_flag_list_add(flag_list, flag); |
3235 | if (r != MAILIMAP_NO_ERROR) { | 3234 | if (r != MAILIMAP_NO_ERROR) { |
3236 | mailimap_flag_free(flag); | 3235 | mailimap_flag_free(flag); |
3237 | res = MAIL_ERROR_MEMORY; | 3236 | res = MAIL_ERROR_MEMORY; |
3238 | goto free_flag_list; | 3237 | goto free_flag_list; |
3239 | } | 3238 | } |
3240 | } | 3239 | } |
3241 | } | 3240 | } |
3241 | |||
3242 | * result = flag_list; | ||
3243 | |||
3244 | return MAIL_NO_ERROR; | ||
3245 | |||
3246 | free_flag_list: | ||
3247 | mailimap_flag_list_free(flag_list); | ||
3248 | err: | ||
3249 | return res; | ||
3250 | } | ||
3242 | 3251 | ||
3252 | static int flags_to_imap_flags(struct mail_flags * flags, | ||
3253 | struct mailimap_store_att_flags ** result) | ||
3254 | { | ||
3255 | struct mailimap_flag_list * flag_list; | ||
3256 | struct mailimap_store_att_flags * att_flags; | ||
3257 | int res; | ||
3258 | int r; | ||
3259 | |||
3260 | r = imap_flags_to_imap_flags(flags, | ||
3261 | &flag_list); | ||
3262 | if (r != MAIL_NO_ERROR) { | ||
3263 | res = r; | ||
3264 | goto err; | ||
3265 | } | ||
3266 | |||
3243 | att_flags = mailimap_store_att_flags_new_set_flags_silent(flag_list); | 3267 | att_flags = mailimap_store_att_flags_new_set_flags_silent(flag_list); |
3244 | if (att_flags == NULL) { | 3268 | if (att_flags == NULL) { |
3245 | res = MAIL_ERROR_MEMORY; | 3269 | res = MAIL_ERROR_MEMORY; |
3246 | goto free_flag_list; | 3270 | goto free_flag_list; |
3247 | } | 3271 | } |
3248 | 3272 | ||
3249 | * result = att_flags; | 3273 | * result = att_flags; |
3250 | 3274 | ||
3251 | return MAIL_NO_ERROR; | 3275 | return MAIL_NO_ERROR; |
3252 | 3276 | ||
3253 | free_flag_list: | 3277 | free_flag_list: |
3254 | mailimap_flag_list_free(flag_list); | 3278 | mailimap_flag_list_free(flag_list); |
3255 | err: | 3279 | err: |
3256 | return res; | 3280 | return res; |
3257 | } | 3281 | } |
3258 | 3282 | ||
3259 | 3283 | ||
3260 | static int | 3284 | static int |
3261 | imap_fetch_result_to_flags(clist * fetch_result, uint32_t index, | 3285 | imap_fetch_result_to_flags(clist * fetch_result, uint32_t index, |
3262 | struct mail_flags ** result) | 3286 | struct mail_flags ** result) |
3263 | { | 3287 | { |
3264 | clistiter * cur; | 3288 | clistiter * cur; |
3265 | int r; | 3289 | int r; |
3266 | 3290 | ||
3267 | for(cur = clist_begin(fetch_result) ; cur != NULL ; | 3291 | for(cur = clist_begin(fetch_result) ; cur != NULL ; |
3268 | cur = clist_next(cur)) { | 3292 | cur = clist_next(cur)) { |
3269 | struct mailimap_msg_att * msg_att; | 3293 | struct mailimap_msg_att * msg_att; |
3270 | clistiter * item_cur; | 3294 | clistiter * item_cur; |
3271 | uint32_t uid; | 3295 | uint32_t uid; |
3272 | struct mailimap_msg_att_dynamic * att_dyn; | 3296 | struct mailimap_msg_att_dynamic * att_dyn; |
3273 | 3297 | ||
3274 | msg_att = clist_content(cur); | 3298 | msg_att = clist_content(cur); |
3275 | 3299 | ||
3276 | uid = 0; | 3300 | uid = 0; |
3277 | att_dyn = NULL; | 3301 | att_dyn = NULL; |
3278 | 3302 | ||
3279 | for(item_cur = clist_begin(msg_att->att_list) ; item_cur != NULL ; | 3303 | for(item_cur = clist_begin(msg_att->att_list) ; item_cur != NULL ; |
3280 | item_cur = clist_next(item_cur)) { | 3304 | item_cur = clist_next(item_cur)) { |
3281 | struct mailimap_msg_att_item * item; | 3305 | struct mailimap_msg_att_item * item; |
3282 | 3306 | ||
3283 | item = clist_content(item_cur); | 3307 | item = clist_content(item_cur); |
3284 | 3308 | ||
diff --git a/kmicromail/libetpan/generic/imapdriver_tools.h b/kmicromail/libetpan/generic/imapdriver_tools.h index 6582a31..59c993e 100644 --- a/kmicromail/libetpan/generic/imapdriver_tools.h +++ b/kmicromail/libetpan/generic/imapdriver_tools.h | |||
@@ -77,37 +77,40 @@ int imap_body_to_body(struct mailimap_body * imap_body, | |||
77 | int mail_search_to_imap_search(struct mail_search_key * key, | 77 | int mail_search_to_imap_search(struct mail_search_key * key, |
78 | struct mailimap_search_key ** result); | 78 | struct mailimap_search_key ** result); |
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | int msg_list_to_imap_set(clist * msg_list, | 81 | int msg_list_to_imap_set(clist * msg_list, |
82 | struct mailimap_set ** result); | 82 | struct mailimap_set ** result); |
83 | 83 | ||
84 | int imap_error_to_mail_error(int error); | 84 | int imap_error_to_mail_error(int error); |
85 | 85 | ||
86 | int imap_store_flags(mailimap * imap, uint32_t first, uint32_t last, | 86 | int imap_store_flags(mailimap * imap, uint32_t first, uint32_t last, |
87 | struct mail_flags * flags); | 87 | struct mail_flags * flags); |
88 | 88 | ||
89 | int imap_fetch_flags(mailimap * imap, | 89 | int imap_fetch_flags(mailimap * imap, |
90 | uint32_t index, struct mail_flags ** result); | 90 | uint32_t index, struct mail_flags ** result); |
91 | 91 | ||
92 | int imap_get_messages_list(mailimap * imap, | 92 | int imap_get_messages_list(mailimap * imap, |
93 | mailsession * session, mailmessage_driver * driver, | 93 | mailsession * session, mailmessage_driver * driver, |
94 | uint32_t first_index, | 94 | uint32_t first_index, |
95 | struct mailmessage_list ** result); | 95 | struct mailmessage_list ** result); |
96 | 96 | ||
97 | int | 97 | int |
98 | imapdriver_get_cached_envelope(struct mail_cache_db * cache_db, | 98 | imapdriver_get_cached_envelope(struct mail_cache_db * cache_db, |
99 | MMAPString * mmapstr, | 99 | MMAPString * mmapstr, |
100 | mailsession * session, mailmessage * msg, | 100 | mailsession * session, mailmessage * msg, |
101 | struct mailimf_fields ** result); | 101 | struct mailimf_fields ** result); |
102 | 102 | ||
103 | int | 103 | int |
104 | imapdriver_write_cached_envelope(struct mail_cache_db * cache_db, | 104 | imapdriver_write_cached_envelope(struct mail_cache_db * cache_db, |
105 | MMAPString * mmapstr, | 105 | MMAPString * mmapstr, |
106 | mailsession * session, mailmessage * msg, | 106 | mailsession * session, mailmessage * msg, |
107 | struct mailimf_fields * fields); | 107 | struct mailimf_fields * fields); |
108 | 108 | ||
109 | int imap_flags_to_imap_flags(struct mail_flags * flags, | ||
110 | struct mailimap_flag_list ** result); | ||
111 | |||
109 | #ifdef __cplusplus | 112 | #ifdef __cplusplus |
110 | } | 113 | } |
111 | #endif | 114 | #endif |
112 | 115 | ||
113 | #endif | 116 | #endif |
diff --git a/kmicromail/libetpan/generic/imapstorage.c b/kmicromail/libetpan/generic/imapstorage.c index e8683d8..972b6dd 100644 --- a/kmicromail/libetpan/generic/imapstorage.c +++ b/kmicromail/libetpan/generic/imapstorage.c | |||
@@ -42,65 +42,65 @@ | |||
42 | #include "imapdriver.h" | 42 | #include "imapdriver.h" |
43 | #include "imapdriver_cached.h" | 43 | #include "imapdriver_cached.h" |
44 | #include "mailstorage_tools.h" | 44 | #include "mailstorage_tools.h" |
45 | #include "maildriver.h" | 45 | #include "maildriver.h" |
46 | 46 | ||
47 | /* imap storage */ | 47 | /* imap storage */ |
48 | 48 | ||
49 | #define IMAP_DEFAULT_PORT 143 | 49 | #define IMAP_DEFAULT_PORT 143 |
50 | #define IMAPS_DEFAULT_PORT 993 | 50 | #define IMAPS_DEFAULT_PORT 993 |
51 | 51 | ||
52 | static int imap_mailstorage_connect(struct mailstorage * storage); | 52 | static int imap_mailstorage_connect(struct mailstorage * storage); |
53 | static int | 53 | static int |
54 | imap_mailstorage_get_folder_session(struct mailstorage * storage, | 54 | imap_mailstorage_get_folder_session(struct mailstorage * storage, |
55 | char * pathname, mailsession ** result); | 55 | char * pathname, mailsession ** result); |
56 | static void imap_mailstorage_uninitialize(struct mailstorage * storage); | 56 | static void imap_mailstorage_uninitialize(struct mailstorage * storage); |
57 | 57 | ||
58 | static mailstorage_driver imap_mailstorage_driver = { | 58 | static mailstorage_driver imap_mailstorage_driver = { |
59 | .sto_name = "imap", | 59 | .sto_name = "imap", |
60 | .sto_connect = imap_mailstorage_connect, | 60 | .sto_connect = imap_mailstorage_connect, |
61 | .sto_get_folder_session = imap_mailstorage_get_folder_session, | 61 | .sto_get_folder_session = imap_mailstorage_get_folder_session, |
62 | .sto_uninitialize = imap_mailstorage_uninitialize, | 62 | .sto_uninitialize = imap_mailstorage_uninitialize, |
63 | }; | 63 | }; |
64 | 64 | ||
65 | int imap_mailstorage_init(struct mailstorage * storage, | 65 | int imap_mailstorage_init(struct mailstorage * storage, |
66 | char * imap_servername, uint16_t imap_port, | 66 | char * imap_servername, uint16_t imap_port, |
67 | char * imap_command, | 67 | char * imap_command, |
68 | int imap_connection_type, int imap_auth_type, | 68 | int imap_connection_type, int imap_auth_type, |
69 | char * imap_login, char * imap_password, | 69 | char * imap_login, char * imap_password, |
70 | int imap_cached, char * imap_cache_directory) | 70 | int imap_cached, char * imap_cache_directory) |
71 | { | 71 | { |
72 | struct imap_mailstorage * imap_storage; | 72 | struct imap_mailstorage * imap_storage; |
73 | 73 | ||
74 | imap_storage = malloc(sizeof(struct imap_mailstorage)); | 74 | imap_storage = malloc(sizeof(* imap_storage)); |
75 | if (imap_storage == NULL) | 75 | if (imap_storage == NULL) |
76 | goto err; | 76 | goto err; |
77 | 77 | ||
78 | imap_storage->imap_servername = strdup(imap_servername); | 78 | imap_storage->imap_servername = strdup(imap_servername); |
79 | if (imap_storage->imap_servername == NULL) | 79 | if (imap_storage->imap_servername == NULL) |
80 | goto free; | 80 | goto free; |
81 | 81 | ||
82 | imap_storage->imap_connection_type = imap_connection_type; | 82 | imap_storage->imap_connection_type = imap_connection_type; |
83 | 83 | ||
84 | if (imap_port == 0) { | 84 | if (imap_port == 0) { |
85 | switch (imap_connection_type) { | 85 | switch (imap_connection_type) { |
86 | case CONNECTION_TYPE_PLAIN: | 86 | case CONNECTION_TYPE_PLAIN: |
87 | case CONNECTION_TYPE_TRY_STARTTLS: | 87 | case CONNECTION_TYPE_TRY_STARTTLS: |
88 | case CONNECTION_TYPE_STARTTLS: | 88 | case CONNECTION_TYPE_STARTTLS: |
89 | case CONNECTION_TYPE_COMMAND: | 89 | case CONNECTION_TYPE_COMMAND: |
90 | case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: | 90 | case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: |
91 | case CONNECTION_TYPE_COMMAND_STARTTLS: | 91 | case CONNECTION_TYPE_COMMAND_STARTTLS: |
92 | imap_port = IMAP_DEFAULT_PORT; | 92 | imap_port = IMAP_DEFAULT_PORT; |
93 | break; | 93 | break; |
94 | 94 | ||
95 | case CONNECTION_TYPE_TLS: | 95 | case CONNECTION_TYPE_TLS: |
96 | case CONNECTION_TYPE_COMMAND_TLS: | 96 | case CONNECTION_TYPE_COMMAND_TLS: |
97 | imap_port = IMAPS_DEFAULT_PORT; | 97 | imap_port = IMAPS_DEFAULT_PORT; |
98 | break; | 98 | break; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | imap_storage->imap_port = imap_port; | 102 | imap_storage->imap_port = imap_port; |
103 | 103 | ||
104 | if (imap_command != NULL) { | 104 | if (imap_command != NULL) { |
105 | imap_storage->imap_command = strdup(imap_command); | 105 | imap_storage->imap_command = strdup(imap_command); |
106 | if (imap_storage->imap_command == NULL) | 106 | if (imap_storage->imap_command == NULL) |
diff --git a/kmicromail/libetpan/generic/maildirdriver.c b/kmicromail/libetpan/generic/maildirdriver.c index 7830ceb..5f21422 100644 --- a/kmicromail/libetpan/generic/maildirdriver.c +++ b/kmicromail/libetpan/generic/maildirdriver.c | |||
@@ -56,108 +56,112 @@ | |||
56 | #include "maildriver_tools.h" | 56 | #include "maildriver_tools.h" |
57 | #include "maildirdriver_message.h" | 57 | #include "maildirdriver_message.h" |
58 | #include "maildirdriver_tools.h" | 58 | #include "maildirdriver_tools.h" |
59 | #include "mailmessage.h" | 59 | #include "mailmessage.h" |
60 | #include "generic_cache.h" | 60 | #include "generic_cache.h" |
61 | 61 | ||
62 | static int initialize(mailsession * session); | 62 | static int initialize(mailsession * session); |
63 | 63 | ||
64 | static void uninitialize(mailsession * session); | 64 | static void uninitialize(mailsession * session); |
65 | 65 | ||
66 | static int connect_path(mailsession * session, char * path); | 66 | static int connect_path(mailsession * session, char * path); |
67 | 67 | ||
68 | static int logout(mailsession * session); | 68 | static int logout(mailsession * session); |
69 | 69 | ||
70 | static int expunge_folder(mailsession * session); | 70 | static int expunge_folder(mailsession * session); |
71 | 71 | ||
72 | static int status_folder(mailsession * session, char * mb, | 72 | static int status_folder(mailsession * session, char * mb, |
73 | uint32_t * result_messages, uint32_t * result_recent, | 73 | uint32_t * result_messages, uint32_t * result_recent, |
74 | uint32_t * result_unseen); | 74 | uint32_t * result_unseen); |
75 | 75 | ||
76 | static int recent_number(mailsession * session, char * mb, | 76 | static int recent_number(mailsession * session, char * mb, |
77 | uint32_t * result); | 77 | uint32_t * result); |
78 | 78 | ||
79 | static int unseen_number(mailsession * session, char * mb, | 79 | static int unseen_number(mailsession * session, char * mb, |
80 | uint32_t * result); | 80 | uint32_t * result); |
81 | 81 | ||
82 | static int messages_number(mailsession * session, char * mb, | 82 | static int messages_number(mailsession * session, char * mb, |
83 | uint32_t * result); | 83 | uint32_t * result); |
84 | 84 | ||
85 | static int append_message(mailsession * session, | 85 | static int append_message(mailsession * session, |
86 | char * message, size_t size); | 86 | char * message, size_t size); |
87 | 87 | ||
88 | static int append_message_flags(mailsession * session, | ||
89 | char * message, size_t size, struct mail_flags * flags); | ||
90 | |||
88 | static int get_messages_list(mailsession * session, | 91 | static int get_messages_list(mailsession * session, |
89 | struct mailmessage_list ** result); | 92 | struct mailmessage_list ** result); |
90 | 93 | ||
91 | static int get_envelopes_list(mailsession * session, | 94 | static int get_envelopes_list(mailsession * session, |
92 | struct mailmessage_list * env_list); | 95 | struct mailmessage_list * env_list); |
93 | 96 | ||
94 | static int check_folder(mailsession * session); | 97 | static int check_folder(mailsession * session); |
95 | 98 | ||
96 | static int get_message_by_uid(mailsession * session, | 99 | static int get_message_by_uid(mailsession * session, |
97 | const char * uid, mailmessage ** result); | 100 | const char * uid, mailmessage ** result); |
98 | 101 | ||
99 | static mailsession_driver local_maildir_session_driver = { | 102 | static mailsession_driver local_maildir_session_driver = { |
100 | .sess_name = "maildir", | 103 | .sess_name = "maildir", |
101 | 104 | ||
102 | .sess_initialize = initialize, | 105 | .sess_initialize = initialize, |
103 | .sess_uninitialize = uninitialize, | 106 | .sess_uninitialize = uninitialize, |
104 | 107 | ||
105 | .sess_parameters = NULL, | 108 | .sess_parameters = NULL, |
106 | 109 | ||
107 | .sess_connect_stream = NULL, | 110 | .sess_connect_stream = NULL, |
108 | .sess_connect_path = connect_path, | 111 | .sess_connect_path = connect_path, |
109 | .sess_starttls = NULL, | 112 | .sess_starttls = NULL, |
110 | .sess_login = NULL, | 113 | .sess_login = NULL, |
111 | .sess_logout = logout, | 114 | .sess_logout = logout, |
112 | .sess_noop = NULL, | 115 | .sess_noop = NULL, |
113 | 116 | ||
114 | .sess_build_folder_name = NULL, | 117 | .sess_build_folder_name = NULL, |
115 | .sess_create_folder = NULL, | 118 | .sess_create_folder = NULL, |
116 | .sess_delete_folder = NULL, | 119 | .sess_delete_folder = NULL, |
117 | .sess_rename_folder = NULL, | 120 | .sess_rename_folder = NULL, |
118 | .sess_check_folder = check_folder, | 121 | .sess_check_folder = check_folder, |
119 | .sess_examine_folder = NULL, | 122 | .sess_examine_folder = NULL, |
120 | .sess_select_folder = NULL, | 123 | .sess_select_folder = NULL, |
121 | .sess_expunge_folder = expunge_folder, | 124 | .sess_expunge_folder = expunge_folder, |
122 | .sess_status_folder = status_folder, | 125 | .sess_status_folder = status_folder, |
123 | .sess_messages_number = messages_number, | 126 | .sess_messages_number = messages_number, |
124 | .sess_recent_number = recent_number, | 127 | .sess_recent_number = recent_number, |
125 | .sess_unseen_number = unseen_number, | 128 | .sess_unseen_number = unseen_number, |
126 | .sess_list_folders = NULL, | 129 | .sess_list_folders = NULL, |
127 | .sess_lsub_folders = NULL, | 130 | .sess_lsub_folders = NULL, |
128 | .sess_subscribe_folder = NULL, | 131 | .sess_subscribe_folder = NULL, |
129 | .sess_unsubscribe_folder = NULL, | 132 | .sess_unsubscribe_folder = NULL, |
130 | 133 | ||
131 | .sess_append_message = append_message, | 134 | .sess_append_message = append_message, |
135 | .sess_append_message_flags = append_message_flags, | ||
132 | .sess_copy_message = NULL, | 136 | .sess_copy_message = NULL, |
133 | .sess_move_message = NULL, | 137 | .sess_move_message = NULL, |
134 | 138 | ||
135 | .sess_get_messages_list = get_messages_list, | 139 | .sess_get_messages_list = get_messages_list, |
136 | .sess_get_envelopes_list = get_envelopes_list, | 140 | .sess_get_envelopes_list = get_envelopes_list, |
137 | .sess_remove_message = NULL, | 141 | .sess_remove_message = NULL, |
138 | #if 0 | 142 | #if 0 |
139 | .sess_search_messages = maildriver_generic_search_messages, | 143 | .sess_search_messages = maildriver_generic_search_messages, |
140 | #endif | 144 | #endif |
141 | 145 | ||
142 | .sess_get_message = NULL, | 146 | .sess_get_message = NULL, |
143 | .sess_get_message_by_uid = get_message_by_uid, | 147 | .sess_get_message_by_uid = get_message_by_uid, |
144 | }; | 148 | }; |
145 | 149 | ||
146 | mailsession_driver * maildir_session_driver = &local_maildir_session_driver; | 150 | mailsession_driver * maildir_session_driver = &local_maildir_session_driver; |
147 | 151 | ||
148 | 152 | ||
149 | static int flags_store_process(struct maildir * md, | 153 | static int flags_store_process(struct maildir * md, |
150 | struct mail_flags_store * flags_store); | 154 | struct mail_flags_store * flags_store); |
151 | 155 | ||
152 | 156 | ||
153 | static inline struct maildir_session_state_data * get_data(mailsession * session) | 157 | static inline struct maildir_session_state_data * get_data(mailsession * session) |
154 | { | 158 | { |
155 | return session->sess_data; | 159 | return session->sess_data; |
156 | } | 160 | } |
157 | 161 | ||
158 | static struct maildir * get_maildir_session(mailsession * session) | 162 | static struct maildir * get_maildir_session(mailsession * session) |
159 | { | 163 | { |
160 | return get_data(session)->md_session; | 164 | return get_data(session)->md_session; |
161 | } | 165 | } |
162 | 166 | ||
163 | static int initialize(mailsession * session) | 167 | static int initialize(mailsession * session) |
@@ -326,76 +330,123 @@ static int unseen_number(mailsession * session, char * mb, | |||
326 | r = status_folder(session, mb, &messages, &recent, &unseen); | 330 | r = status_folder(session, mb, &messages, &recent, &unseen); |
327 | if (r != MAIL_NO_ERROR) | 331 | if (r != MAIL_NO_ERROR) |
328 | return r; | 332 | return r; |
329 | 333 | ||
330 | * result = unseen; | 334 | * result = unseen; |
331 | 335 | ||
332 | return MAIL_NO_ERROR; | 336 | return MAIL_NO_ERROR; |
333 | } | 337 | } |
334 | 338 | ||
335 | static int recent_number(mailsession * session, char * mb, | 339 | static int recent_number(mailsession * session, char * mb, |
336 | uint32_t * result) | 340 | uint32_t * result) |
337 | { | 341 | { |
338 | uint32_t messages; | 342 | uint32_t messages; |
339 | uint32_t recent; | 343 | uint32_t recent; |
340 | uint32_t unseen; | 344 | uint32_t unseen; |
341 | int r; | 345 | int r; |
342 | 346 | ||
343 | r = status_folder(session, mb, &messages, &recent, &unseen); | 347 | r = status_folder(session, mb, &messages, &recent, &unseen); |
344 | if (r != MAIL_NO_ERROR) | 348 | if (r != MAIL_NO_ERROR) |
345 | return r; | 349 | return r; |
346 | 350 | ||
347 | * result = recent; | 351 | * result = recent; |
348 | 352 | ||
349 | return MAIL_NO_ERROR; | 353 | return MAIL_NO_ERROR; |
350 | } | 354 | } |
351 | 355 | ||
352 | 356 | ||
353 | /* messages operations */ | 357 | /* messages operations */ |
354 | 358 | ||
355 | static int append_message(mailsession * session, | 359 | static int append_message(mailsession * session, |
356 | char * message, size_t size) | 360 | char * message, size_t size) |
357 | { | 361 | { |
362 | #if 0 | ||
358 | struct maildir * md; | 363 | struct maildir * md; |
359 | int r; | 364 | int r; |
360 | 365 | ||
361 | md = get_maildir_session(session); | 366 | md = get_maildir_session(session); |
362 | if (md == NULL) | 367 | if (md == NULL) |
363 | return MAIL_ERROR_BAD_STATE; | 368 | return MAIL_ERROR_BAD_STATE; |
364 | 369 | ||
365 | r = maildir_message_add(md, message, size); | 370 | r = maildir_message_add(md, message, size); |
366 | if (r != MAILDIR_NO_ERROR) | 371 | if (r != MAILDIR_NO_ERROR) |
367 | return maildirdriver_maildir_error_to_mail_error(r); | 372 | return maildirdriver_maildir_error_to_mail_error(r); |
368 | 373 | ||
369 | return MAIL_NO_ERROR; | 374 | return MAIL_NO_ERROR; |
375 | #endif | ||
376 | |||
377 | return append_message_flags(session, message, size, NULL); | ||
378 | } | ||
379 | |||
380 | static int append_message_flags(mailsession * session, | ||
381 | char * message, size_t size, struct mail_flags * flags) | ||
382 | { | ||
383 | struct maildir * md; | ||
384 | int r; | ||
385 | char uid[PATH_MAX]; | ||
386 | struct maildir_msg * md_msg; | ||
387 | chashdatum key; | ||
388 | chashdatum value; | ||
389 | uint32_t md_flags; | ||
390 | |||
391 | md = get_maildir_session(session); | ||
392 | if (md == NULL) | ||
393 | return MAIL_ERROR_BAD_STATE; | ||
394 | |||
395 | r = maildir_message_add_uid(md, message, size, | ||
396 | uid, sizeof(uid)); | ||
397 | if (r != MAILDIR_NO_ERROR) | ||
398 | return maildirdriver_maildir_error_to_mail_error(r); | ||
399 | |||
400 | if (flags == NULL) | ||
401 | goto exit; | ||
402 | |||
403 | key.data = uid; | ||
404 | key.len = strlen(uid); | ||
405 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
406 | if (r < 0) | ||
407 | goto exit; | ||
408 | |||
409 | md_msg = value.data; | ||
410 | |||
411 | md_flags = maildirdriver_flags_to_maildir_flags(flags->fl_flags); | ||
412 | |||
413 | r = maildir_message_change_flags(md, uid, md_flags); | ||
414 | if (r != MAILDIR_NO_ERROR) | ||
415 | goto exit; | ||
416 | |||
417 | return MAIL_NO_ERROR; | ||
418 | |||
419 | exit: | ||
420 | return MAIL_NO_ERROR; | ||
370 | } | 421 | } |
371 | 422 | ||
372 | static int get_messages_list(mailsession * session, | 423 | static int get_messages_list(mailsession * session, |
373 | struct mailmessage_list ** result) | 424 | struct mailmessage_list ** result) |
374 | { | 425 | { |
375 | struct maildir * md; | 426 | struct maildir * md; |
376 | int r; | 427 | int r; |
377 | struct mailmessage_list * env_list; | 428 | struct mailmessage_list * env_list; |
378 | int res; | 429 | int res; |
379 | 430 | ||
380 | md = get_maildir_session(session); | 431 | md = get_maildir_session(session); |
381 | if (md == NULL) | 432 | if (md == NULL) |
382 | return MAIL_ERROR_BAD_STATE; | 433 | return MAIL_ERROR_BAD_STATE; |
383 | 434 | ||
384 | r = maildir_update(md); | 435 | r = maildir_update(md); |
385 | if (r != MAILDIR_NO_ERROR) { | 436 | if (r != MAILDIR_NO_ERROR) { |
386 | res = maildirdriver_maildir_error_to_mail_error(r); | 437 | res = maildirdriver_maildir_error_to_mail_error(r); |
387 | goto err; | 438 | goto err; |
388 | } | 439 | } |
389 | 440 | ||
390 | r = maildir_get_messages_list(session, md, | 441 | r = maildir_get_messages_list(session, md, |
391 | maildir_message_driver, &env_list); | 442 | maildir_message_driver, &env_list); |
392 | if (r != MAILDIR_NO_ERROR) { | 443 | if (r != MAILDIR_NO_ERROR) { |
393 | res = r; | 444 | res = r; |
394 | goto free_list; | 445 | goto free_list; |
395 | } | 446 | } |
396 | 447 | ||
397 | * result = env_list; | 448 | * result = env_list; |
398 | 449 | ||
399 | return MAIL_NO_ERROR; | 450 | return MAIL_NO_ERROR; |
400 | 451 | ||
401 | free_list: | 452 | free_list: |
diff --git a/kmicromail/libetpan/generic/maildirdriver_cached.c b/kmicromail/libetpan/generic/maildirdriver_cached.c index 503d1c9..8a5e206 100644 --- a/kmicromail/libetpan/generic/maildirdriver_cached.c +++ b/kmicromail/libetpan/generic/maildirdriver_cached.c | |||
@@ -57,111 +57,115 @@ | |||
57 | #include "mail_cache_db.h" | 57 | #include "mail_cache_db.h" |
58 | #include "libetpan-config.h" | 58 | #include "libetpan-config.h" |
59 | 59 | ||
60 | static int initialize(mailsession * session); | 60 | static int initialize(mailsession * session); |
61 | 61 | ||
62 | static void uninitialize(mailsession * session); | 62 | static void uninitialize(mailsession * session); |
63 | 63 | ||
64 | static int parameters(mailsession * session, | 64 | static int parameters(mailsession * session, |
65 | int id, void * value); | 65 | int id, void * value); |
66 | 66 | ||
67 | static int connect_path(mailsession * session, char * path); | 67 | static int connect_path(mailsession * session, char * path); |
68 | 68 | ||
69 | static int logout(mailsession * session); | 69 | static int logout(mailsession * session); |
70 | 70 | ||
71 | static int expunge_folder(mailsession * session); | 71 | static int expunge_folder(mailsession * session); |
72 | 72 | ||
73 | static int status_folder(mailsession * session, char * mb, | 73 | static int status_folder(mailsession * session, char * mb, |
74 | uint32_t * result_messages, uint32_t * result_recent, | 74 | uint32_t * result_messages, uint32_t * result_recent, |
75 | uint32_t * result_unseen); | 75 | uint32_t * result_unseen); |
76 | 76 | ||
77 | static int recent_number(mailsession * session, char * mb, | 77 | static int recent_number(mailsession * session, char * mb, |
78 | uint32_t * result); | 78 | uint32_t * result); |
79 | 79 | ||
80 | static int unseen_number(mailsession * session, char * mb, | 80 | static int unseen_number(mailsession * session, char * mb, |
81 | uint32_t * result); | 81 | uint32_t * result); |
82 | 82 | ||
83 | static int messages_number(mailsession * session, char * mb, | 83 | static int messages_number(mailsession * session, char * mb, |
84 | uint32_t * result); | 84 | uint32_t * result); |
85 | 85 | ||
86 | static int append_message(mailsession * session, | 86 | static int append_message(mailsession * session, |
87 | char * message, size_t size); | 87 | char * message, size_t size); |
88 | 88 | ||
89 | static int append_message_flags(mailsession * session, | ||
90 | char * message, size_t size, struct mail_flags * flags); | ||
91 | |||
89 | static int get_messages_list(mailsession * session, | 92 | static int get_messages_list(mailsession * session, |
90 | struct mailmessage_list ** result); | 93 | struct mailmessage_list ** result); |
91 | 94 | ||
92 | static int get_envelopes_list(mailsession * session, | 95 | static int get_envelopes_list(mailsession * session, |
93 | struct mailmessage_list * env_list); | 96 | struct mailmessage_list * env_list); |
94 | 97 | ||
95 | static int check_folder(mailsession * session); | 98 | static int check_folder(mailsession * session); |
96 | 99 | ||
97 | static int get_message(mailsession * session, | 100 | static int get_message(mailsession * session, |
98 | uint32_t num, mailmessage ** result); | 101 | uint32_t num, mailmessage ** result); |
99 | 102 | ||
100 | static int get_message_by_uid(mailsession * session, | 103 | static int get_message_by_uid(mailsession * session, |
101 | const char * uid, mailmessage ** result); | 104 | const char * uid, mailmessage ** result); |
102 | 105 | ||
103 | static mailsession_driver local_maildir_cached_session_driver = { | 106 | static mailsession_driver local_maildir_cached_session_driver = { |
104 | .sess_name = "maildir-cached", | 107 | .sess_name = "maildir-cached", |
105 | 108 | ||
106 | .sess_initialize = initialize, | 109 | .sess_initialize = initialize, |
107 | .sess_uninitialize = uninitialize, | 110 | .sess_uninitialize = uninitialize, |
108 | 111 | ||
109 | .sess_parameters = parameters, | 112 | .sess_parameters = parameters, |
110 | 113 | ||
111 | .sess_connect_stream = NULL, | 114 | .sess_connect_stream = NULL, |
112 | .sess_connect_path = connect_path, | 115 | .sess_connect_path = connect_path, |
113 | .sess_starttls = NULL, | 116 | .sess_starttls = NULL, |
114 | .sess_login = NULL, | 117 | .sess_login = NULL, |
115 | .sess_logout = logout, | 118 | .sess_logout = logout, |
116 | .sess_noop = NULL, | 119 | .sess_noop = NULL, |
117 | 120 | ||
118 | .sess_build_folder_name = NULL, | 121 | .sess_build_folder_name = NULL, |
119 | .sess_create_folder = NULL, | 122 | .sess_create_folder = NULL, |
120 | .sess_delete_folder = NULL, | 123 | .sess_delete_folder = NULL, |
121 | .sess_rename_folder = NULL, | 124 | .sess_rename_folder = NULL, |
122 | .sess_check_folder = check_folder, | 125 | .sess_check_folder = check_folder, |
123 | .sess_examine_folder = NULL, | 126 | .sess_examine_folder = NULL, |
124 | .sess_select_folder = NULL, | 127 | .sess_select_folder = NULL, |
125 | .sess_expunge_folder = expunge_folder, | 128 | .sess_expunge_folder = expunge_folder, |
126 | .sess_status_folder = status_folder, | 129 | .sess_status_folder = status_folder, |
127 | .sess_messages_number = messages_number, | 130 | .sess_messages_number = messages_number, |
128 | .sess_recent_number = recent_number, | 131 | .sess_recent_number = recent_number, |
129 | .sess_unseen_number = unseen_number, | 132 | .sess_unseen_number = unseen_number, |
130 | .sess_list_folders = NULL, | 133 | .sess_list_folders = NULL, |
131 | .sess_lsub_folders = NULL, | 134 | .sess_lsub_folders = NULL, |
132 | .sess_subscribe_folder = NULL, | 135 | .sess_subscribe_folder = NULL, |
133 | .sess_unsubscribe_folder = NULL, | 136 | .sess_unsubscribe_folder = NULL, |
134 | 137 | ||
135 | .sess_append_message = append_message, | 138 | .sess_append_message = append_message, |
139 | .sess_append_message_flags = append_message_flags, | ||
136 | .sess_copy_message = NULL, | 140 | .sess_copy_message = NULL, |
137 | .sess_move_message = NULL, | 141 | .sess_move_message = NULL, |
138 | 142 | ||
139 | .sess_get_messages_list = get_messages_list, | 143 | .sess_get_messages_list = get_messages_list, |
140 | .sess_get_envelopes_list = get_envelopes_list, | 144 | .sess_get_envelopes_list = get_envelopes_list, |
141 | .sess_remove_message = NULL, | 145 | .sess_remove_message = NULL, |
142 | #if 0 | 146 | #if 0 |
143 | .sess_search_messages = maildriver_generic_search_messages, | 147 | .sess_search_messages = maildriver_generic_search_messages, |
144 | #endif | 148 | #endif |
145 | 149 | ||
146 | .sess_get_message = get_message, | 150 | .sess_get_message = get_message, |
147 | .sess_get_message_by_uid = get_message_by_uid, | 151 | .sess_get_message_by_uid = get_message_by_uid, |
148 | }; | 152 | }; |
149 | 153 | ||
150 | mailsession_driver * maildir_cached_session_driver = | 154 | mailsession_driver * maildir_cached_session_driver = |
151 | &local_maildir_cached_session_driver; | 155 | &local_maildir_cached_session_driver; |
152 | 156 | ||
153 | 157 | ||
154 | static inline struct maildir_cached_session_state_data * | 158 | static inline struct maildir_cached_session_state_data * |
155 | get_cached_data(mailsession * session) | 159 | get_cached_data(mailsession * session) |
156 | { | 160 | { |
157 | return session->sess_data; | 161 | return session->sess_data; |
158 | } | 162 | } |
159 | 163 | ||
160 | static inline mailsession * get_ancestor(mailsession * session) | 164 | static inline mailsession * get_ancestor(mailsession * session) |
161 | { | 165 | { |
162 | return get_cached_data(session)->md_ancestor; | 166 | return get_cached_data(session)->md_ancestor; |
163 | } | 167 | } |
164 | 168 | ||
165 | static inline struct maildir_session_state_data * | 169 | static inline struct maildir_session_state_data * |
166 | get_ancestor_data(mailsession * session) | 170 | get_ancestor_data(mailsession * session) |
167 | { | 171 | { |
@@ -425,67 +429,141 @@ static int logout(mailsession * session) | |||
425 | } | 429 | } |
426 | 430 | ||
427 | static int status_folder(mailsession * session, char * mb, | 431 | static int status_folder(mailsession * session, char * mb, |
428 | uint32_t * result_messages, uint32_t * result_recent, | 432 | uint32_t * result_messages, uint32_t * result_recent, |
429 | uint32_t * result_unseen) | 433 | uint32_t * result_unseen) |
430 | { | 434 | { |
431 | return mailsession_status_folder(get_ancestor(session), mb, | 435 | return mailsession_status_folder(get_ancestor(session), mb, |
432 | result_messages, result_recent, result_unseen); | 436 | result_messages, result_recent, result_unseen); |
433 | } | 437 | } |
434 | 438 | ||
435 | static int messages_number(mailsession * session, char * mb, | 439 | static int messages_number(mailsession * session, char * mb, |
436 | uint32_t * result) | 440 | uint32_t * result) |
437 | { | 441 | { |
438 | return mailsession_messages_number(get_ancestor(session), mb, result); | 442 | return mailsession_messages_number(get_ancestor(session), mb, result); |
439 | } | 443 | } |
440 | 444 | ||
441 | static int unseen_number(mailsession * session, char * mb, | 445 | static int unseen_number(mailsession * session, char * mb, |
442 | uint32_t * result) | 446 | uint32_t * result) |
443 | { | 447 | { |
444 | return mailsession_unseen_number(get_ancestor(session), mb, result); | 448 | return mailsession_unseen_number(get_ancestor(session), mb, result); |
445 | } | 449 | } |
446 | 450 | ||
447 | static int recent_number(mailsession * session, char * mb, | 451 | static int recent_number(mailsession * session, char * mb, |
448 | uint32_t * result) | 452 | uint32_t * result) |
449 | { | 453 | { |
450 | return mailsession_recent_number(get_ancestor(session), mb, result); | 454 | return mailsession_recent_number(get_ancestor(session), mb, result); |
451 | } | 455 | } |
452 | 456 | ||
453 | 457 | ||
454 | static int append_message(mailsession * session, | 458 | static int append_message(mailsession * session, |
455 | char * message, size_t size) | 459 | char * message, size_t size) |
456 | { | 460 | { |
461 | #if 0 | ||
457 | return mailsession_append_message(get_ancestor(session), message, size); | 462 | return mailsession_append_message(get_ancestor(session), message, size); |
463 | #endif | ||
464 | return append_message_flags(session, message, size, NULL); | ||
458 | } | 465 | } |
459 | 466 | ||
467 | static int append_message_flags(mailsession * session, | ||
468 | char * message, size_t size, struct mail_flags * flags) | ||
469 | { | ||
470 | struct maildir * md; | ||
471 | int r; | ||
472 | char uid[PATH_MAX]; | ||
473 | struct maildir_msg * md_msg; | ||
474 | chashdatum key; | ||
475 | chashdatum value; | ||
476 | uint32_t md_flags; | ||
477 | struct mail_cache_db * cache_db_flags; | ||
478 | char filename_flags[PATH_MAX]; | ||
479 | MMAPString * mmapstr; | ||
480 | struct maildir_cached_session_state_data * data; | ||
481 | |||
482 | md = get_maildir_session(session); | ||
483 | if (md == NULL) | ||
484 | return MAIL_ERROR_BAD_STATE; | ||
485 | |||
486 | r = maildir_message_add_uid(md, message, size, | ||
487 | uid, sizeof(uid)); | ||
488 | if (r != MAILDIR_NO_ERROR) | ||
489 | return maildirdriver_maildir_error_to_mail_error(r); | ||
490 | |||
491 | if (flags == NULL) | ||
492 | goto exit; | ||
493 | |||
494 | data = get_cached_data(session); | ||
495 | |||
496 | snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", | ||
497 | data->md_flags_directory, MAIL_DIR_SEPARATOR, data->md_quoted_mb, | ||
498 | MAIL_DIR_SEPARATOR, FLAGS_NAME); | ||
499 | |||
500 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
501 | if (r < 0) | ||
502 | goto exit; | ||
503 | |||
504 | mmapstr = mmap_string_new(""); | ||
505 | if (mmapstr == NULL) | ||
506 | goto close_db_flags; | ||
507 | |||
508 | r = write_cached_flags(cache_db_flags, mmapstr, | ||
509 | uid, flags); | ||
510 | |||
511 | mmap_string_free(mmapstr); | ||
512 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
513 | |||
514 | if (r != MAIL_NO_ERROR) | ||
515 | goto exit; | ||
516 | |||
517 | key.data = uid; | ||
518 | key.len = strlen(uid); | ||
519 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
520 | if (r < 0) | ||
521 | goto exit; | ||
522 | |||
523 | md_msg = value.data; | ||
524 | |||
525 | md_flags = maildirdriver_flags_to_maildir_flags(flags->fl_flags); | ||
526 | |||
527 | r = maildir_message_change_flags(md, uid, md_flags); | ||
528 | if (r != MAILDIR_NO_ERROR) | ||
529 | goto exit; | ||
530 | |||
531 | return MAIL_NO_ERROR; | ||
532 | |||
533 | close_db_flags: | ||
534 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
535 | exit: | ||
536 | return MAIL_NO_ERROR; | ||
537 | } | ||
460 | 538 | ||
461 | #define UID_NAME "uid.db" | 539 | #define UID_NAME "uid.db" |
462 | 540 | ||
463 | static int uid_clean_up(struct mail_cache_db * uid_db, | 541 | static int uid_clean_up(struct mail_cache_db * uid_db, |
464 | struct mailmessage_list * env_list) | 542 | struct mailmessage_list * env_list) |
465 | { | 543 | { |
466 | chash * hash_exist; | 544 | chash * hash_exist; |
467 | int res; | 545 | int res; |
468 | int r; | 546 | int r; |
469 | unsigned int i; | 547 | unsigned int i; |
470 | chashdatum key; | 548 | chashdatum key; |
471 | chashdatum value; | 549 | chashdatum value; |
472 | char key_str[PATH_MAX]; | 550 | char key_str[PATH_MAX]; |
473 | 551 | ||
474 | /* flush cache */ | 552 | /* flush cache */ |
475 | 553 | ||
476 | hash_exist = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYALL); | 554 | hash_exist = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYALL); |
477 | if (hash_exist == NULL) { | 555 | if (hash_exist == NULL) { |
478 | res = MAIL_ERROR_MEMORY; | 556 | res = MAIL_ERROR_MEMORY; |
479 | goto err; | 557 | goto err; |
480 | } | 558 | } |
481 | 559 | ||
482 | value.data = NULL; | 560 | value.data = NULL; |
483 | value.len = 0; | 561 | value.len = 0; |
484 | 562 | ||
485 | key.data = "max-uid"; | 563 | key.data = "max-uid"; |
486 | key.len = strlen("max-uid"); | 564 | key.len = strlen("max-uid"); |
487 | r = chash_set(hash_exist, &key, &value, NULL); | 565 | r = chash_set(hash_exist, &key, &value, NULL); |
488 | 566 | ||
489 | for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { | 567 | for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) { |
490 | mailmessage * msg; | 568 | mailmessage * msg; |
491 | 569 | ||
diff --git a/kmicromail/libetpan/generic/maildirdriver_cached_message.c b/kmicromail/libetpan/generic/maildirdriver_cached_message.c index 51866aa..34de351 100644 --- a/kmicromail/libetpan/generic/maildirdriver_cached_message.c +++ b/kmicromail/libetpan/generic/maildirdriver_cached_message.c | |||
@@ -10,104 +10,109 @@ | |||
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "maildirdriver_message.h" | 36 | #include "maildirdriver_message.h" |
37 | 37 | ||
38 | #include "mailmessage_tools.h" | 38 | #include "mailmessage_tools.h" |
39 | #include "maildirdriver.h" | 39 | #include "maildirdriver.h" |
40 | #include "maildir.h" | 40 | #include "maildir.h" |
41 | #include "generic_cache.h" | 41 | #include "generic_cache.h" |
42 | #include "mail_cache_db.h" | ||
43 | #include "maildirdriver_tools.h" | ||
42 | 44 | ||
43 | #include <unistd.h> | 45 | #include <unistd.h> |
44 | #include <sys/mman.h> | 46 | #include <sys/mman.h> |
45 | #include <sys/types.h> | 47 | #include <sys/types.h> |
46 | #include <sys/stat.h> | 48 | #include <sys/stat.h> |
47 | #include <fcntl.h> | 49 | #include <fcntl.h> |
48 | #include <string.h> | 50 | #include <string.h> |
49 | #include <stdlib.h> | 51 | #include <stdlib.h> |
50 | 52 | ||
53 | static int get_flags(mailmessage * msg_info, | ||
54 | struct mail_flags ** result); | ||
55 | |||
51 | static int prefetch(mailmessage * msg_info); | 56 | static int prefetch(mailmessage * msg_info); |
52 | 57 | ||
53 | static void prefetch_free(struct generic_message_t * msg); | 58 | static void prefetch_free(struct generic_message_t * msg); |
54 | 59 | ||
55 | static int initialize(mailmessage * msg_info); | 60 | static int initialize(mailmessage * msg_info); |
56 | 61 | ||
57 | static void check(mailmessage * msg_info); | 62 | static void check(mailmessage * msg_info); |
58 | 63 | ||
59 | static mailmessage_driver local_maildir_cached_message_driver = { | 64 | static mailmessage_driver local_maildir_cached_message_driver = { |
60 | .msg_name = "maildir-cached", | 65 | .msg_name = "maildir-cached", |
61 | 66 | ||
62 | .msg_initialize = initialize, | 67 | .msg_initialize = initialize, |
63 | .msg_uninitialize = mailmessage_generic_uninitialize, | 68 | .msg_uninitialize = mailmessage_generic_uninitialize, |
64 | 69 | ||
65 | .msg_flush = mailmessage_generic_flush, | 70 | .msg_flush = mailmessage_generic_flush, |
66 | .msg_check = check, | 71 | .msg_check = check, |
67 | 72 | ||
68 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, | 73 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, |
69 | 74 | ||
70 | .msg_fetch = mailmessage_generic_fetch, | 75 | .msg_fetch = mailmessage_generic_fetch, |
71 | .msg_fetch_header = mailmessage_generic_fetch_header, | 76 | .msg_fetch_header = mailmessage_generic_fetch_header, |
72 | .msg_fetch_body = mailmessage_generic_fetch_header, | 77 | .msg_fetch_body = mailmessage_generic_fetch_header, |
73 | .msg_fetch_size = NULL, | 78 | .msg_fetch_size = NULL, |
74 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, | 79 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, |
75 | .msg_fetch_section = mailmessage_generic_fetch_section, | 80 | .msg_fetch_section = mailmessage_generic_fetch_section, |
76 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, | 81 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, |
77 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, | 82 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, |
78 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, | 83 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, |
79 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, | 84 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, |
80 | 85 | ||
81 | .msg_get_flags = NULL, | 86 | .msg_get_flags = get_flags, |
82 | }; | 87 | }; |
83 | 88 | ||
84 | mailmessage_driver * maildir_cached_message_driver = | 89 | mailmessage_driver * maildir_cached_message_driver = |
85 | &local_maildir_cached_message_driver; | 90 | &local_maildir_cached_message_driver; |
86 | 91 | ||
87 | struct maildir_msg_data { | 92 | struct maildir_msg_data { |
88 | int fd; | 93 | int fd; |
89 | }; | 94 | }; |
90 | 95 | ||
91 | #if 0 | 96 | #if 0 |
92 | static inline struct maildir_cached_session_state_data * | 97 | static inline struct maildir_cached_session_state_data * |
93 | get_cached_session_data(mailmessage * msg) | 98 | get_cached_session_data(mailmessage * msg) |
94 | { | 99 | { |
95 | return msg->session->data; | 100 | return msg->session->data; |
96 | } | 101 | } |
97 | 102 | ||
98 | static inline mailsession * cached_session_get_ancestor(mailsession * session) | 103 | static inline mailsession * cached_session_get_ancestor(mailsession * session) |
99 | { | 104 | { |
100 | return get_data(session)->session; | 105 | return get_data(session)->session; |
101 | } | 106 | } |
102 | 107 | ||
103 | static inline struct maildir_session_state_data * | 108 | static inline struct maildir_session_state_data * |
104 | cached_session_get_ancestor_data(mailsession * session) | 109 | cached_session_get_ancestor_data(mailsession * session) |
105 | { | 110 | { |
106 | return get_ancestor(session)->data; | 111 | return get_ancestor(session)->data; |
107 | } | 112 | } |
108 | 113 | ||
109 | static struct maildir * get_maildir_session(mailmessage * msg) | 114 | static struct maildir * get_maildir_session(mailmessage * msg) |
110 | { | 115 | { |
111 | return cached_session_get_ancestor_data(msg->session)->session; | 116 | return cached_session_get_ancestor_data(msg->session)->session; |
112 | } | 117 | } |
113 | #endif | 118 | #endif |
@@ -217,32 +222,113 @@ static void prefetch_free(struct generic_message_t * msg) | |||
217 | close(data->fd); | 222 | close(data->fd); |
218 | free(data); | 223 | free(data); |
219 | } | 224 | } |
220 | } | 225 | } |
221 | 226 | ||
222 | static int initialize(mailmessage * msg_info) | 227 | static int initialize(mailmessage * msg_info) |
223 | { | 228 | { |
224 | struct generic_message_t * msg; | 229 | struct generic_message_t * msg; |
225 | int r; | 230 | int r; |
226 | 231 | ||
227 | r = mailmessage_generic_initialize(msg_info); | 232 | r = mailmessage_generic_initialize(msg_info); |
228 | if (r != MAIL_NO_ERROR) | 233 | if (r != MAIL_NO_ERROR) |
229 | return r; | 234 | return r; |
230 | 235 | ||
231 | msg = msg_info->msg_data; | 236 | msg = msg_info->msg_data; |
232 | msg->msg_prefetch = prefetch; | 237 | msg->msg_prefetch = prefetch; |
233 | msg->msg_prefetch_free = prefetch_free; | 238 | msg->msg_prefetch_free = prefetch_free; |
234 | 239 | ||
235 | return MAIL_NO_ERROR; | 240 | return MAIL_NO_ERROR; |
236 | } | 241 | } |
237 | 242 | ||
238 | static void check(mailmessage * msg_info) | 243 | static void check(mailmessage * msg_info) |
239 | { | 244 | { |
240 | int r; | 245 | int r; |
241 | 246 | ||
242 | if (msg_info->msg_flags != NULL) { | 247 | if (msg_info->msg_flags != NULL) { |
243 | r = mail_flags_store_set(get_session_ancestor_data(msg_info)->md_flags_store, msg_info); | 248 | r = mail_flags_store_set(get_session_ancestor_data(msg_info)->md_flags_store, msg_info); |
244 | 249 | ||
245 | r = mail_flags_store_set(get_cached_session_data(msg_info)->md_flags_store, msg_info); | 250 | r = mail_flags_store_set(get_cached_session_data(msg_info)->md_flags_store, msg_info); |
246 | /* ignore errors */ | 251 | /* ignore errors */ |
247 | } | 252 | } |
248 | } | 253 | } |
254 | |||
255 | #define FLAGS_NAME "flags.db" | ||
256 | |||
257 | static int get_flags(mailmessage * msg_info, | ||
258 | struct mail_flags ** result) | ||
259 | { | ||
260 | struct mail_cache_db * cache_db_flags; | ||
261 | chashdatum key; | ||
262 | chashdatum value; | ||
263 | struct maildir * md; | ||
264 | struct mail_flags * flags; | ||
265 | struct maildir_cached_session_state_data * data; | ||
266 | struct maildir_msg * md_msg; | ||
267 | int r; | ||
268 | uint32_t driver_flags; | ||
269 | char filename_flags[PATH_MAX]; | ||
270 | char keyname[PATH_MAX]; | ||
271 | MMAPString * mmapstr; | ||
272 | |||
273 | if (msg_info->msg_flags != NULL) { | ||
274 | * result = msg_info->msg_flags; | ||
275 | return MAIL_NO_ERROR; | ||
276 | } | ||
277 | |||
278 | data = get_cached_session_data(msg_info); | ||
279 | flags = mail_flags_store_get(data->md_flags_store, | ||
280 | msg_info->msg_index); | ||
281 | if (flags != NULL) { | ||
282 | msg_info->msg_flags = flags; | ||
283 | * result = msg_info->msg_flags; | ||
284 | return MAIL_NO_ERROR; | ||
285 | } | ||
286 | |||
287 | snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", | ||
288 | data->md_flags_directory, MAIL_DIR_SEPARATOR, data->md_quoted_mb, | ||
289 | MAIL_DIR_SEPARATOR, FLAGS_NAME); | ||
290 | |||
291 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
292 | if (r < 0) | ||
293 | return MAIL_ERROR_FILE; | ||
294 | |||
295 | snprintf(keyname, PATH_MAX, "%s-flags", msg_info->msg_uid); | ||
296 | |||
297 | mmapstr = mmap_string_new(""); | ||
298 | if (mmapstr == NULL) { | ||
299 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
300 | return MAIL_ERROR_MEMORY; | ||
301 | } | ||
302 | |||
303 | r = generic_cache_flags_read(cache_db_flags, mmapstr, keyname, &flags); | ||
304 | mmap_string_free(mmapstr); | ||
305 | |||
306 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
307 | |||
308 | if (r != MAIL_NO_ERROR) { | ||
309 | flags = mail_flags_new_empty(); | ||
310 | if (flags == NULL) | ||
311 | return MAIL_ERROR_MEMORY; | ||
312 | } | ||
313 | |||
314 | md = get_maildir_session(msg_info); | ||
315 | if (md == NULL) | ||
316 | return MAIL_ERROR_BAD_STATE; | ||
317 | |||
318 | key.data = msg_info->msg_uid; | ||
319 | key.len = strlen(msg_info->msg_uid); | ||
320 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
321 | if (r < 0) | ||
322 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
323 | |||
324 | md_msg = value.data; | ||
325 | |||
326 | driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); | ||
327 | |||
328 | flags->fl_flags = driver_flags; | ||
329 | msg_info->msg_flags = flags; | ||
330 | |||
331 | * result = msg_info->msg_flags; | ||
332 | |||
333 | return MAIL_NO_ERROR; | ||
334 | } | ||
diff --git a/kmicromail/libetpan/generic/maildirdriver_message.c b/kmicromail/libetpan/generic/maildirdriver_message.c index 7cf9dd1..613fc39 100644 --- a/kmicromail/libetpan/generic/maildirdriver_message.c +++ b/kmicromail/libetpan/generic/maildirdriver_message.c | |||
@@ -5,109 +5,113 @@ | |||
5 | * All rights reserved. | 5 | * All rights reserved. |
6 | * | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "maildirdriver_message.h" | 36 | #include "maildirdriver_message.h" |
37 | #include "maildirdriver_tools.h" | ||
37 | 38 | ||
38 | #include "mailmessage_tools.h" | 39 | #include "mailmessage_tools.h" |
39 | #include "maildirdriver.h" | 40 | #include "maildirdriver.h" |
40 | #include "maildir.h" | 41 | #include "maildir.h" |
41 | #include "generic_cache.h" | 42 | #include "generic_cache.h" |
42 | 43 | ||
43 | #include <unistd.h> | 44 | #include <unistd.h> |
44 | #include <sys/mman.h> | 45 | #include <sys/mman.h> |
45 | #include <sys/types.h> | 46 | #include <sys/types.h> |
46 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
47 | #include <fcntl.h> | 48 | #include <fcntl.h> |
48 | #include <string.h> | 49 | #include <string.h> |
49 | #include <stdlib.h> | 50 | #include <stdlib.h> |
50 | 51 | ||
52 | static int get_flags(mailmessage * msg_info, | ||
53 | struct mail_flags ** result); | ||
54 | |||
51 | static int prefetch(mailmessage * msg_info); | 55 | static int prefetch(mailmessage * msg_info); |
52 | 56 | ||
53 | static void prefetch_free(struct generic_message_t * msg); | 57 | static void prefetch_free(struct generic_message_t * msg); |
54 | 58 | ||
55 | static int initialize(mailmessage * msg_info); | 59 | static int initialize(mailmessage * msg_info); |
56 | 60 | ||
57 | static void check(mailmessage * msg_info); | 61 | static void check(mailmessage * msg_info); |
58 | 62 | ||
59 | static mailmessage_driver local_maildir_message_driver = { | 63 | static mailmessage_driver local_maildir_message_driver = { |
60 | .msg_name = "maildir", | 64 | .msg_name = "maildir", |
61 | 65 | ||
62 | .msg_initialize = initialize, | 66 | .msg_initialize = initialize, |
63 | .msg_uninitialize = mailmessage_generic_uninitialize, | 67 | .msg_uninitialize = mailmessage_generic_uninitialize, |
64 | 68 | ||
65 | .msg_flush = mailmessage_generic_flush, | 69 | .msg_flush = mailmessage_generic_flush, |
66 | .msg_check = check, | 70 | .msg_check = check, |
67 | 71 | ||
68 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, | 72 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, |
69 | 73 | ||
70 | .msg_fetch = mailmessage_generic_fetch, | 74 | .msg_fetch = mailmessage_generic_fetch, |
71 | .msg_fetch_header = mailmessage_generic_fetch_header, | 75 | .msg_fetch_header = mailmessage_generic_fetch_header, |
72 | .msg_fetch_body = mailmessage_generic_fetch_header, | 76 | .msg_fetch_body = mailmessage_generic_fetch_header, |
73 | .msg_fetch_size = NULL, | 77 | .msg_fetch_size = NULL, |
74 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, | 78 | .msg_get_bodystructure = mailmessage_generic_get_bodystructure, |
75 | .msg_fetch_section = mailmessage_generic_fetch_section, | 79 | .msg_fetch_section = mailmessage_generic_fetch_section, |
76 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, | 80 | .msg_fetch_section_header = mailmessage_generic_fetch_section_header, |
77 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, | 81 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, |
78 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, | 82 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, |
79 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, | 83 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, |
80 | 84 | ||
81 | .msg_get_flags = NULL, | 85 | .msg_get_flags = get_flags, |
82 | }; | 86 | }; |
83 | 87 | ||
84 | mailmessage_driver * maildir_message_driver = &local_maildir_message_driver; | 88 | mailmessage_driver * maildir_message_driver = &local_maildir_message_driver; |
85 | 89 | ||
86 | struct maildir_msg_data { | 90 | struct maildir_msg_data { |
87 | int fd; | 91 | int fd; |
88 | }; | 92 | }; |
89 | 93 | ||
90 | static inline struct maildir_session_state_data * | 94 | static inline struct maildir_session_state_data * |
91 | get_session_data(mailmessage * msg) | 95 | get_session_data(mailmessage * msg) |
92 | { | 96 | { |
93 | return msg->msg_session->sess_data; | 97 | return msg->msg_session->sess_data; |
94 | } | 98 | } |
95 | 99 | ||
96 | static struct maildir * get_maildir_session(mailmessage * msg) | 100 | static struct maildir * get_maildir_session(mailmessage * msg) |
97 | { | 101 | { |
98 | return get_session_data(msg)->md_session; | 102 | return get_session_data(msg)->md_session; |
99 | } | 103 | } |
100 | 104 | ||
101 | static int prefetch(mailmessage * msg_info) | 105 | static int prefetch(mailmessage * msg_info) |
102 | { | 106 | { |
103 | struct generic_message_t * msg; | 107 | struct generic_message_t * msg; |
104 | int res; | 108 | int res; |
105 | struct maildir_msg_data * data; | 109 | struct maildir_msg_data * data; |
106 | char * filename; | 110 | char * filename; |
107 | int fd; | 111 | int fd; |
108 | char * mapping; | 112 | char * mapping; |
109 | struct maildir * md; | 113 | struct maildir * md; |
110 | 114 | ||
111 | md = get_maildir_session(msg_info); | 115 | md = get_maildir_session(msg_info); |
112 | 116 | ||
113 | if (msg_info->msg_uid == NULL) { | 117 | if (msg_info->msg_uid == NULL) { |
@@ -168,32 +172,84 @@ static void prefetch_free(struct generic_message_t * msg) | |||
168 | data = msg->msg_data; | 172 | data = msg->msg_data; |
169 | close(data->fd); | 173 | close(data->fd); |
170 | free(data); | 174 | free(data); |
171 | } | 175 | } |
172 | } | 176 | } |
173 | 177 | ||
174 | static int initialize(mailmessage * msg_info) | 178 | static int initialize(mailmessage * msg_info) |
175 | { | 179 | { |
176 | struct generic_message_t * msg; | 180 | struct generic_message_t * msg; |
177 | int r; | 181 | int r; |
178 | 182 | ||
179 | r = mailmessage_generic_initialize(msg_info); | 183 | r = mailmessage_generic_initialize(msg_info); |
180 | if (r != MAIL_NO_ERROR) | 184 | if (r != MAIL_NO_ERROR) |
181 | return r; | 185 | return r; |
182 | 186 | ||
183 | msg = msg_info->msg_data; | 187 | msg = msg_info->msg_data; |
184 | msg->msg_prefetch = prefetch; | 188 | msg->msg_prefetch = prefetch; |
185 | msg->msg_prefetch_free = prefetch_free; | 189 | msg->msg_prefetch_free = prefetch_free; |
186 | 190 | ||
187 | return MAIL_NO_ERROR; | 191 | return MAIL_NO_ERROR; |
188 | } | 192 | } |
189 | 193 | ||
190 | static void check(mailmessage * msg_info) | 194 | static void check(mailmessage * msg_info) |
191 | { | 195 | { |
192 | int r; | 196 | int r; |
193 | 197 | ||
194 | if (msg_info->msg_flags != NULL) { | 198 | if (msg_info->msg_flags != NULL) { |
195 | r = mail_flags_store_set(get_session_data(msg_info)->md_flags_store, | 199 | r = mail_flags_store_set(get_session_data(msg_info)->md_flags_store, |
196 | msg_info); | 200 | msg_info); |
197 | /* ignore errors */ | 201 | /* ignore errors */ |
198 | } | 202 | } |
199 | } | 203 | } |
204 | |||
205 | static int get_flags(mailmessage * msg_info, | ||
206 | struct mail_flags ** result) | ||
207 | { | ||
208 | chashdatum key; | ||
209 | chashdatum value; | ||
210 | struct maildir * md; | ||
211 | struct mail_flags * flags; | ||
212 | struct maildir_session_state_data * data; | ||
213 | struct maildir_msg * md_msg; | ||
214 | int r; | ||
215 | uint32_t driver_flags; | ||
216 | clist * ext; | ||
217 | |||
218 | if (msg_info->msg_flags != NULL) { | ||
219 | * result = msg_info->msg_flags; | ||
220 | return MAIL_NO_ERROR; | ||
221 | } | ||
222 | |||
223 | data = get_session_data(msg_info); | ||
224 | flags = mail_flags_store_get(data->md_flags_store, | ||
225 | msg_info->msg_index); | ||
226 | if (flags != NULL) { | ||
227 | msg_info->msg_flags = flags; | ||
228 | * result = msg_info->msg_flags; | ||
229 | return MAIL_NO_ERROR; | ||
230 | } | ||
231 | |||
232 | md = get_maildir_session(msg_info); | ||
233 | if (md == NULL) | ||
234 | return MAIL_ERROR_BAD_STATE; | ||
235 | |||
236 | key.data = msg_info->msg_uid; | ||
237 | key.len = strlen(msg_info->msg_uid); | ||
238 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
239 | if (r < 0) | ||
240 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
241 | |||
242 | md_msg = value.data; | ||
243 | |||
244 | driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); | ||
245 | |||
246 | ext = clist_new(); | ||
247 | if (ext == NULL) | ||
248 | return MAIL_ERROR_MEMORY; | ||
249 | |||
250 | msg_info->msg_flags = mail_flags_new(driver_flags, ext); | ||
251 | |||
252 | * result = msg_info->msg_flags; | ||
253 | |||
254 | return MAIL_NO_ERROR; | ||
255 | } | ||
diff --git a/kmicromail/libetpan/generic/maildirstorage.c b/kmicromail/libetpan/generic/maildirstorage.c index 7e6b461..e37f591 100644 --- a/kmicromail/libetpan/generic/maildirstorage.c +++ b/kmicromail/libetpan/generic/maildirstorage.c | |||
@@ -4,97 +4,98 @@ | |||
4 | * Copyright (C) 2001, 2002 - DINH Viet Hoa | 4 | * Copyright (C) 2001, 2002 - DINH Viet Hoa |
5 | * All rights reserved. | 5 | * All rights reserved. |
6 | * | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "maildirstorage.h" | ||
36 | #include "mailstorage.h" | 37 | #include "mailstorage.h" |
37 | 38 | ||
38 | #include "mail.h" | 39 | #include "mail.h" |
39 | #include "mailmessage.h" | 40 | #include "mailmessage.h" |
40 | #include "maildirdriver.h" | 41 | #include "maildirdriver.h" |
41 | #include "maildirdriver_cached.h" | 42 | #include "maildirdriver_cached.h" |
42 | #include "maildriver.h" | 43 | #include "maildriver.h" |
43 | 44 | ||
44 | #include <stdlib.h> | 45 | #include <stdlib.h> |
45 | #include <string.h> | 46 | #include <string.h> |
46 | 47 | ||
47 | /* maildir storage */ | 48 | /* maildir storage */ |
48 | 49 | ||
49 | static int maildir_mailstorage_connect(struct mailstorage * storage); | 50 | static int maildir_mailstorage_connect(struct mailstorage * storage); |
50 | static int | 51 | static int |
51 | maildir_mailstorage_get_folder_session(struct mailstorage * storage, | 52 | maildir_mailstorage_get_folder_session(struct mailstorage * storage, |
52 | char * pathname, mailsession ** result); | 53 | char * pathname, mailsession ** result); |
53 | static void maildir_mailstorage_uninitialize(struct mailstorage * storage); | 54 | static void maildir_mailstorage_uninitialize(struct mailstorage * storage); |
54 | 55 | ||
55 | static mailstorage_driver maildir_mailstorage_driver = { | 56 | static mailstorage_driver maildir_mailstorage_driver = { |
56 | .sto_name = "maildir", | 57 | .sto_name = "maildir", |
57 | .sto_connect = maildir_mailstorage_connect, | 58 | .sto_connect = maildir_mailstorage_connect, |
58 | .sto_get_folder_session = maildir_mailstorage_get_folder_session, | 59 | .sto_get_folder_session = maildir_mailstorage_get_folder_session, |
59 | .sto_uninitialize = maildir_mailstorage_uninitialize, | 60 | .sto_uninitialize = maildir_mailstorage_uninitialize, |
60 | }; | 61 | }; |
61 | 62 | ||
62 | int maildir_mailstorage_init(struct mailstorage * storage, | 63 | int maildir_mailstorage_init(struct mailstorage * storage, |
63 | char * md_pathname, int md_cached, | 64 | char * md_pathname, int md_cached, |
64 | char * md_cache_directory, char * md_flags_directory) | 65 | char * md_cache_directory, char * md_flags_directory) |
65 | { | 66 | { |
66 | struct maildir_mailstorage * maildir_storage; | 67 | struct maildir_mailstorage * maildir_storage; |
67 | 68 | ||
68 | maildir_storage = malloc(sizeof(struct maildir_mailstorage)); | 69 | maildir_storage = malloc(sizeof(* maildir_storage)); |
69 | if (maildir_storage == NULL) | 70 | if (maildir_storage == NULL) |
70 | goto err; | 71 | goto err; |
71 | 72 | ||
72 | maildir_storage->md_pathname = strdup(md_pathname); | 73 | maildir_storage->md_pathname = strdup(md_pathname); |
73 | if (maildir_storage->md_pathname == NULL) | 74 | if (maildir_storage->md_pathname == NULL) |
74 | goto free; | 75 | goto free; |
75 | 76 | ||
76 | maildir_storage->md_cached = md_cached; | 77 | maildir_storage->md_cached = md_cached; |
77 | 78 | ||
78 | if (md_cached && (md_cache_directory != NULL) && | 79 | if (md_cached && (md_cache_directory != NULL) && |
79 | (md_flags_directory != NULL)) { | 80 | (md_flags_directory != NULL)) { |
80 | maildir_storage->md_cache_directory = strdup(md_cache_directory); | 81 | maildir_storage->md_cache_directory = strdup(md_cache_directory); |
81 | if (maildir_storage->md_cache_directory == NULL) | 82 | if (maildir_storage->md_cache_directory == NULL) |
82 | goto free_pathname; | 83 | goto free_pathname; |
83 | 84 | ||
84 | maildir_storage->md_flags_directory = strdup(md_flags_directory); | 85 | maildir_storage->md_flags_directory = strdup(md_flags_directory); |
85 | if (maildir_storage->md_flags_directory == NULL) | 86 | if (maildir_storage->md_flags_directory == NULL) |
86 | goto free_cache_directory; | 87 | goto free_cache_directory; |
87 | } | 88 | } |
88 | else { | 89 | else { |
89 | maildir_storage->md_cached = FALSE; | 90 | maildir_storage->md_cached = FALSE; |
90 | maildir_storage->md_cache_directory = NULL; | 91 | maildir_storage->md_cache_directory = NULL; |
91 | maildir_storage->md_flags_directory = NULL; | 92 | maildir_storage->md_flags_directory = NULL; |
92 | } | 93 | } |
93 | 94 | ||
94 | storage->sto_data = maildir_storage; | 95 | storage->sto_data = maildir_storage; |
95 | storage->sto_driver = &maildir_mailstorage_driver; | 96 | storage->sto_driver = &maildir_mailstorage_driver; |
96 | 97 | ||
97 | return MAIL_NO_ERROR; | 98 | return MAIL_NO_ERROR; |
98 | 99 | ||
99 | free_cache_directory: | 100 | free_cache_directory: |
100 | free(maildir_storage->md_cache_directory); | 101 | free(maildir_storage->md_cache_directory); |
diff --git a/kmicromail/libetpan/generic/maildirstorage.h b/kmicromail/libetpan/generic/maildirstorage.h index d17ea2c..73d7b20 100644 --- a/kmicromail/libetpan/generic/maildirstorage.h +++ b/kmicromail/libetpan/generic/maildirstorage.h | |||
@@ -15,55 +15,55 @@ | |||
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef MAILDIRSTORAGE_H | 36 | #ifndef MAILDIRSTORAGE_H |
37 | 37 | ||
38 | #define MAILDIRSTORAGE_H | 38 | #define MAILDIRSTORAGE_H |
39 | 39 | ||
40 | #include <libetpan/maildirdriver_types.h> | 40 | #include <libetpan/maildirdriver_types.h> |
41 | 41 | ||
42 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
43 | extern "C" { | 43 | extern "C" { |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | /* | 46 | /* |
47 | maildir_mailstorage_init is the constructor for a mbox storage. | 47 | maildir_mailstorage_init is the constructor for a maildir storage. |
48 | 48 | ||
49 | @param storage this is the storage to initialize. | 49 | @param storage this is the storage to initialize. |
50 | 50 | ||
51 | @param pathname is the directory that contains the mailbox. | 51 | @param pathname is the directory that contains the mailbox. |
52 | 52 | ||
53 | @param cached if this value is != 0, a persistant cache will be | 53 | @param cached if this value is != 0, a persistant cache will be |
54 | stored on local system. | 54 | stored on local system. |
55 | 55 | ||
56 | @param cache_directory is the location of the cache | 56 | @param cache_directory is the location of the cache |
57 | 57 | ||
58 | @param flags_directory is the location of the flags | 58 | @param flags_directory is the location of the flags |
59 | */ | 59 | */ |
60 | 60 | ||
61 | int maildir_mailstorage_init(struct mailstorage * storage, | 61 | int maildir_mailstorage_init(struct mailstorage * storage, |
62 | char * md_pathname, int md_cached, | 62 | char * md_pathname, int md_cached, |
63 | char * md_cache_directory, char * md_flags_directory); | 63 | char * md_cache_directory, char * md_flags_directory); |
64 | 64 | ||
65 | #ifdef __cplusplus | 65 | #ifdef __cplusplus |
66 | } | 66 | } |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | #endif | 69 | #endif |
diff --git a/kmicromail/libetpan/generic/maildriver.c b/kmicromail/libetpan/generic/maildriver.c index 01e3e34..1fc478a 100644 --- a/kmicromail/libetpan/generic/maildriver.c +++ b/kmicromail/libetpan/generic/maildriver.c | |||
@@ -253,64 +253,74 @@ int mailsession_lsub_folders(mailsession * session, char * mb, | |||
253 | return MAIL_ERROR_NOT_IMPLEMENTED; | 253 | return MAIL_ERROR_NOT_IMPLEMENTED; |
254 | 254 | ||
255 | return session->sess_driver->sess_lsub_folders(session, mb, result); | 255 | return session->sess_driver->sess_lsub_folders(session, mb, result); |
256 | } | 256 | } |
257 | 257 | ||
258 | int mailsession_subscribe_folder(mailsession * session, char * mb) | 258 | int mailsession_subscribe_folder(mailsession * session, char * mb) |
259 | { | 259 | { |
260 | if (session->sess_driver->sess_subscribe_folder == NULL) | 260 | if (session->sess_driver->sess_subscribe_folder == NULL) |
261 | return MAIL_ERROR_NOT_IMPLEMENTED; | 261 | return MAIL_ERROR_NOT_IMPLEMENTED; |
262 | 262 | ||
263 | return session->sess_driver->sess_subscribe_folder(session, mb); | 263 | return session->sess_driver->sess_subscribe_folder(session, mb); |
264 | } | 264 | } |
265 | 265 | ||
266 | int mailsession_unsubscribe_folder(mailsession * session, char * mb) | 266 | int mailsession_unsubscribe_folder(mailsession * session, char * mb) |
267 | { | 267 | { |
268 | if (session->sess_driver->sess_unsubscribe_folder == NULL) | 268 | if (session->sess_driver->sess_unsubscribe_folder == NULL) |
269 | return MAIL_ERROR_NOT_IMPLEMENTED; | 269 | return MAIL_ERROR_NOT_IMPLEMENTED; |
270 | 270 | ||
271 | return session->sess_driver->sess_unsubscribe_folder(session, mb); | 271 | return session->sess_driver->sess_unsubscribe_folder(session, mb); |
272 | } | 272 | } |
273 | 273 | ||
274 | /* message */ | 274 | /* message */ |
275 | 275 | ||
276 | int mailsession_append_message(mailsession * session, | 276 | int mailsession_append_message(mailsession * session, |
277 | char * message, size_t size) | 277 | char * message, size_t size) |
278 | { | 278 | { |
279 | if (session->sess_driver->sess_append_message == NULL) | 279 | if (session->sess_driver->sess_append_message == NULL) |
280 | return MAIL_ERROR_NOT_IMPLEMENTED; | 280 | return MAIL_ERROR_NOT_IMPLEMENTED; |
281 | 281 | ||
282 | return session->sess_driver->sess_append_message(session, message, size); | 282 | return session->sess_driver->sess_append_message(session, message, size); |
283 | } | 283 | } |
284 | 284 | ||
285 | int mailsession_append_message_flags(mailsession * session, | ||
286 | char * message, size_t size, struct mail_flags * flags) | ||
287 | { | ||
288 | if (session->sess_driver->sess_append_message_flags == NULL) | ||
289 | return MAIL_ERROR_NOT_IMPLEMENTED; | ||
290 | |||
291 | return session->sess_driver->sess_append_message_flags(session, | ||
292 | message, size, flags); | ||
293 | } | ||
294 | |||
285 | int mailsession_copy_message(mailsession * session, | 295 | int mailsession_copy_message(mailsession * session, |
286 | uint32_t num, char * mb) | 296 | uint32_t num, char * mb) |
287 | { | 297 | { |
288 | if (session->sess_driver->sess_copy_message == NULL) | 298 | if (session->sess_driver->sess_copy_message == NULL) |
289 | return MAIL_ERROR_NOT_IMPLEMENTED; | 299 | return MAIL_ERROR_NOT_IMPLEMENTED; |
290 | 300 | ||
291 | return session->sess_driver->sess_copy_message(session, num, mb); | 301 | return session->sess_driver->sess_copy_message(session, num, mb); |
292 | } | 302 | } |
293 | 303 | ||
294 | int mailsession_move_message(mailsession * session, | 304 | int mailsession_move_message(mailsession * session, |
295 | uint32_t num, char * mb) | 305 | uint32_t num, char * mb) |
296 | { | 306 | { |
297 | if (session->sess_driver->sess_move_message == NULL) { | 307 | if (session->sess_driver->sess_move_message == NULL) { |
298 | int r; | 308 | int r; |
299 | 309 | ||
300 | if ((session->sess_driver->sess_copy_message == NULL) && | 310 | if ((session->sess_driver->sess_copy_message == NULL) && |
301 | (session->sess_driver->sess_remove_message == NULL)) | 311 | (session->sess_driver->sess_remove_message == NULL)) |
302 | return MAIL_ERROR_NOT_IMPLEMENTED; | 312 | return MAIL_ERROR_NOT_IMPLEMENTED; |
303 | 313 | ||
304 | r = mailsession_copy_message(session, num, mb); | 314 | r = mailsession_copy_message(session, num, mb); |
305 | if (r != MAIL_NO_ERROR) | 315 | if (r != MAIL_NO_ERROR) |
306 | return r; | 316 | return r; |
307 | 317 | ||
308 | r = mailsession_remove_message(session, num); | 318 | r = mailsession_remove_message(session, num); |
309 | if (r != MAIL_NO_ERROR) | 319 | if (r != MAIL_NO_ERROR) |
310 | return r; | 320 | return r; |
311 | 321 | ||
312 | return MAIL_NO_ERROR; | 322 | return MAIL_NO_ERROR; |
313 | } | 323 | } |
314 | 324 | ||
315 | return session->sess_driver->sess_move_message(session, num, mb); | 325 | return session->sess_driver->sess_move_message(session, num, mb); |
316 | } | 326 | } |
diff --git a/kmicromail/libetpan/generic/maildriver.h b/kmicromail/libetpan/generic/maildriver.h index 7da9aea..c773190 100644 --- a/kmicromail/libetpan/generic/maildriver.h +++ b/kmicromail/libetpan/generic/maildriver.h | |||
@@ -371,64 +371,67 @@ int mailsession_lsub_folders(mailsession * session, char * mb, | |||
371 | 371 | ||
372 | int mailsession_subscribe_folder(mailsession * session, char * mb); | 372 | int mailsession_subscribe_folder(mailsession * session, char * mb); |
373 | 373 | ||
374 | /* | 374 | /* |
375 | NOTE: driver's specific should be used | 375 | NOTE: driver's specific should be used |
376 | 376 | ||
377 | mailsession_unsubscribe_folder unsubscribes to the given mailbox | 377 | mailsession_unsubscribe_folder unsubscribes to the given mailbox |
378 | 378 | ||
379 | @param session the session | 379 | @param session the session |
380 | @param mb the mailbox | 380 | @param mb the mailbox |
381 | 381 | ||
382 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 382 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
383 | on error | 383 | on error |
384 | */ | 384 | */ |
385 | 385 | ||
386 | int mailsession_unsubscribe_folder(mailsession * session, char * mb); | 386 | int mailsession_unsubscribe_folder(mailsession * session, char * mb); |
387 | 387 | ||
388 | /* | 388 | /* |
389 | mailsession_append_message adds a RFC 2822 message to the current | 389 | mailsession_append_message adds a RFC 2822 message to the current |
390 | given mailbox | 390 | given mailbox |
391 | 391 | ||
392 | @param session the session | 392 | @param session the session |
393 | @param message is a string that contains the RFC 2822 message | 393 | @param message is a string that contains the RFC 2822 message |
394 | @param size this is the size of the message | 394 | @param size this is the size of the message |
395 | 395 | ||
396 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 396 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
397 | on error | 397 | on error |
398 | */ | 398 | */ |
399 | 399 | ||
400 | int mailsession_append_message(mailsession * session, | 400 | int mailsession_append_message(mailsession * session, |
401 | char * message, size_t size); | 401 | char * message, size_t size); |
402 | 402 | ||
403 | int mailsession_append_message_flags(mailsession * session, | ||
404 | char * message, size_t size, struct mail_flags * flags); | ||
405 | |||
403 | /* | 406 | /* |
404 | NOTE: some drivers does not implement this | 407 | NOTE: some drivers does not implement this |
405 | 408 | ||
406 | mailsession_copy_message copies a message whose number is given to | 409 | mailsession_copy_message copies a message whose number is given to |
407 | a given mailbox. The mailbox must be accessible from the same session. | 410 | a given mailbox. The mailbox must be accessible from the same session. |
408 | 411 | ||
409 | @param session the session | 412 | @param session the session |
410 | @param num the message number | 413 | @param num the message number |
411 | @param mb the destination mailbox | 414 | @param mb the destination mailbox |
412 | 415 | ||
413 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 416 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
414 | on error | 417 | on error |
415 | */ | 418 | */ |
416 | 419 | ||
417 | int mailsession_copy_message(mailsession * session, | 420 | int mailsession_copy_message(mailsession * session, |
418 | uint32_t num, char * mb); | 421 | uint32_t num, char * mb); |
419 | 422 | ||
420 | /* | 423 | /* |
421 | NOTE: some drivers does not implement this | 424 | NOTE: some drivers does not implement this |
422 | 425 | ||
423 | mailsession_move_message copies a message whose number is given to | 426 | mailsession_move_message copies a message whose number is given to |
424 | a given mailbox. The mailbox must be accessible from the same session. | 427 | a given mailbox. The mailbox must be accessible from the same session. |
425 | 428 | ||
426 | @param session the session | 429 | @param session the session |
427 | @param num the message number | 430 | @param num the message number |
428 | @param mb the destination mailbox | 431 | @param mb the destination mailbox |
429 | 432 | ||
430 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 433 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
431 | on error | 434 | on error |
432 | */ | 435 | */ |
433 | 436 | ||
434 | int mailsession_move_message(mailsession * session, | 437 | int mailsession_move_message(mailsession * session, |
diff --git a/kmicromail/libetpan/generic/maildriver_types.h b/kmicromail/libetpan/generic/maildriver_types.h index 3ff9440..9eab4d6 100644 --- a/kmicromail/libetpan/generic/maildriver_types.h +++ b/kmicromail/libetpan/generic/maildriver_types.h | |||
@@ -478,64 +478,66 @@ struct mailsession_driver { | |||
478 | char * name, char ** result); | 478 | char * name, char ** result); |
479 | 479 | ||
480 | int (* sess_create_folder)(mailsession * session, char * mb); | 480 | int (* sess_create_folder)(mailsession * session, char * mb); |
481 | int (* sess_delete_folder)(mailsession * session, char * mb); | 481 | int (* sess_delete_folder)(mailsession * session, char * mb); |
482 | int (* sess_rename_folder)(mailsession * session, char * mb, | 482 | int (* sess_rename_folder)(mailsession * session, char * mb, |
483 | char * new_name); | 483 | char * new_name); |
484 | int (* sess_check_folder)(mailsession * session); | 484 | int (* sess_check_folder)(mailsession * session); |
485 | int (* sess_examine_folder)(mailsession * session, char * mb); | 485 | int (* sess_examine_folder)(mailsession * session, char * mb); |
486 | int (* sess_select_folder)(mailsession * session, char * mb); | 486 | int (* sess_select_folder)(mailsession * session, char * mb); |
487 | int (* sess_expunge_folder)(mailsession * session); | 487 | int (* sess_expunge_folder)(mailsession * session); |
488 | int (* sess_status_folder)(mailsession * session, char * mb, | 488 | int (* sess_status_folder)(mailsession * session, char * mb, |
489 | uint32_t * result_num, uint32_t * result_recent, | 489 | uint32_t * result_num, uint32_t * result_recent, |
490 | uint32_t * result_unseen); | 490 | uint32_t * result_unseen); |
491 | int (* sess_messages_number)(mailsession * session, char * mb, | 491 | int (* sess_messages_number)(mailsession * session, char * mb, |
492 | uint32_t * result); | 492 | uint32_t * result); |
493 | int (* sess_recent_number)(mailsession * session, char * mb, | 493 | int (* sess_recent_number)(mailsession * session, char * mb, |
494 | uint32_t * result); | 494 | uint32_t * result); |
495 | int (* sess_unseen_number)(mailsession * session, char * mb, | 495 | int (* sess_unseen_number)(mailsession * session, char * mb, |
496 | uint32_t * result); | 496 | uint32_t * result); |
497 | 497 | ||
498 | int (* sess_list_folders)(mailsession * session, char * mb, | 498 | int (* sess_list_folders)(mailsession * session, char * mb, |
499 | struct mail_list ** result); | 499 | struct mail_list ** result); |
500 | int (* sess_lsub_folders)(mailsession * session, char * mb, | 500 | int (* sess_lsub_folders)(mailsession * session, char * mb, |
501 | struct mail_list ** result); | 501 | struct mail_list ** result); |
502 | 502 | ||
503 | int (* sess_subscribe_folder)(mailsession * session, char * mb); | 503 | int (* sess_subscribe_folder)(mailsession * session, char * mb); |
504 | int (* sess_unsubscribe_folder)(mailsession * session, char * mb); | 504 | int (* sess_unsubscribe_folder)(mailsession * session, char * mb); |
505 | 505 | ||
506 | /* messages operations */ | 506 | /* messages operations */ |
507 | 507 | ||
508 | int (* sess_append_message)(mailsession * session, | 508 | int (* sess_append_message)(mailsession * session, |
509 | char * message, size_t size); | 509 | char * message, size_t size); |
510 | int (* sess_append_message_flags)(mailsession * session, | ||
511 | char * message, size_t size, struct mail_flags * flags); | ||
510 | int (* sess_copy_message)(mailsession * session, | 512 | int (* sess_copy_message)(mailsession * session, |
511 | uint32_t num, char * mb); | 513 | uint32_t num, char * mb); |
512 | int (* sess_move_message)(mailsession * session, | 514 | int (* sess_move_message)(mailsession * session, |
513 | uint32_t num, char * mb); | 515 | uint32_t num, char * mb); |
514 | 516 | ||
515 | int (* sess_get_message)(mailsession * session, | 517 | int (* sess_get_message)(mailsession * session, |
516 | uint32_t num, mailmessage ** result); | 518 | uint32_t num, mailmessage ** result); |
517 | 519 | ||
518 | int (* sess_get_message_by_uid)(mailsession * session, | 520 | int (* sess_get_message_by_uid)(mailsession * session, |
519 | const char * uid, mailmessage ** result); | 521 | const char * uid, mailmessage ** result); |
520 | 522 | ||
521 | int (* sess_get_messages_list)(mailsession * session, | 523 | int (* sess_get_messages_list)(mailsession * session, |
522 | struct mailmessage_list ** result); | 524 | struct mailmessage_list ** result); |
523 | int (* sess_get_envelopes_list)(mailsession * session, | 525 | int (* sess_get_envelopes_list)(mailsession * session, |
524 | struct mailmessage_list * env_list); | 526 | struct mailmessage_list * env_list); |
525 | int (* sess_remove_message)(mailsession * session, uint32_t num); | 527 | int (* sess_remove_message)(mailsession * session, uint32_t num); |
526 | #if 0 | 528 | #if 0 |
527 | int (* sess_search_messages)(mailsession * session, char * charset, | 529 | int (* sess_search_messages)(mailsession * session, char * charset, |
528 | struct mail_search_key * key, | 530 | struct mail_search_key * key, |
529 | struct mail_search_result ** result); | 531 | struct mail_search_result ** result); |
530 | #endif | 532 | #endif |
531 | }; | 533 | }; |
532 | 534 | ||
533 | 535 | ||
534 | /* | 536 | /* |
535 | session is the data structure for a mail session. | 537 | session is the data structure for a mail session. |
536 | 538 | ||
537 | - data is the internal data structure used by the driver | 539 | - data is the internal data structure used by the driver |
538 | It is called when initializing the mailsession structure. | 540 | It is called when initializing the mailsession structure. |
539 | 541 | ||
540 | - driver is the driver used for the session | 542 | - driver is the driver used for the session |
541 | */ | 543 | */ |
diff --git a/kmicromail/libetpan/generic/mailfolder.c b/kmicromail/libetpan/generic/mailfolder.c index 2ddc37d..89ba891 100644 --- a/kmicromail/libetpan/generic/mailfolder.c +++ b/kmicromail/libetpan/generic/mailfolder.c | |||
@@ -3,64 +3,71 @@ | |||
3 | #include "maildriver.h" | 3 | #include "maildriver.h" |
4 | 4 | ||
5 | int mailfolder_noop(struct mailfolder * folder) | 5 | int mailfolder_noop(struct mailfolder * folder) |
6 | { | 6 | { |
7 | return mailsession_noop(folder->fld_session); | 7 | return mailsession_noop(folder->fld_session); |
8 | } | 8 | } |
9 | 9 | ||
10 | int mailfolder_check(struct mailfolder * folder) | 10 | int mailfolder_check(struct mailfolder * folder) |
11 | { | 11 | { |
12 | return mailsession_check_folder(folder->fld_session); | 12 | return mailsession_check_folder(folder->fld_session); |
13 | } | 13 | } |
14 | 14 | ||
15 | int mailfolder_expunge(struct mailfolder * folder) | 15 | int mailfolder_expunge(struct mailfolder * folder) |
16 | { | 16 | { |
17 | return mailsession_expunge_folder(folder->fld_session); | 17 | return mailsession_expunge_folder(folder->fld_session); |
18 | } | 18 | } |
19 | 19 | ||
20 | int mailfolder_status(struct mailfolder * folder, | 20 | int mailfolder_status(struct mailfolder * folder, |
21 | uint32_t * result_messages, uint32_t * result_recent, | 21 | uint32_t * result_messages, uint32_t * result_recent, |
22 | uint32_t * result_unseen) | 22 | uint32_t * result_unseen) |
23 | { | 23 | { |
24 | return mailsession_status_folder(folder->fld_session, | 24 | return mailsession_status_folder(folder->fld_session, |
25 | folder->fld_pathname, result_messages, | 25 | folder->fld_pathname, result_messages, |
26 | result_recent, result_unseen); | 26 | result_recent, result_unseen); |
27 | } | 27 | } |
28 | 28 | ||
29 | int mailfolder_append_message(struct mailfolder * folder, | 29 | int mailfolder_append_message(struct mailfolder * folder, |
30 | char * message, size_t size) | 30 | char * message, size_t size) |
31 | { | 31 | { |
32 | return mailsession_append_message(folder->fld_session, message, size); | 32 | return mailsession_append_message(folder->fld_session, message, size); |
33 | } | 33 | } |
34 | 34 | ||
35 | int mailfolder_append_message_flags(struct mailfolder * folder, | ||
36 | char * message, size_t size, struct mail_flags * flags) | ||
37 | { | ||
38 | return mailsession_append_message_flags(folder->fld_session, message, | ||
39 | size, flags); | ||
40 | } | ||
41 | |||
35 | int mailfolder_get_messages_list(struct mailfolder * folder, | 42 | int mailfolder_get_messages_list(struct mailfolder * folder, |
36 | struct mailmessage_list ** result) | 43 | struct mailmessage_list ** result) |
37 | { | 44 | { |
38 | int r; | 45 | int r; |
39 | struct mailmessage_list * msg_list; | 46 | struct mailmessage_list * msg_list; |
40 | unsigned int i; | 47 | unsigned int i; |
41 | 48 | ||
42 | r = mailsession_get_messages_list(folder->fld_session, &msg_list); | 49 | r = mailsession_get_messages_list(folder->fld_session, &msg_list); |
43 | if (r != MAIL_NO_ERROR) | 50 | if (r != MAIL_NO_ERROR) |
44 | return r; | 51 | return r; |
45 | 52 | ||
46 | for(i = 0 ; i < carray_count(msg_list->msg_tab) ; i ++) { | 53 | for(i = 0 ; i < carray_count(msg_list->msg_tab) ; i ++) { |
47 | mailmessage * msg; | 54 | mailmessage * msg; |
48 | 55 | ||
49 | msg = carray_get(msg_list->msg_tab, i); | 56 | msg = carray_get(msg_list->msg_tab, i); |
50 | msg->msg_folder = folder; | 57 | msg->msg_folder = folder; |
51 | } | 58 | } |
52 | 59 | ||
53 | * result = msg_list; | 60 | * result = msg_list; |
54 | 61 | ||
55 | return MAIL_NO_ERROR; | 62 | return MAIL_NO_ERROR; |
56 | } | 63 | } |
57 | 64 | ||
58 | int mailfolder_get_envelopes_list(struct mailfolder * folder, | 65 | int mailfolder_get_envelopes_list(struct mailfolder * folder, |
59 | struct mailmessage_list * result) | 66 | struct mailmessage_list * result) |
60 | { | 67 | { |
61 | return mailsession_get_envelopes_list(folder->fld_session, result); | 68 | return mailsession_get_envelopes_list(folder->fld_session, result); |
62 | } | 69 | } |
63 | 70 | ||
64 | int mailfolder_get_message(struct mailfolder * folder, | 71 | int mailfolder_get_message(struct mailfolder * folder, |
65 | uint32_t num, mailmessage ** result) | 72 | uint32_t num, mailmessage ** result) |
66 | { | 73 | { |
diff --git a/kmicromail/libetpan/generic/mailfolder.h b/kmicromail/libetpan/generic/mailfolder.h index 3ecad23..ff53470 100644 --- a/kmicromail/libetpan/generic/mailfolder.h +++ b/kmicromail/libetpan/generic/mailfolder.h | |||
@@ -1,32 +1,35 @@ | |||
1 | #ifndef MAILFOLDER_H | 1 | #ifndef MAILFOLDER_H |
2 | 2 | ||
3 | #define MAILFOLDER_H | 3 | #define MAILFOLDER_H |
4 | 4 | ||
5 | #include "mailstorage_types.h" | 5 | #include "mailstorage_types.h" |
6 | 6 | ||
7 | int mailfolder_noop(struct mailfolder * folder); | 7 | int mailfolder_noop(struct mailfolder * folder); |
8 | 8 | ||
9 | int mailfolder_check(struct mailfolder * folder); | 9 | int mailfolder_check(struct mailfolder * folder); |
10 | 10 | ||
11 | int mailfolder_expunge(struct mailfolder * folder); | 11 | int mailfolder_expunge(struct mailfolder * folder); |
12 | 12 | ||
13 | int mailfolder_status(struct mailfolder * folder, | 13 | int mailfolder_status(struct mailfolder * folder, |
14 | uint32_t * result_messages, uint32_t * result_recent, | 14 | uint32_t * result_messages, uint32_t * result_recent, |
15 | uint32_t * result_unseen); | 15 | uint32_t * result_unseen); |
16 | 16 | ||
17 | int mailfolder_append_message(struct mailfolder * folder, | 17 | int mailfolder_append_message(struct mailfolder * folder, |
18 | char * message, size_t size); | 18 | char * message, size_t size); |
19 | 19 | ||
20 | int mailfolder_append_message_flags(struct mailfolder * folder, | ||
21 | char * message, size_t size, struct mail_flags * flags); | ||
22 | |||
20 | int mailfolder_get_messages_list(struct mailfolder * folder, | 23 | int mailfolder_get_messages_list(struct mailfolder * folder, |
21 | struct mailmessage_list ** result); | 24 | struct mailmessage_list ** result); |
22 | 25 | ||
23 | int mailfolder_get_envelopes_list(struct mailfolder * folder, | 26 | int mailfolder_get_envelopes_list(struct mailfolder * folder, |
24 | struct mailmessage_list * result); | 27 | struct mailmessage_list * result); |
25 | 28 | ||
26 | int mailfolder_get_message(struct mailfolder * folder, | 29 | int mailfolder_get_message(struct mailfolder * folder, |
27 | uint32_t num, mailmessage ** result); | 30 | uint32_t num, mailmessage ** result); |
28 | 31 | ||
29 | int mailfolder_get_message_by_uid(struct mailfolder * folder, | 32 | int mailfolder_get_message_by_uid(struct mailfolder * folder, |
30 | const char * uid, mailmessage ** result); | 33 | const char * uid, mailmessage ** result); |
31 | 34 | ||
32 | #endif | 35 | #endif |
diff --git a/kmicromail/libetpan/generic/mailstorage.c b/kmicromail/libetpan/generic/mailstorage.c index 25e561e..dc91744 100644 --- a/kmicromail/libetpan/generic/mailstorage.c +++ b/kmicromail/libetpan/generic/mailstorage.c | |||
@@ -294,41 +294,48 @@ int mailstorage_connect(struct mailstorage * storage) | |||
294 | 294 | ||
295 | if (!clist_isempty(storage->sto_shared_folders)) | 295 | if (!clist_isempty(storage->sto_shared_folders)) |
296 | return MAIL_ERROR_BAD_STATE; | 296 | return MAIL_ERROR_BAD_STATE; |
297 | 297 | ||
298 | if (storage->sto_driver->sto_connect == NULL) | 298 | if (storage->sto_driver->sto_connect == NULL) |
299 | return MAIL_ERROR_NOT_IMPLEMENTED; | 299 | return MAIL_ERROR_NOT_IMPLEMENTED; |
300 | 300 | ||
301 | return storage->sto_driver->sto_connect(storage); | 301 | return storage->sto_driver->sto_connect(storage); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | void mailstorage_disconnect(struct mailstorage * storage) | 305 | void mailstorage_disconnect(struct mailstorage * storage) |
306 | { | 306 | { |
307 | int r; | 307 | int r; |
308 | clistiter * cur; | 308 | clistiter * cur; |
309 | 309 | ||
310 | while ((cur = clist_begin(storage->sto_shared_folders)) != NULL) { | 310 | while ((cur = clist_begin(storage->sto_shared_folders)) != NULL) { |
311 | struct mailfolder * folder; | 311 | struct mailfolder * folder; |
312 | 312 | ||
313 | folder = cur->data; | 313 | folder = cur->data; |
314 | mailfolder_disconnect(folder); | 314 | mailfolder_disconnect(folder); |
315 | } | 315 | } |
316 | 316 | ||
317 | if (storage->sto_session == NULL) | 317 | if (storage->sto_session == NULL) |
318 | return; | 318 | return; |
319 | 319 | ||
320 | r = mailsession_logout(storage->sto_session); | 320 | r = mailsession_logout(storage->sto_session); |
321 | 321 | ||
322 | mailsession_free(storage->sto_session); | 322 | mailsession_free(storage->sto_session); |
323 | storage->sto_session = NULL; | 323 | storage->sto_session = NULL; |
324 | } | 324 | } |
325 | 325 | ||
326 | |||
327 | int mailstorage_noop(struct mailstorage * storage) | ||
328 | { | ||
329 | return mailsession_noop(storage->sto_session); | ||
330 | } | ||
331 | |||
332 | |||
326 | static int mailstorage_get_folder(struct mailstorage * storage, | 333 | static int mailstorage_get_folder(struct mailstorage * storage, |
327 | char * pathname, mailsession ** result) | 334 | char * pathname, mailsession ** result) |
328 | { | 335 | { |
329 | if (storage->sto_driver->sto_get_folder_session == NULL) | 336 | if (storage->sto_driver->sto_get_folder_session == NULL) |
330 | return MAIL_ERROR_NOT_IMPLEMENTED; | 337 | return MAIL_ERROR_NOT_IMPLEMENTED; |
331 | 338 | ||
332 | return storage->sto_driver->sto_get_folder_session(storage, | 339 | return storage->sto_driver->sto_get_folder_session(storage, |
333 | pathname, result); | 340 | pathname, result); |
334 | } | 341 | } |
diff --git a/kmicromail/libetpan/generic/mailstorage.h b/kmicromail/libetpan/generic/mailstorage.h index d56aef1..4c57883 100644 --- a/kmicromail/libetpan/generic/mailstorage.h +++ b/kmicromail/libetpan/generic/mailstorage.h | |||
@@ -42,57 +42,58 @@ | |||
42 | 42 | ||
43 | #ifdef __cplusplus | 43 | #ifdef __cplusplus |
44 | extern "C" { | 44 | extern "C" { |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | /* storage */ | 47 | /* storage */ |
48 | 48 | ||
49 | /* | 49 | /* |
50 | mailstorage_new | 50 | mailstorage_new |
51 | 51 | ||
52 | This function creates an empty storage. This storage have to be initialized. | 52 | This function creates an empty storage. This storage have to be initialized. |
53 | The "driver" and "data" fields should be initialized. | 53 | The "driver" and "data" fields should be initialized. |
54 | 54 | ||
55 | @param id is the name of the storage. It can be NULL. | 55 | @param id is the name of the storage. It can be NULL. |
56 | The given parameter is no more needed when the creation is finished. | 56 | The given parameter is no more needed when the creation is finished. |
57 | The given string is duplicated. | 57 | The given string is duplicated. |
58 | 58 | ||
59 | @return The mail storage is returned. | 59 | @return The mail storage is returned. |
60 | */ | 60 | */ |
61 | 61 | ||
62 | struct mailstorage * mailstorage_new(char * sto_id); | 62 | struct mailstorage * mailstorage_new(char * sto_id); |
63 | 63 | ||
64 | void mailstorage_free(struct mailstorage * storage); | 64 | void mailstorage_free(struct mailstorage * storage); |
65 | 65 | ||
66 | /* | 66 | /* |
67 | session will be initialized on success. | 67 | session will be initialized on success. |
68 | */ | 68 | */ |
69 | 69 | ||
70 | int mailstorage_connect(struct mailstorage * storage); | 70 | int mailstorage_connect(struct mailstorage * storage); |
71 | 71 | ||
72 | void mailstorage_disconnect(struct mailstorage * storage); | 72 | void mailstorage_disconnect(struct mailstorage * storage); |
73 | 73 | ||
74 | int mailstorage_noop(struct mailstorage * storage); | ||
75 | |||
74 | 76 | ||
75 | /* folder */ | 77 | /* folder */ |
76 | 78 | ||
77 | struct mailfolder * mailfolder_new(struct mailstorage * fld_storage, | 79 | struct mailfolder * mailfolder_new(struct mailstorage * fld_storage, |
78 | char * fld_pathname, char * fld_virtual_name); | 80 | char * fld_pathname, char * fld_virtual_name); |
79 | 81 | ||
80 | void mailfolder_free(struct mailfolder * folder); | 82 | void mailfolder_free(struct mailfolder * folder); |
81 | 83 | ||
82 | int mailfolder_add_child(struct mailfolder * parent, | 84 | int mailfolder_add_child(struct mailfolder * parent, |
83 | struct mailfolder * child); | 85 | struct mailfolder * child); |
84 | 86 | ||
85 | int mailfolder_detach_parent(struct mailfolder * folder); | 87 | int mailfolder_detach_parent(struct mailfolder * folder); |
86 | 88 | ||
87 | int mailfolder_connect(struct mailfolder * folder); | 89 | int mailfolder_connect(struct mailfolder * folder); |
88 | 90 | ||
89 | void mailfolder_disconnect(struct mailfolder * folder); | 91 | void mailfolder_disconnect(struct mailfolder * folder); |
90 | 92 | ||
91 | |||
92 | #ifdef __cplusplus | 93 | #ifdef __cplusplus |
93 | } | 94 | } |
94 | #endif | 95 | #endif |
95 | 96 | ||
96 | #endif | 97 | #endif |
97 | 98 | ||
98 | 99 | ||
diff --git a/kmicromail/libetpan/generic/mboxdriver.c b/kmicromail/libetpan/generic/mboxdriver.c index fa3e2ea..c19a668 100644 --- a/kmicromail/libetpan/generic/mboxdriver.c +++ b/kmicromail/libetpan/generic/mboxdriver.c | |||
@@ -48,113 +48,117 @@ | |||
48 | #include "mail.h" | 48 | #include "mail.h" |
49 | #include "maildriver_tools.h" | 49 | #include "maildriver_tools.h" |
50 | #include "mailmbox.h" | 50 | #include "mailmbox.h" |
51 | #include "mboxdriver_tools.h" | 51 | #include "mboxdriver_tools.h" |
52 | #include "maildriver.h" | 52 | #include "maildriver.h" |
53 | #include "carray.h" | 53 | #include "carray.h" |
54 | #include "mboxdriver_message.h" | 54 | #include "mboxdriver_message.h" |
55 | #include "mailmessage.h" | 55 | #include "mailmessage.h" |
56 | 56 | ||
57 | static int mboxdriver_initialize(mailsession * session); | 57 | static int mboxdriver_initialize(mailsession * session); |
58 | 58 | ||
59 | static void mboxdriver_uninitialize(mailsession * session); | 59 | static void mboxdriver_uninitialize(mailsession * session); |
60 | 60 | ||
61 | static int mboxdriver_parameters(mailsession * session, | 61 | static int mboxdriver_parameters(mailsession * session, |
62 | int id, void * value); | 62 | int id, void * value); |
63 | 63 | ||
64 | static int mboxdriver_connect_path(mailsession * session, char * path); | 64 | static int mboxdriver_connect_path(mailsession * session, char * path); |
65 | 65 | ||
66 | static int mboxdriver_logout(mailsession * session); | 66 | static int mboxdriver_logout(mailsession * session); |
67 | 67 | ||
68 | static int mboxdriver_expunge_folder(mailsession * session); | 68 | static int mboxdriver_expunge_folder(mailsession * session); |
69 | 69 | ||
70 | static int mboxdriver_status_folder(mailsession * session, char * mb, | 70 | static int mboxdriver_status_folder(mailsession * session, char * mb, |
71 | uint32_t * result_messages, uint32_t * result_recent, | 71 | uint32_t * result_messages, uint32_t * result_recent, |
72 | uint32_t * result_unseen); | 72 | uint32_t * result_unseen); |
73 | 73 | ||
74 | static int mboxdriver_messages_number(mailsession * session, char * mb, | 74 | static int mboxdriver_messages_number(mailsession * session, char * mb, |
75 | uint32_t * result); | 75 | uint32_t * result); |
76 | 76 | ||
77 | static int mboxdriver_append_message(mailsession * session, | 77 | static int mboxdriver_append_message(mailsession * session, |
78 | char * message, size_t size); | 78 | char * message, size_t size); |
79 | 79 | ||
80 | static int mboxdriver_append_message_flags(mailsession * session, | ||
81 | char * message, size_t size, struct mail_flags * flags); | ||
82 | |||
80 | static int mboxdriver_get_messages_list(mailsession * session, | 83 | static int mboxdriver_get_messages_list(mailsession * session, |
81 | struct mailmessage_list ** result); | 84 | struct mailmessage_list ** result); |
82 | 85 | ||
83 | static int | 86 | static int |
84 | mboxdriver_get_envelopes_list(mailsession * session, | 87 | mboxdriver_get_envelopes_list(mailsession * session, |
85 | struct mailmessage_list * env_list); | 88 | struct mailmessage_list * env_list); |
86 | 89 | ||
87 | static int mboxdriver_remove_message(mailsession * session, uint32_t num); | 90 | static int mboxdriver_remove_message(mailsession * session, uint32_t num); |
88 | 91 | ||
89 | static int mboxdriver_get_message(mailsession * session, | 92 | static int mboxdriver_get_message(mailsession * session, |
90 | uint32_t num, mailmessage ** result); | 93 | uint32_t num, mailmessage ** result); |
91 | 94 | ||
92 | static int mboxdriver_get_message_by_uid(mailsession * session, | 95 | static int mboxdriver_get_message_by_uid(mailsession * session, |
93 | const char * uid, | 96 | const char * uid, |
94 | mailmessage ** result); | 97 | mailmessage ** result); |
95 | 98 | ||
96 | static mailsession_driver local_mbox_session_driver = { | 99 | static mailsession_driver local_mbox_session_driver = { |
97 | .sess_name = "mbox", | 100 | .sess_name = "mbox", |
98 | 101 | ||
99 | .sess_initialize = mboxdriver_initialize, | 102 | .sess_initialize = mboxdriver_initialize, |
100 | .sess_uninitialize = mboxdriver_uninitialize, | 103 | .sess_uninitialize = mboxdriver_uninitialize, |
101 | 104 | ||
102 | .sess_parameters = mboxdriver_parameters, | 105 | .sess_parameters = mboxdriver_parameters, |
103 | 106 | ||
104 | .sess_connect_path = mboxdriver_connect_path, | 107 | .sess_connect_path = mboxdriver_connect_path, |
105 | .sess_connect_stream = NULL, | 108 | .sess_connect_stream = NULL, |
106 | .sess_starttls = NULL, | 109 | .sess_starttls = NULL, |
107 | .sess_login = NULL, | 110 | .sess_login = NULL, |
108 | .sess_logout = mboxdriver_logout, | 111 | .sess_logout = mboxdriver_logout, |
109 | .sess_noop = NULL, | 112 | .sess_noop = NULL, |
110 | 113 | ||
111 | .sess_build_folder_name = NULL, | 114 | .sess_build_folder_name = NULL, |
112 | .sess_create_folder = NULL, | 115 | .sess_create_folder = NULL, |
113 | .sess_delete_folder = NULL, | 116 | .sess_delete_folder = NULL, |
114 | .sess_rename_folder = NULL, | 117 | .sess_rename_folder = NULL, |
115 | .sess_check_folder = NULL, | 118 | .sess_check_folder = NULL, |
116 | .sess_examine_folder = NULL, | 119 | .sess_examine_folder = NULL, |
117 | .sess_select_folder = NULL, | 120 | .sess_select_folder = NULL, |
118 | .sess_expunge_folder = mboxdriver_expunge_folder, | 121 | .sess_expunge_folder = mboxdriver_expunge_folder, |
119 | .sess_status_folder = mboxdriver_status_folder, | 122 | .sess_status_folder = mboxdriver_status_folder, |
120 | .sess_messages_number = mboxdriver_messages_number, | 123 | .sess_messages_number = mboxdriver_messages_number, |
121 | .sess_recent_number = mboxdriver_messages_number, | 124 | .sess_recent_number = mboxdriver_messages_number, |
122 | .sess_unseen_number = mboxdriver_messages_number, | 125 | .sess_unseen_number = mboxdriver_messages_number, |
123 | .sess_list_folders = NULL, | 126 | .sess_list_folders = NULL, |
124 | .sess_lsub_folders = NULL, | 127 | .sess_lsub_folders = NULL, |
125 | .sess_subscribe_folder = NULL, | 128 | .sess_subscribe_folder = NULL, |
126 | .sess_unsubscribe_folder = NULL, | 129 | .sess_unsubscribe_folder = NULL, |
127 | 130 | ||
128 | .sess_append_message = mboxdriver_append_message, | 131 | .sess_append_message = mboxdriver_append_message, |
132 | .sess_append_message_flags = mboxdriver_append_message_flags, | ||
129 | .sess_copy_message = NULL, | 133 | .sess_copy_message = NULL, |
130 | .sess_move_message = NULL, | 134 | .sess_move_message = NULL, |
131 | 135 | ||
132 | .sess_get_messages_list = mboxdriver_get_messages_list, | 136 | .sess_get_messages_list = mboxdriver_get_messages_list, |
133 | .sess_get_envelopes_list = mboxdriver_get_envelopes_list, | 137 | .sess_get_envelopes_list = mboxdriver_get_envelopes_list, |
134 | .sess_remove_message = mboxdriver_remove_message, | 138 | .sess_remove_message = mboxdriver_remove_message, |
135 | #if 0 | 139 | #if 0 |
136 | .sess_search_messages = maildriver_generic_search_messages, | 140 | .sess_search_messages = maildriver_generic_search_messages, |
137 | #endif | 141 | #endif |
138 | 142 | ||
139 | .sess_get_message = mboxdriver_get_message, | 143 | .sess_get_message = mboxdriver_get_message, |
140 | .sess_get_message_by_uid = mboxdriver_get_message_by_uid, | 144 | .sess_get_message_by_uid = mboxdriver_get_message_by_uid, |
141 | }; | 145 | }; |
142 | 146 | ||
143 | mailsession_driver * mbox_session_driver = &local_mbox_session_driver; | 147 | mailsession_driver * mbox_session_driver = &local_mbox_session_driver; |
144 | 148 | ||
145 | static inline struct mbox_session_state_data * get_data(mailsession * session) | 149 | static inline struct mbox_session_state_data * get_data(mailsession * session) |
146 | { | 150 | { |
147 | return session->sess_data; | 151 | return session->sess_data; |
148 | } | 152 | } |
149 | 153 | ||
150 | static inline struct mailmbox_folder * get_mbox_session(mailsession * session) | 154 | static inline struct mailmbox_folder * get_mbox_session(mailsession * session) |
151 | { | 155 | { |
152 | return get_data(session)->mbox_folder; | 156 | return get_data(session)->mbox_folder; |
153 | } | 157 | } |
154 | 158 | ||
155 | static int mboxdriver_initialize(mailsession * session) | 159 | static int mboxdriver_initialize(mailsession * session) |
156 | { | 160 | { |
157 | struct mbox_session_state_data * data; | 161 | struct mbox_session_state_data * data; |
158 | 162 | ||
159 | data = malloc(sizeof(* data)); | 163 | data = malloc(sizeof(* data)); |
160 | if (data == NULL) | 164 | if (data == NULL) |
@@ -315,64 +319,70 @@ static int mboxdriver_messages_number(mailsession * session, char * mb, | |||
315 | if (r != MAIL_NO_ERROR) | 319 | if (r != MAIL_NO_ERROR) |
316 | return r; | 320 | return r; |
317 | 321 | ||
318 | mailmbox_read_unlock(folder); | 322 | mailmbox_read_unlock(folder); |
319 | 323 | ||
320 | * result = carray_count(folder->mb_tab) - folder->mb_deleted_count; | 324 | * result = carray_count(folder->mb_tab) - folder->mb_deleted_count; |
321 | 325 | ||
322 | return MAILMBOX_NO_ERROR; | 326 | return MAILMBOX_NO_ERROR; |
323 | } | 327 | } |
324 | 328 | ||
325 | /* messages operations */ | 329 | /* messages operations */ |
326 | 330 | ||
327 | static int mboxdriver_append_message(mailsession * session, | 331 | static int mboxdriver_append_message(mailsession * session, |
328 | char * message, size_t size) | 332 | char * message, size_t size) |
329 | { | 333 | { |
330 | int r; | 334 | int r; |
331 | struct mailmbox_folder * folder; | 335 | struct mailmbox_folder * folder; |
332 | 336 | ||
333 | folder = get_mbox_session(session); | 337 | folder = get_mbox_session(session); |
334 | if (folder == NULL) | 338 | if (folder == NULL) |
335 | return MAIL_ERROR_APPEND; | 339 | return MAIL_ERROR_APPEND; |
336 | 340 | ||
337 | r = mailmbox_append_message(folder, message, size); | 341 | r = mailmbox_append_message(folder, message, size); |
338 | 342 | ||
339 | switch (r) { | 343 | switch (r) { |
340 | case MAILMBOX_ERROR_FILE: | 344 | case MAILMBOX_ERROR_FILE: |
341 | return MAIL_ERROR_DISKSPACE; | 345 | return MAIL_ERROR_DISKSPACE; |
342 | default: | 346 | default: |
343 | return mboxdriver_mbox_error_to_mail_error(r); | 347 | return mboxdriver_mbox_error_to_mail_error(r); |
344 | } | 348 | } |
345 | } | 349 | } |
346 | 350 | ||
351 | static int mboxdriver_append_message_flags(mailsession * session, | ||
352 | char * message, size_t size, struct mail_flags * flags) | ||
353 | { | ||
354 | return mboxdriver_append_message(session, message, size); | ||
355 | } | ||
356 | |||
347 | static int mboxdriver_get_messages_list(mailsession * session, | 357 | static int mboxdriver_get_messages_list(mailsession * session, |
348 | struct mailmessage_list ** result) | 358 | struct mailmessage_list ** result) |
349 | { | 359 | { |
350 | struct mailmbox_folder * folder; | 360 | struct mailmbox_folder * folder; |
351 | int res; | 361 | int res; |
352 | 362 | ||
353 | folder = get_mbox_session(session); | 363 | folder = get_mbox_session(session); |
354 | if (folder == NULL) { | 364 | if (folder == NULL) { |
355 | res = MAIL_ERROR_BAD_STATE; | 365 | res = MAIL_ERROR_BAD_STATE; |
356 | goto err; | 366 | goto err; |
357 | } | 367 | } |
358 | 368 | ||
359 | return mbox_get_messages_list(folder, session, mbox_message_driver, result); | 369 | return mbox_get_messages_list(folder, session, mbox_message_driver, result); |
360 | 370 | ||
361 | err: | 371 | err: |
362 | return res; | 372 | return res; |
363 | } | 373 | } |
364 | 374 | ||
365 | static int | 375 | static int |
366 | mboxdriver_get_envelopes_list(mailsession * session, | 376 | mboxdriver_get_envelopes_list(mailsession * session, |
367 | struct mailmessage_list * env_list) | 377 | struct mailmessage_list * env_list) |
368 | { | 378 | { |
369 | struct mailmbox_folder * folder; | 379 | struct mailmbox_folder * folder; |
370 | unsigned int i; | 380 | unsigned int i; |
371 | int r; | 381 | int r; |
372 | int res; | 382 | int res; |
373 | 383 | ||
374 | folder = get_mbox_session(session); | 384 | folder = get_mbox_session(session); |
375 | if (folder == NULL) { | 385 | if (folder == NULL) { |
376 | res = MAIL_ERROR_BAD_STATE; | 386 | res = MAIL_ERROR_BAD_STATE; |
377 | goto err; | 387 | goto err; |
378 | } | 388 | } |
diff --git a/kmicromail/libetpan/generic/mboxdriver_cached.c b/kmicromail/libetpan/generic/mboxdriver_cached.c index 07871fa..3af7fb9 100644 --- a/kmicromail/libetpan/generic/mboxdriver_cached.c +++ b/kmicromail/libetpan/generic/mboxdriver_cached.c | |||
@@ -57,115 +57,120 @@ | |||
57 | #include "imfcache.h" | 57 | #include "imfcache.h" |
58 | #include "mboxdriver_cached_message.h" | 58 | #include "mboxdriver_cached_message.h" |
59 | #include "libetpan-config.h" | 59 | #include "libetpan-config.h" |
60 | 60 | ||
61 | static int mboxdriver_cached_initialize(mailsession * session); | 61 | static int mboxdriver_cached_initialize(mailsession * session); |
62 | 62 | ||
63 | static void mboxdriver_cached_uninitialize(mailsession * session); | 63 | static void mboxdriver_cached_uninitialize(mailsession * session); |
64 | 64 | ||
65 | static int mboxdriver_cached_parameters(mailsession * session, | 65 | static int mboxdriver_cached_parameters(mailsession * session, |
66 | int id, void * value); | 66 | int id, void * value); |
67 | 67 | ||
68 | static int mboxdriver_cached_connect_path(mailsession * session, char * path); | 68 | static int mboxdriver_cached_connect_path(mailsession * session, char * path); |
69 | 69 | ||
70 | static int mboxdriver_cached_logout(mailsession * session); | 70 | static int mboxdriver_cached_logout(mailsession * session); |
71 | 71 | ||
72 | static int mboxdriver_cached_check_folder(mailsession * session); | 72 | static int mboxdriver_cached_check_folder(mailsession * session); |
73 | 73 | ||
74 | static int mboxdriver_cached_expunge_folder(mailsession * session); | 74 | static int mboxdriver_cached_expunge_folder(mailsession * session); |
75 | 75 | ||
76 | static int mboxdriver_cached_status_folder(mailsession * session, char * mb, | 76 | static int mboxdriver_cached_status_folder(mailsession * session, char * mb, |
77 | uint32_t * result_messages, uint32_t * result_recent, | 77 | uint32_t * result_messages, uint32_t * result_recent, |
78 | uint32_t * result_unseen); | 78 | uint32_t * result_unseen); |
79 | static int mboxdriver_cached_messages_number(mailsession * session, char * mb, | 79 | static int mboxdriver_cached_messages_number(mailsession * session, char * mb, |
80 | uint32_t * result); | 80 | uint32_t * result); |
81 | static int mboxdriver_cached_recent_number(mailsession * session, char * mb, | 81 | static int mboxdriver_cached_recent_number(mailsession * session, char * mb, |
82 | uint32_t * result); | 82 | uint32_t * result); |
83 | static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, | 83 | static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, |
84 | uint32_t * result); | 84 | uint32_t * result); |
85 | 85 | ||
86 | static int mboxdriver_cached_append_message(mailsession * session, | 86 | static int mboxdriver_cached_append_message(mailsession * session, |
87 | char * message, size_t size); | 87 | char * message, size_t size); |
88 | 88 | ||
89 | static int mboxdriver_cached_append_message_flags(mailsession * session, | ||
90 | char * message, size_t size, struct mail_flags * flags); | ||
91 | |||
89 | static int | 92 | static int |
90 | mboxdriver_cached_get_messages_list(mailsession * session, | 93 | mboxdriver_cached_get_messages_list(mailsession * session, |
91 | struct mailmessage_list ** result); | 94 | struct mailmessage_list ** result); |
92 | 95 | ||
93 | static int | 96 | static int |
94 | mboxdriver_cached_get_envelopes_list(mailsession * session, | 97 | mboxdriver_cached_get_envelopes_list(mailsession * session, |
95 | struct mailmessage_list * env_list); | 98 | struct mailmessage_list * env_list); |
96 | 99 | ||
97 | static int mboxdriver_cached_remove_message(mailsession * session, | 100 | static int mboxdriver_cached_remove_message(mailsession * session, |
98 | uint32_t num); | 101 | uint32_t num); |
99 | 102 | ||
100 | static int mboxdriver_cached_get_message(mailsession * session, | 103 | static int mboxdriver_cached_get_message(mailsession * session, |
101 | uint32_t num, mailmessage ** result); | 104 | uint32_t num, mailmessage ** result); |
102 | 105 | ||
103 | static int mboxdriver_cached_get_message_by_uid(mailsession * session, | 106 | static int mboxdriver_cached_get_message_by_uid(mailsession * session, |
104 | const char * uid, | 107 | const char * uid, |
105 | mailmessage ** result); | 108 | mailmessage ** result); |
106 | 109 | ||
107 | static mailsession_driver local_mbox_cached_session_driver = { | 110 | static mailsession_driver local_mbox_cached_session_driver = { |
108 | .sess_name = "mbox-cached", | 111 | .sess_name = "mbox-cached", |
109 | 112 | ||
110 | .sess_initialize = mboxdriver_cached_initialize, | 113 | .sess_initialize = mboxdriver_cached_initialize, |
111 | .sess_uninitialize = mboxdriver_cached_uninitialize, | 114 | .sess_uninitialize = mboxdriver_cached_uninitialize, |
112 | 115 | ||
113 | .sess_parameters = mboxdriver_cached_parameters, | 116 | .sess_parameters = mboxdriver_cached_parameters, |
114 | 117 | ||
115 | .sess_connect_path = mboxdriver_cached_connect_path, | 118 | .sess_connect_path = mboxdriver_cached_connect_path, |
116 | .sess_connect_stream = NULL, | 119 | .sess_connect_stream = NULL, |
117 | .sess_starttls = NULL, | 120 | .sess_starttls = NULL, |
118 | .sess_login = NULL, | 121 | .sess_login = NULL, |
119 | .sess_logout = mboxdriver_cached_logout, | 122 | .sess_logout = mboxdriver_cached_logout, |
120 | .sess_noop = NULL, | 123 | .sess_noop = NULL, |
121 | 124 | ||
122 | .sess_build_folder_name = NULL, | 125 | .sess_build_folder_name = NULL, |
123 | .sess_create_folder = NULL, | 126 | .sess_create_folder = NULL, |
124 | .sess_delete_folder = NULL, | 127 | .sess_delete_folder = NULL, |
125 | .sess_rename_folder = NULL, | 128 | .sess_rename_folder = NULL, |
126 | .sess_check_folder = mboxdriver_cached_check_folder, | 129 | .sess_check_folder = mboxdriver_cached_check_folder, |
127 | .sess_examine_folder = NULL, | 130 | .sess_examine_folder = NULL, |
128 | .sess_select_folder = NULL, | 131 | .sess_select_folder = NULL, |
129 | .sess_expunge_folder = mboxdriver_cached_expunge_folder, | 132 | .sess_expunge_folder = mboxdriver_cached_expunge_folder, |
130 | .sess_status_folder = mboxdriver_cached_status_folder, | 133 | .sess_status_folder = mboxdriver_cached_status_folder, |
131 | .sess_messages_number = mboxdriver_cached_messages_number, | 134 | .sess_messages_number = mboxdriver_cached_messages_number, |
132 | .sess_recent_number = mboxdriver_cached_recent_number, | 135 | .sess_recent_number = mboxdriver_cached_recent_number, |
133 | .sess_unseen_number = mboxdriver_cached_unseen_number, | 136 | .sess_unseen_number = mboxdriver_cached_unseen_number, |
134 | .sess_list_folders = NULL, | 137 | .sess_list_folders = NULL, |
135 | .sess_lsub_folders = NULL, | 138 | .sess_lsub_folders = NULL, |
136 | .sess_subscribe_folder = NULL, | 139 | .sess_subscribe_folder = NULL, |
137 | .sess_unsubscribe_folder = NULL, | 140 | .sess_unsubscribe_folder = NULL, |
138 | 141 | ||
139 | .sess_append_message = mboxdriver_cached_append_message, | 142 | .sess_append_message = mboxdriver_cached_append_message, |
143 | .sess_append_message_flags = mboxdriver_cached_append_message_flags, | ||
144 | |||
140 | .sess_copy_message = NULL, | 145 | .sess_copy_message = NULL, |
141 | .sess_move_message = NULL, | 146 | .sess_move_message = NULL, |
142 | 147 | ||
143 | .sess_get_messages_list = mboxdriver_cached_get_messages_list, | 148 | .sess_get_messages_list = mboxdriver_cached_get_messages_list, |
144 | .sess_get_envelopes_list = mboxdriver_cached_get_envelopes_list, | 149 | .sess_get_envelopes_list = mboxdriver_cached_get_envelopes_list, |
145 | .sess_remove_message = mboxdriver_cached_remove_message, | 150 | .sess_remove_message = mboxdriver_cached_remove_message, |
146 | #if 0 | 151 | #if 0 |
147 | .sess_search_messages = maildriver_generic_search_messages, | 152 | .sess_search_messages = maildriver_generic_search_messages, |
148 | #endif | 153 | #endif |
149 | 154 | ||
150 | .sess_get_message = mboxdriver_cached_get_message, | 155 | .sess_get_message = mboxdriver_cached_get_message, |
151 | .sess_get_message_by_uid = mboxdriver_cached_get_message_by_uid, | 156 | .sess_get_message_by_uid = mboxdriver_cached_get_message_by_uid, |
152 | }; | 157 | }; |
153 | 158 | ||
154 | mailsession_driver * mbox_cached_session_driver = | 159 | mailsession_driver * mbox_cached_session_driver = |
155 | &local_mbox_cached_session_driver; | 160 | &local_mbox_cached_session_driver; |
156 | 161 | ||
157 | 162 | ||
158 | #define ENV_NAME "env.db" | 163 | #define ENV_NAME "env.db" |
159 | #define FLAGS_NAME "flags.db" | 164 | #define FLAGS_NAME "flags.db" |
160 | 165 | ||
161 | 166 | ||
162 | 167 | ||
163 | static int mbox_error_to_mail_error(int error) | 168 | static int mbox_error_to_mail_error(int error) |
164 | { | 169 | { |
165 | switch (error) { | 170 | switch (error) { |
166 | case MAILMBOX_NO_ERROR: | 171 | case MAILMBOX_NO_ERROR: |
167 | return MAIL_NO_ERROR; | 172 | return MAIL_NO_ERROR; |
168 | 173 | ||
169 | case MAILMBOX_ERROR_PARSE: | 174 | case MAILMBOX_ERROR_PARSE: |
170 | return MAIL_ERROR_PARSE; | 175 | return MAIL_ERROR_PARSE; |
171 | 176 | ||
@@ -877,165 +882,244 @@ static int mboxdriver_cached_recent_number(mailsession * session, char * mb, | |||
877 | r = mboxdriver_cached_status_folder(session, mb, &messages, &recent, &unseen); | 882 | r = mboxdriver_cached_status_folder(session, mb, &messages, &recent, &unseen); |
878 | if (r != MAIL_NO_ERROR) | 883 | if (r != MAIL_NO_ERROR) |
879 | return r; | 884 | return r; |
880 | 885 | ||
881 | * result = recent; | 886 | * result = recent; |
882 | 887 | ||
883 | return MAIL_NO_ERROR; | 888 | return MAIL_NO_ERROR; |
884 | } | 889 | } |
885 | 890 | ||
886 | static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, | 891 | static int mboxdriver_cached_unseen_number(mailsession * session, char * mb, |
887 | uint32_t * result) | 892 | uint32_t * result) |
888 | { | 893 | { |
889 | uint32_t messages; | 894 | uint32_t messages; |
890 | uint32_t recent; | 895 | uint32_t recent; |
891 | uint32_t unseen; | 896 | uint32_t unseen; |
892 | int r; | 897 | int r; |
893 | 898 | ||
894 | r = mboxdriver_cached_status_folder(session, mb, | 899 | r = mboxdriver_cached_status_folder(session, mb, |
895 | &messages, &recent, &unseen); | 900 | &messages, &recent, &unseen); |
896 | if (r != MAIL_NO_ERROR) | 901 | if (r != MAIL_NO_ERROR) |
897 | return r; | 902 | return r; |
898 | 903 | ||
899 | * result = unseen; | 904 | * result = unseen; |
900 | 905 | ||
901 | return MAIL_NO_ERROR; | 906 | return MAIL_NO_ERROR; |
902 | } | 907 | } |
903 | 908 | ||
904 | /* messages operations */ | 909 | /* messages operations */ |
905 | 910 | ||
906 | static int mboxdriver_cached_append_message(mailsession * session, | 911 | static int mboxdriver_cached_append_message(mailsession * session, |
907 | char * message, size_t size) | 912 | char * message, size_t size) |
908 | { | 913 | { |
909 | return mailsession_append_message(get_ancestor(session), message, size); | 914 | return mboxdriver_cached_append_message_flags(session, |
915 | message, size, NULL); | ||
916 | } | ||
917 | |||
918 | static int mboxdriver_cached_append_message_flags(mailsession * session, | ||
919 | char * message, size_t size, struct mail_flags * flags) | ||
920 | { | ||
921 | int r; | ||
922 | struct mailmbox_folder * folder; | ||
923 | struct mbox_cached_session_state_data * data; | ||
924 | unsigned int uid; | ||
925 | struct mailmbox_msg_info * msg_info; | ||
926 | chashdatum key; | ||
927 | chashdatum value; | ||
928 | struct mail_cache_db * cache_db_flags; | ||
929 | char filename_flags[PATH_MAX]; | ||
930 | MMAPString * mmapstr; | ||
931 | char keyname[PATH_MAX]; | ||
932 | |||
933 | folder = get_mbox_session(session); | ||
934 | if (folder == NULL) | ||
935 | return MAIL_ERROR_APPEND; | ||
936 | |||
937 | r = mailmbox_append_message_uid(folder, message, size, &uid); | ||
938 | |||
939 | switch (r) { | ||
940 | case MAILMBOX_ERROR_FILE: | ||
941 | return MAIL_ERROR_DISKSPACE; | ||
942 | case MAILMBOX_NO_ERROR: | ||
943 | break; | ||
944 | default: | ||
945 | return mboxdriver_mbox_error_to_mail_error(r); | ||
946 | } | ||
947 | |||
948 | /* could store in flags store instead */ | ||
949 | |||
950 | if (flags == NULL) | ||
951 | goto exit; | ||
952 | |||
953 | key.data = &uid; | ||
954 | key.len = sizeof(uid); | ||
955 | r = chash_get(folder->mb_hash, &key, &value); | ||
956 | if (r < 0) | ||
957 | goto exit; | ||
958 | |||
959 | msg_info = value.data; | ||
960 | |||
961 | data = get_cached_data(session); | ||
962 | |||
963 | snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", | ||
964 | data->mbox_flags_directory, MAIL_DIR_SEPARATOR, data->mbox_quoted_mb, | ||
965 | MAIL_DIR_SEPARATOR, FLAGS_NAME); | ||
966 | |||
967 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
968 | if (r < 0) | ||
969 | goto exit; | ||
970 | |||
971 | mmapstr = mmap_string_new(""); | ||
972 | if (mmapstr == NULL) | ||
973 | goto close_db_flags; | ||
974 | |||
975 | snprintf(keyname, PATH_MAX, "%u-%lu", uid, | ||
976 | (unsigned long) msg_info->msg_body_len); | ||
977 | |||
978 | r = mboxdriver_write_cached_flags(cache_db_flags, mmapstr, keyname, flags); | ||
979 | |||
980 | mmap_string_free(mmapstr); | ||
981 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
982 | |||
983 | if (r != MAIL_NO_ERROR) | ||
984 | goto exit; | ||
985 | |||
986 | return MAIL_NO_ERROR; | ||
987 | |||
988 | close_db_flags: | ||
989 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
990 | exit: | ||
991 | return MAIL_NO_ERROR; | ||
910 | } | 992 | } |
911 | 993 | ||
912 | static int | 994 | static int |
913 | mboxdriver_cached_get_messages_list(mailsession * session, | 995 | mboxdriver_cached_get_messages_list(mailsession * session, |
914 | struct mailmessage_list ** result) | 996 | struct mailmessage_list ** result) |
915 | { | 997 | { |
916 | struct mailmbox_folder * folder; | 998 | struct mailmbox_folder * folder; |
917 | int res; | 999 | int res; |
918 | 1000 | ||
919 | folder = get_mbox_session(session); | 1001 | folder = get_mbox_session(session); |
920 | if (folder == NULL) { | 1002 | if (folder == NULL) { |
921 | res = MAIL_ERROR_BAD_STATE; | 1003 | res = MAIL_ERROR_BAD_STATE; |
922 | goto err; | 1004 | goto err; |
923 | } | 1005 | } |
924 | 1006 | ||
925 | return mbox_get_uid_messages_list(folder, | 1007 | return mbox_get_uid_messages_list(folder, |
926 | session, mbox_cached_message_driver, result); | 1008 | session, mbox_cached_message_driver, result); |
927 | 1009 | ||
928 | err: | 1010 | err: |
929 | return res; | 1011 | return res; |
930 | } | 1012 | } |
931 | 1013 | ||
932 | static int | 1014 | static int |
933 | get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | 1015 | get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, |
934 | mailsession * session, uint32_t num, | 1016 | mailsession * session, uint32_t num, |
935 | struct mailimf_fields ** result) | 1017 | struct mailimf_fields ** result) |
936 | { | 1018 | { |
937 | int r; | 1019 | int r; |
938 | char keyname[PATH_MAX]; | 1020 | char keyname[PATH_MAX]; |
939 | struct mailimf_fields * fields; | 1021 | struct mailimf_fields * fields; |
940 | int res; | 1022 | int res; |
941 | struct mailmbox_msg_info * info; | 1023 | struct mailmbox_msg_info * info; |
942 | struct mailmbox_folder * folder; | 1024 | struct mailmbox_folder * folder; |
943 | chashdatum key; | 1025 | chashdatum key; |
944 | chashdatum data; | 1026 | chashdatum data; |
945 | 1027 | ||
946 | folder = get_mbox_session(session); | 1028 | folder = get_mbox_session(session); |
947 | if (folder == NULL) { | 1029 | if (folder == NULL) { |
948 | res = MAIL_ERROR_BAD_STATE; | 1030 | res = MAIL_ERROR_BAD_STATE; |
949 | goto err; | 1031 | goto err; |
950 | } | 1032 | } |
951 | 1033 | ||
952 | key.data = # | 1034 | key.data = # |
953 | key.len = sizeof(num); | 1035 | key.len = sizeof(num); |
954 | 1036 | ||
955 | r = chash_get(folder->mb_hash, &key, &data); | 1037 | r = chash_get(folder->mb_hash, &key, &data); |
956 | if (r < 0) { | 1038 | if (r < 0) { |
957 | res = MAIL_ERROR_MSG_NOT_FOUND; | 1039 | res = MAIL_ERROR_MSG_NOT_FOUND; |
958 | goto err; | 1040 | goto err; |
959 | } | 1041 | } |
960 | 1042 | ||
961 | info = data.data; | 1043 | info = data.data; |
962 | 1044 | ||
963 | snprintf(keyname, PATH_MAX, "%u-%u-envelope", num, info->msg_body_len); | 1045 | snprintf(keyname, PATH_MAX, "%u-%lu-envelope", num, |
1046 | (unsigned long) info->msg_body_len); | ||
964 | 1047 | ||
965 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); | 1048 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); |
966 | if (r != MAIL_NO_ERROR) { | 1049 | if (r != MAIL_NO_ERROR) { |
967 | res = r; | 1050 | res = r; |
968 | goto err; | 1051 | goto err; |
969 | } | 1052 | } |
970 | 1053 | ||
971 | * result = fields; | 1054 | * result = fields; |
972 | 1055 | ||
973 | return MAIL_NO_ERROR; | 1056 | return MAIL_NO_ERROR; |
974 | 1057 | ||
975 | err: | 1058 | err: |
976 | return res; | 1059 | return res; |
977 | } | 1060 | } |
978 | 1061 | ||
979 | static int | 1062 | static int |
980 | write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | 1063 | write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, |
981 | mailsession * session, uint32_t num, | 1064 | mailsession * session, uint32_t num, |
982 | struct mailimf_fields * fields) | 1065 | struct mailimf_fields * fields) |
983 | { | 1066 | { |
984 | int r; | 1067 | int r; |
985 | char keyname[PATH_MAX]; | 1068 | char keyname[PATH_MAX]; |
986 | int res; | 1069 | int res; |
987 | struct mailmbox_msg_info * info; | 1070 | struct mailmbox_msg_info * info; |
988 | struct mailmbox_folder * folder; | 1071 | struct mailmbox_folder * folder; |
989 | chashdatum key; | 1072 | chashdatum key; |
990 | chashdatum data; | 1073 | chashdatum data; |
991 | 1074 | ||
992 | folder = get_mbox_session(session); | 1075 | folder = get_mbox_session(session); |
993 | if (folder == NULL) { | 1076 | if (folder == NULL) { |
994 | res = MAIL_ERROR_BAD_STATE; | 1077 | res = MAIL_ERROR_BAD_STATE; |
995 | goto err; | 1078 | goto err; |
996 | } | 1079 | } |
997 | 1080 | ||
998 | key.data = # | 1081 | key.data = # |
999 | key.len = sizeof(num); | 1082 | key.len = sizeof(num); |
1000 | 1083 | ||
1001 | r = chash_get(folder->mb_hash, &key, &data); | 1084 | r = chash_get(folder->mb_hash, &key, &data); |
1002 | if (r < 0) { | 1085 | if (r < 0) { |
1003 | res = MAIL_ERROR_MSG_NOT_FOUND; | 1086 | res = MAIL_ERROR_MSG_NOT_FOUND; |
1004 | goto err; | 1087 | goto err; |
1005 | } | 1088 | } |
1006 | 1089 | ||
1007 | info = data.data; | 1090 | info = data.data; |
1008 | 1091 | ||
1009 | snprintf(keyname, PATH_MAX, "%u-%u-envelope", num, info->msg_body_len); | 1092 | snprintf(keyname, PATH_MAX, "%u-%lu-envelope", num, |
1093 | (unsigned long) info->msg_body_len); | ||
1010 | 1094 | ||
1011 | r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); | 1095 | r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); |
1012 | if (r != MAIL_NO_ERROR) { | 1096 | if (r != MAIL_NO_ERROR) { |
1013 | res = r; | 1097 | res = r; |
1014 | goto err; | 1098 | goto err; |
1015 | } | 1099 | } |
1016 | 1100 | ||
1017 | return MAIL_NO_ERROR; | 1101 | return MAIL_NO_ERROR; |
1018 | 1102 | ||
1019 | err: | 1103 | err: |
1020 | return res; | 1104 | return res; |
1021 | } | 1105 | } |
1022 | 1106 | ||
1023 | static int | 1107 | static int |
1024 | mboxdriver_cached_get_envelopes_list(mailsession * session, | 1108 | mboxdriver_cached_get_envelopes_list(mailsession * session, |
1025 | struct mailmessage_list * env_list) | 1109 | struct mailmessage_list * env_list) |
1026 | { | 1110 | { |
1027 | int r; | 1111 | int r; |
1028 | unsigned int i; | 1112 | unsigned int i; |
1029 | struct mbox_cached_session_state_data * cached_data; | 1113 | struct mbox_cached_session_state_data * cached_data; |
1030 | char filename_env[PATH_MAX]; | 1114 | char filename_env[PATH_MAX]; |
1031 | char filename_flags[PATH_MAX]; | 1115 | char filename_flags[PATH_MAX]; |
1032 | struct mail_cache_db * cache_db_env; | 1116 | struct mail_cache_db * cache_db_env; |
1033 | struct mail_cache_db * cache_db_flags; | 1117 | struct mail_cache_db * cache_db_flags; |
1034 | MMAPString * mmapstr; | 1118 | MMAPString * mmapstr; |
1035 | int res; | 1119 | int res; |
1036 | struct mailmbox_folder * folder; | 1120 | struct mailmbox_folder * folder; |
1037 | 1121 | ||
1038 | folder = get_mbox_session(session); | 1122 | folder = get_mbox_session(session); |
1039 | if (folder == NULL) { | 1123 | if (folder == NULL) { |
1040 | res = MAIL_ERROR_BAD_STATE; | 1124 | res = MAIL_ERROR_BAD_STATE; |
1041 | goto err; | 1125 | goto err; |
diff --git a/kmicromail/libetpan/generic/mboxdriver_cached_message.c b/kmicromail/libetpan/generic/mboxdriver_cached_message.c index 6d92b22..828396b 100644 --- a/kmicromail/libetpan/generic/mboxdriver_cached_message.c +++ b/kmicromail/libetpan/generic/mboxdriver_cached_message.c | |||
@@ -153,65 +153,66 @@ static void mbox_prefetch_free(struct generic_message_t * msg) | |||
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | static int mbox_initialize(mailmessage * msg_info) | 156 | static int mbox_initialize(mailmessage * msg_info) |
157 | { | 157 | { |
158 | struct generic_message_t * msg; | 158 | struct generic_message_t * msg; |
159 | int r; | 159 | int r; |
160 | char * uid; | 160 | char * uid; |
161 | char static_uid[PATH_MAX]; | 161 | char static_uid[PATH_MAX]; |
162 | struct mailmbox_msg_info * info; | 162 | struct mailmbox_msg_info * info; |
163 | struct mailmbox_folder * folder; | 163 | struct mailmbox_folder * folder; |
164 | int res; | 164 | int res; |
165 | chashdatum key; | 165 | chashdatum key; |
166 | chashdatum data; | 166 | chashdatum data; |
167 | 167 | ||
168 | folder = get_mbox_session(msg_info); | 168 | folder = get_mbox_session(msg_info); |
169 | if (folder == NULL) { | 169 | if (folder == NULL) { |
170 | res = MAIL_ERROR_BAD_STATE; | 170 | res = MAIL_ERROR_BAD_STATE; |
171 | goto err; | 171 | goto err; |
172 | } | 172 | } |
173 | 173 | ||
174 | key.data = (char *) &msg_info->msg_index; | 174 | key.data = (char *) &msg_info->msg_index; |
175 | key.len = sizeof(msg_info->msg_index); | 175 | key.len = sizeof(msg_info->msg_index); |
176 | 176 | ||
177 | r = chash_get(folder->mb_hash, &key, &data); | 177 | r = chash_get(folder->mb_hash, &key, &data); |
178 | if (r < 0) { | 178 | if (r < 0) { |
179 | res = MAIL_ERROR_MSG_NOT_FOUND; | 179 | res = MAIL_ERROR_MSG_NOT_FOUND; |
180 | goto err; | 180 | goto err; |
181 | } | 181 | } |
182 | 182 | ||
183 | info = (struct mailmbox_msg_info *) data.data; | 183 | info = (struct mailmbox_msg_info *) data.data; |
184 | 184 | ||
185 | snprintf(static_uid, PATH_MAX, "%u-%u", msg_info->msg_index, info->msg_body_len); | 185 | snprintf(static_uid, PATH_MAX, "%u-%lu", |
186 | msg_info->msg_index, (unsigned long) info->msg_body_len); | ||
186 | uid = strdup(static_uid); | 187 | uid = strdup(static_uid); |
187 | if (uid == NULL) { | 188 | if (uid == NULL) { |
188 | res = MAIL_ERROR_MEMORY; | 189 | res = MAIL_ERROR_MEMORY; |
189 | goto err; | 190 | goto err; |
190 | } | 191 | } |
191 | 192 | ||
192 | r = mailmessage_generic_initialize(msg_info); | 193 | r = mailmessage_generic_initialize(msg_info); |
193 | if (r != MAIL_NO_ERROR) { | 194 | if (r != MAIL_NO_ERROR) { |
194 | free(uid); | 195 | free(uid); |
195 | res = r; | 196 | res = r; |
196 | goto err; | 197 | goto err; |
197 | } | 198 | } |
198 | 199 | ||
199 | msg = msg_info->msg_data; | 200 | msg = msg_info->msg_data; |
200 | 201 | ||
201 | msg->msg_prefetch = mbox_prefetch; | 202 | msg->msg_prefetch = mbox_prefetch; |
202 | msg->msg_prefetch_free = mbox_prefetch_free; | 203 | msg->msg_prefetch_free = mbox_prefetch_free; |
203 | msg_info->msg_uid = uid; | 204 | msg_info->msg_uid = uid; |
204 | 205 | ||
205 | return MAIL_NO_ERROR; | 206 | return MAIL_NO_ERROR; |
206 | 207 | ||
207 | err: | 208 | err: |
208 | return res; | 209 | return res; |
209 | } | 210 | } |
210 | 211 | ||
211 | static void mbox_uninitialize(mailmessage * msg_info) | 212 | static void mbox_uninitialize(mailmessage * msg_info) |
212 | { | 213 | { |
213 | mailmessage_generic_uninitialize(msg_info); | 214 | mailmessage_generic_uninitialize(msg_info); |
214 | } | 215 | } |
215 | 216 | ||
216 | #define FLAGS_NAME "flags.db" | 217 | #define FLAGS_NAME "flags.db" |
217 | 218 | ||
diff --git a/kmicromail/libetpan/generic/mboxdriver_message.c b/kmicromail/libetpan/generic/mboxdriver_message.c index da9a65d..6922625 100644 --- a/kmicromail/libetpan/generic/mboxdriver_message.c +++ b/kmicromail/libetpan/generic/mboxdriver_message.c | |||
@@ -4,65 +4,65 @@ | |||
4 | * Copyright (C) 2001, 2002 - DINH Viet Hoa | 4 | * Copyright (C) 2001, 2002 - DINH Viet Hoa |
5 | * All rights reserved. | 5 | * All rights reserved. |
6 | * | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "mhdriver_message.h" | 36 | #include "mboxdriver_message.h" |
37 | 37 | ||
38 | #include "mailmessage_tools.h" | 38 | #include "mailmessage_tools.h" |
39 | #include "mboxdriver_tools.h" | 39 | #include "mboxdriver_tools.h" |
40 | #include "mboxdriver.h" | 40 | #include "mboxdriver.h" |
41 | #include "mailmbox.h" | 41 | #include "mailmbox.h" |
42 | 42 | ||
43 | #include <unistd.h> | 43 | #include <unistd.h> |
44 | #include <sys/mman.h> | 44 | #include <sys/mman.h> |
45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | #include <sys/stat.h> | 46 | #include <sys/stat.h> |
47 | #include <fcntl.h> | 47 | #include <fcntl.h> |
48 | #include <string.h> | 48 | #include <string.h> |
49 | #include <stdlib.h> | 49 | #include <stdlib.h> |
50 | 50 | ||
51 | static int mbox_prefetch(mailmessage * msg_info); | 51 | static int mbox_prefetch(mailmessage * msg_info); |
52 | 52 | ||
53 | static void mbox_prefetch_free(struct generic_message_t * msg); | 53 | static void mbox_prefetch_free(struct generic_message_t * msg); |
54 | 54 | ||
55 | static int mbox_initialize(mailmessage * msg_info); | 55 | static int mbox_initialize(mailmessage * msg_info); |
56 | 56 | ||
57 | static int mbox_fetch_size(mailmessage * msg_info, | 57 | static int mbox_fetch_size(mailmessage * msg_info, |
58 | size_t * result); | 58 | size_t * result); |
59 | 59 | ||
60 | static int mbox_fetch_header(mailmessage * msg_info, | 60 | static int mbox_fetch_header(mailmessage * msg_info, |
61 | char ** result, | 61 | char ** result, |
62 | size_t * result_len); | 62 | size_t * result_len); |
63 | 63 | ||
64 | static mailmessage_driver local_mbox_message_driver = { | 64 | static mailmessage_driver local_mbox_message_driver = { |
65 | .msg_name = "mbox", | 65 | .msg_name = "mbox", |
66 | 66 | ||
67 | .msg_initialize = mbox_initialize, | 67 | .msg_initialize = mbox_initialize, |
68 | .msg_uninitialize = mailmessage_generic_uninitialize, | 68 | .msg_uninitialize = mailmessage_generic_uninitialize, |
@@ -127,66 +127,66 @@ static void mbox_prefetch_free(struct generic_message_t * msg) | |||
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
130 | static int mbox_initialize(mailmessage * msg_info) | 130 | static int mbox_initialize(mailmessage * msg_info) |
131 | { | 131 | { |
132 | struct generic_message_t * msg; | 132 | struct generic_message_t * msg; |
133 | int r; | 133 | int r; |
134 | char * uid; | 134 | char * uid; |
135 | char static_uid[PATH_MAX]; | 135 | char static_uid[PATH_MAX]; |
136 | struct mailmbox_msg_info * info; | 136 | struct mailmbox_msg_info * info; |
137 | struct mailmbox_folder * folder; | 137 | struct mailmbox_folder * folder; |
138 | int res; | 138 | int res; |
139 | chashdatum key; | 139 | chashdatum key; |
140 | chashdatum data; | 140 | chashdatum data; |
141 | 141 | ||
142 | folder = get_mbox_session(msg_info); | 142 | folder = get_mbox_session(msg_info); |
143 | if (folder == NULL) { | 143 | if (folder == NULL) { |
144 | res = MAIL_ERROR_BAD_STATE; | 144 | res = MAIL_ERROR_BAD_STATE; |
145 | goto err; | 145 | goto err; |
146 | } | 146 | } |
147 | 147 | ||
148 | key.data = &msg_info->msg_index; | 148 | key.data = &msg_info->msg_index; |
149 | key.len = sizeof(msg_info->msg_index); | 149 | key.len = sizeof(msg_info->msg_index); |
150 | 150 | ||
151 | r = chash_get(folder->mb_hash, &key, &data); | 151 | r = chash_get(folder->mb_hash, &key, &data); |
152 | if (r < 0) { | 152 | if (r < 0) { |
153 | res = MAIL_ERROR_MSG_NOT_FOUND; | 153 | res = MAIL_ERROR_MSG_NOT_FOUND; |
154 | goto err; | 154 | goto err; |
155 | } | 155 | } |
156 | 156 | ||
157 | info = data.data; | 157 | info = data.data; |
158 | 158 | ||
159 | snprintf(static_uid, PATH_MAX, "%u-%u", | 159 | snprintf(static_uid, PATH_MAX, "%u-%lu", |
160 | msg_info->msg_index, info->msg_body_len); | 160 | msg_info->msg_index, (unsigned long) info->msg_body_len); |
161 | uid = strdup(static_uid); | 161 | uid = strdup(static_uid); |
162 | if (uid == NULL) { | 162 | if (uid == NULL) { |
163 | res = MAIL_ERROR_MEMORY; | 163 | res = MAIL_ERROR_MEMORY; |
164 | goto err; | 164 | goto err; |
165 | } | 165 | } |
166 | 166 | ||
167 | r = mailmessage_generic_initialize(msg_info); | 167 | r = mailmessage_generic_initialize(msg_info); |
168 | if (r != MAIL_NO_ERROR) { | 168 | if (r != MAIL_NO_ERROR) { |
169 | free(uid); | 169 | free(uid); |
170 | res = r; | 170 | res = r; |
171 | goto err; | 171 | goto err; |
172 | } | 172 | } |
173 | 173 | ||
174 | msg = msg_info->msg_data; | 174 | msg = msg_info->msg_data; |
175 | msg->msg_prefetch = mbox_prefetch; | 175 | msg->msg_prefetch = mbox_prefetch; |
176 | msg->msg_prefetch_free = mbox_prefetch_free; | 176 | msg->msg_prefetch_free = mbox_prefetch_free; |
177 | msg_info->msg_uid = uid; | 177 | msg_info->msg_uid = uid; |
178 | 178 | ||
179 | return MAIL_NO_ERROR; | 179 | return MAIL_NO_ERROR; |
180 | 180 | ||
181 | err: | 181 | err: |
182 | return res; | 182 | return res; |
183 | } | 183 | } |
184 | 184 | ||
185 | static int mbox_fetch_size(mailmessage * msg_info, | 185 | static int mbox_fetch_size(mailmessage * msg_info, |
186 | size_t * result) | 186 | size_t * result) |
187 | { | 187 | { |
188 | int r; | 188 | int r; |
189 | size_t size; | 189 | size_t size; |
190 | 190 | ||
191 | r = mboxdriver_fetch_size(msg_info->msg_session, | 191 | r = mboxdriver_fetch_size(msg_info->msg_session, |
192 | msg_info->msg_index, &size); | 192 | msg_info->msg_index, &size); |
diff --git a/kmicromail/libetpan/generic/mboxdriver_tools.c b/kmicromail/libetpan/generic/mboxdriver_tools.c index 1e27798..252a20b 100644 --- a/kmicromail/libetpan/generic/mboxdriver_tools.c +++ b/kmicromail/libetpan/generic/mboxdriver_tools.c | |||
@@ -188,65 +188,66 @@ int | |||
188 | mboxdriver_get_cached_flags(struct mail_cache_db * cache_db, | 188 | mboxdriver_get_cached_flags(struct mail_cache_db * cache_db, |
189 | MMAPString * mmapstr, | 189 | MMAPString * mmapstr, |
190 | mailsession * session, | 190 | mailsession * session, |
191 | uint32_t num, | 191 | uint32_t num, |
192 | struct mail_flags ** result) | 192 | struct mail_flags ** result) |
193 | { | 193 | { |
194 | int r; | 194 | int r; |
195 | char keyname[PATH_MAX]; | 195 | char keyname[PATH_MAX]; |
196 | struct mail_flags * flags; | 196 | struct mail_flags * flags; |
197 | int res; | 197 | int res; |
198 | struct mailmbox_msg_info * info; | 198 | struct mailmbox_msg_info * info; |
199 | struct mailmbox_folder * folder; | 199 | struct mailmbox_folder * folder; |
200 | chashdatum key; | 200 | chashdatum key; |
201 | chashdatum data; | 201 | chashdatum data; |
202 | 202 | ||
203 | folder = cached_session_get_mbox_session(session); | 203 | folder = cached_session_get_mbox_session(session); |
204 | if (folder == NULL) { | 204 | if (folder == NULL) { |
205 | res = MAIL_ERROR_BAD_STATE; | 205 | res = MAIL_ERROR_BAD_STATE; |
206 | goto err; | 206 | goto err; |
207 | } | 207 | } |
208 | 208 | ||
209 | key.data = # | 209 | key.data = # |
210 | key.len = sizeof(num); | 210 | key.len = sizeof(num); |
211 | 211 | ||
212 | r = chash_get(folder->mb_hash, &key, &data); | 212 | r = chash_get(folder->mb_hash, &key, &data); |
213 | if (r < 0) { | 213 | if (r < 0) { |
214 | res = MAIL_ERROR_MSG_NOT_FOUND; | 214 | res = MAIL_ERROR_MSG_NOT_FOUND; |
215 | goto err; | 215 | goto err; |
216 | } | 216 | } |
217 | 217 | ||
218 | info = data.data; | 218 | info = data.data; |
219 | 219 | ||
220 | snprintf(keyname, PATH_MAX, "%u-%u-flags", num, info->msg_body_len); | 220 | snprintf(keyname, PATH_MAX, "%u-%lu-flags", num, |
221 | (unsigned long) info->msg_body_len); | ||
221 | 222 | ||
222 | r = generic_cache_flags_read(cache_db, mmapstr, keyname, &flags); | 223 | r = generic_cache_flags_read(cache_db, mmapstr, keyname, &flags); |
223 | if (r != MAIL_NO_ERROR) { | 224 | if (r != MAIL_NO_ERROR) { |
224 | res = r; | 225 | res = r; |
225 | goto err; | 226 | goto err; |
226 | } | 227 | } |
227 | 228 | ||
228 | * result = flags; | 229 | * result = flags; |
229 | 230 | ||
230 | return MAIL_NO_ERROR; | 231 | return MAIL_NO_ERROR; |
231 | 232 | ||
232 | err: | 233 | err: |
233 | return res; | 234 | return res; |
234 | } | 235 | } |
235 | 236 | ||
236 | int | 237 | int |
237 | mboxdriver_write_cached_flags(struct mail_cache_db * cache_db, | 238 | mboxdriver_write_cached_flags(struct mail_cache_db * cache_db, |
238 | MMAPString * mmapstr, | 239 | MMAPString * mmapstr, |
239 | char * uid, | 240 | char * uid, |
240 | struct mail_flags * flags) | 241 | struct mail_flags * flags) |
241 | { | 242 | { |
242 | int r; | 243 | int r; |
243 | char keyname[PATH_MAX]; | 244 | char keyname[PATH_MAX]; |
244 | int res; | 245 | int res; |
245 | 246 | ||
246 | snprintf(keyname, PATH_MAX, "%s-flags", uid); | 247 | snprintf(keyname, PATH_MAX, "%s-flags", uid); |
247 | 248 | ||
248 | r = generic_cache_flags_write(cache_db, mmapstr, keyname, flags); | 249 | r = generic_cache_flags_write(cache_db, mmapstr, keyname, flags); |
249 | if (r != MAIL_NO_ERROR) { | 250 | if (r != MAIL_NO_ERROR) { |
250 | res = r; | 251 | res = r; |
251 | goto err; | 252 | goto err; |
252 | } | 253 | } |
diff --git a/kmicromail/libetpan/generic/mboxstorage.c b/kmicromail/libetpan/generic/mboxstorage.c index 0a7dc93..4b55b2b 100644 --- a/kmicromail/libetpan/generic/mboxstorage.c +++ b/kmicromail/libetpan/generic/mboxstorage.c | |||
@@ -36,65 +36,65 @@ | |||
36 | #include "mboxstorage.h" | 36 | #include "mboxstorage.h" |
37 | 37 | ||
38 | #include "mail.h" | 38 | #include "mail.h" |
39 | #include "mailmessage.h" | 39 | #include "mailmessage.h" |
40 | #include "mboxdriver.h" | 40 | #include "mboxdriver.h" |
41 | #include "mboxdriver_cached.h" | 41 | #include "mboxdriver_cached.h" |
42 | #include "maildriver.h" | 42 | #include "maildriver.h" |
43 | 43 | ||
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | #include <string.h> | 45 | #include <string.h> |
46 | 46 | ||
47 | /* mbox storage */ | 47 | /* mbox storage */ |
48 | 48 | ||
49 | static int mbox_mailstorage_connect(struct mailstorage * storage); | 49 | static int mbox_mailstorage_connect(struct mailstorage * storage); |
50 | static int | 50 | static int |
51 | mbox_mailstorage_get_folder_session(struct mailstorage * storage, | 51 | mbox_mailstorage_get_folder_session(struct mailstorage * storage, |
52 | char * pathname, mailsession ** result); | 52 | char * pathname, mailsession ** result); |
53 | static void mbox_mailstorage_uninitialize(struct mailstorage * storage); | 53 | static void mbox_mailstorage_uninitialize(struct mailstorage * storage); |
54 | 54 | ||
55 | static mailstorage_driver mbox_mailstorage_driver = { | 55 | static mailstorage_driver mbox_mailstorage_driver = { |
56 | .sto_name = "mbox", | 56 | .sto_name = "mbox", |
57 | .sto_connect = mbox_mailstorage_connect, | 57 | .sto_connect = mbox_mailstorage_connect, |
58 | .sto_get_folder_session = mbox_mailstorage_get_folder_session, | 58 | .sto_get_folder_session = mbox_mailstorage_get_folder_session, |
59 | .sto_uninitialize = mbox_mailstorage_uninitialize, | 59 | .sto_uninitialize = mbox_mailstorage_uninitialize, |
60 | }; | 60 | }; |
61 | 61 | ||
62 | int mbox_mailstorage_init(struct mailstorage * storage, | 62 | int mbox_mailstorage_init(struct mailstorage * storage, |
63 | char * mbox_pathname, int mbox_cached, | 63 | char * mbox_pathname, int mbox_cached, |
64 | char * mbox_cache_directory, char * mbox_flags_directory) | 64 | char * mbox_cache_directory, char * mbox_flags_directory) |
65 | { | 65 | { |
66 | struct mbox_mailstorage * mbox_storage; | 66 | struct mbox_mailstorage * mbox_storage; |
67 | 67 | ||
68 | mbox_storage = malloc(sizeof(struct mbox_mailstorage)); | 68 | mbox_storage = malloc(sizeof(* mbox_storage)); |
69 | if (mbox_storage == NULL) | 69 | if (mbox_storage == NULL) |
70 | goto err; | 70 | goto err; |
71 | 71 | ||
72 | mbox_storage->mbox_pathname = strdup(mbox_pathname); | 72 | mbox_storage->mbox_pathname = strdup(mbox_pathname); |
73 | if (mbox_storage->mbox_pathname == NULL) | 73 | if (mbox_storage->mbox_pathname == NULL) |
74 | goto free; | 74 | goto free; |
75 | 75 | ||
76 | mbox_storage->mbox_cached = mbox_cached; | 76 | mbox_storage->mbox_cached = mbox_cached; |
77 | 77 | ||
78 | if (mbox_cached && (mbox_cache_directory != NULL) && | 78 | if (mbox_cached && (mbox_cache_directory != NULL) && |
79 | (mbox_flags_directory != NULL)) { | 79 | (mbox_flags_directory != NULL)) { |
80 | mbox_storage->mbox_cache_directory = strdup(mbox_cache_directory); | 80 | mbox_storage->mbox_cache_directory = strdup(mbox_cache_directory); |
81 | if (mbox_storage->mbox_cache_directory == NULL) | 81 | if (mbox_storage->mbox_cache_directory == NULL) |
82 | goto free_pathname; | 82 | goto free_pathname; |
83 | 83 | ||
84 | mbox_storage->mbox_flags_directory = strdup(mbox_flags_directory); | 84 | mbox_storage->mbox_flags_directory = strdup(mbox_flags_directory); |
85 | if (mbox_storage->mbox_flags_directory == NULL) | 85 | if (mbox_storage->mbox_flags_directory == NULL) |
86 | goto free_cache_directory; | 86 | goto free_cache_directory; |
87 | } | 87 | } |
88 | else { | 88 | else { |
89 | mbox_storage->mbox_cached = FALSE; | 89 | mbox_storage->mbox_cached = FALSE; |
90 | mbox_storage->mbox_cache_directory = NULL; | 90 | mbox_storage->mbox_cache_directory = NULL; |
91 | mbox_storage->mbox_flags_directory = NULL; | 91 | mbox_storage->mbox_flags_directory = NULL; |
92 | } | 92 | } |
93 | 93 | ||
94 | storage->sto_data = mbox_storage; | 94 | storage->sto_data = mbox_storage; |
95 | storage->sto_driver = &mbox_mailstorage_driver; | 95 | storage->sto_driver = &mbox_mailstorage_driver; |
96 | 96 | ||
97 | return MAIL_NO_ERROR; | 97 | return MAIL_NO_ERROR; |
98 | 98 | ||
99 | free_cache_directory: | 99 | free_cache_directory: |
100 | free(mbox_storage->mbox_cache_directory); | 100 | free(mbox_storage->mbox_cache_directory); |
diff --git a/kmicromail/libetpan/generic/mhdriver.c b/kmicromail/libetpan/generic/mhdriver.c index af38d27..05a6a4f 100644 --- a/kmicromail/libetpan/generic/mhdriver.c +++ b/kmicromail/libetpan/generic/mhdriver.c | |||
@@ -60,115 +60,118 @@ static int mhdriver_connect_path(mailsession * session, char * path); | |||
60 | static int mhdriver_logout(mailsession * session); | 60 | static int mhdriver_logout(mailsession * session); |
61 | 61 | ||
62 | static int mhdriver_build_folder_name(mailsession * session, char * mb, | 62 | static int mhdriver_build_folder_name(mailsession * session, char * mb, |
63 | char * name, char ** result); | 63 | char * name, char ** result); |
64 | static int mhdriver_create_folder(mailsession * session, char * mb); | 64 | static int mhdriver_create_folder(mailsession * session, char * mb); |
65 | 65 | ||
66 | static int mhdriver_delete_folder(mailsession * session, char * mb); | 66 | static int mhdriver_delete_folder(mailsession * session, char * mb); |
67 | 67 | ||
68 | static int mhdriver_rename_folder(mailsession * session, char * mb, | 68 | static int mhdriver_rename_folder(mailsession * session, char * mb, |
69 | char * new_name); | 69 | char * new_name); |
70 | 70 | ||
71 | static int mhdriver_select_folder(mailsession * session, char * mb); | 71 | static int mhdriver_select_folder(mailsession * session, char * mb); |
72 | 72 | ||
73 | static int mhdriver_status_folder(mailsession * session, char * mb, | 73 | static int mhdriver_status_folder(mailsession * session, char * mb, |
74 | uint32_t * result_messages, uint32_t * result_recent, | 74 | uint32_t * result_messages, uint32_t * result_recent, |
75 | uint32_t * result_unseen); | 75 | uint32_t * result_unseen); |
76 | 76 | ||
77 | static int mhdriver_messages_number(mailsession * session, char * mb, | 77 | static int mhdriver_messages_number(mailsession * session, char * mb, |
78 | uint32_t * result); | 78 | uint32_t * result); |
79 | 79 | ||
80 | static int mhdriver_list_folders(mailsession * session, char * mb, | 80 | static int mhdriver_list_folders(mailsession * session, char * mb, |
81 | struct mail_list ** result); | 81 | struct mail_list ** result); |
82 | 82 | ||
83 | static int mhdriver_lsub_folders(mailsession * session, char * mb, | 83 | static int mhdriver_lsub_folders(mailsession * session, char * mb, |
84 | struct mail_list ** result); | 84 | struct mail_list ** result); |
85 | 85 | ||
86 | static int mhdriver_subscribe_folder(mailsession * session, char * mb); | 86 | static int mhdriver_subscribe_folder(mailsession * session, char * mb); |
87 | 87 | ||
88 | static int mhdriver_unsubscribe_folder(mailsession * session, char * mb); | 88 | static int mhdriver_unsubscribe_folder(mailsession * session, char * mb); |
89 | 89 | ||
90 | static int mhdriver_append_message(mailsession * session, | 90 | static int mhdriver_append_message(mailsession * session, |
91 | char * message, size_t size); | 91 | char * message, size_t size); |
92 | static int mhdriver_append_message_flags(mailsession * session, | ||
93 | char * message, size_t size, struct mail_flags * flags); | ||
92 | static int mhdriver_copy_message(mailsession * session, | 94 | static int mhdriver_copy_message(mailsession * session, |
93 | uint32_t num, char * mb); | 95 | uint32_t num, char * mb); |
94 | 96 | ||
95 | static int mhdriver_remove_message(mailsession * session, uint32_t num); | 97 | static int mhdriver_remove_message(mailsession * session, uint32_t num); |
96 | 98 | ||
97 | static int mhdriver_move_message(mailsession * session, | 99 | static int mhdriver_move_message(mailsession * session, |
98 | uint32_t num, char * mb); | 100 | uint32_t num, char * mb); |
99 | 101 | ||
100 | static int mhdriver_get_messages_list(mailsession * session, | 102 | static int mhdriver_get_messages_list(mailsession * session, |
101 | struct mailmessage_list ** result); | 103 | struct mailmessage_list ** result); |
102 | 104 | ||
103 | static int mhdriver_get_message(mailsession * session, | 105 | static int mhdriver_get_message(mailsession * session, |
104 | uint32_t num, mailmessage ** result); | 106 | uint32_t num, mailmessage ** result); |
105 | 107 | ||
106 | static int mhdriver_get_message_by_uid(mailsession * session, | 108 | static int mhdriver_get_message_by_uid(mailsession * session, |
107 | const char * uid, | 109 | const char * uid, |
108 | mailmessage ** result); | 110 | mailmessage ** result); |
109 | 111 | ||
110 | static mailsession_driver local_mh_session_driver = { | 112 | static mailsession_driver local_mh_session_driver = { |
111 | .sess_name = "mh", | 113 | .sess_name = "mh", |
112 | 114 | ||
113 | .sess_initialize = mhdriver_initialize, | 115 | .sess_initialize = mhdriver_initialize, |
114 | .sess_uninitialize = mhdriver_uninitialize, | 116 | .sess_uninitialize = mhdriver_uninitialize, |
115 | 117 | ||
116 | .sess_parameters = NULL, | 118 | .sess_parameters = NULL, |
117 | 119 | ||
118 | .sess_connect_stream = NULL, | 120 | .sess_connect_stream = NULL, |
119 | .sess_connect_path = mhdriver_connect_path, | 121 | .sess_connect_path = mhdriver_connect_path, |
120 | .sess_starttls = NULL, | 122 | .sess_starttls = NULL, |
121 | .sess_login = NULL, | 123 | .sess_login = NULL, |
122 | .sess_logout = mhdriver_logout, | 124 | .sess_logout = mhdriver_logout, |
123 | .sess_noop = NULL, | 125 | .sess_noop = NULL, |
124 | 126 | ||
125 | .sess_build_folder_name = mhdriver_build_folder_name, | 127 | .sess_build_folder_name = mhdriver_build_folder_name, |
126 | .sess_create_folder = mhdriver_create_folder, | 128 | .sess_create_folder = mhdriver_create_folder, |
127 | .sess_delete_folder = mhdriver_delete_folder, | 129 | .sess_delete_folder = mhdriver_delete_folder, |
128 | .sess_rename_folder = mhdriver_rename_folder, | 130 | .sess_rename_folder = mhdriver_rename_folder, |
129 | .sess_check_folder = NULL, | 131 | .sess_check_folder = NULL, |
130 | .sess_examine_folder = NULL, | 132 | .sess_examine_folder = NULL, |
131 | .sess_select_folder = mhdriver_select_folder, | 133 | .sess_select_folder = mhdriver_select_folder, |
132 | .sess_expunge_folder = NULL, | 134 | .sess_expunge_folder = NULL, |
133 | .sess_status_folder = mhdriver_status_folder, | 135 | .sess_status_folder = mhdriver_status_folder, |
134 | .sess_messages_number = mhdriver_messages_number, | 136 | .sess_messages_number = mhdriver_messages_number, |
135 | .sess_recent_number = mhdriver_messages_number, | 137 | .sess_recent_number = mhdriver_messages_number, |
136 | .sess_unseen_number = mhdriver_messages_number, | 138 | .sess_unseen_number = mhdriver_messages_number, |
137 | .sess_list_folders = mhdriver_list_folders, | 139 | .sess_list_folders = mhdriver_list_folders, |
138 | .sess_lsub_folders = mhdriver_lsub_folders, | 140 | .sess_lsub_folders = mhdriver_lsub_folders, |
139 | .sess_subscribe_folder = mhdriver_subscribe_folder, | 141 | .sess_subscribe_folder = mhdriver_subscribe_folder, |
140 | .sess_unsubscribe_folder = mhdriver_unsubscribe_folder, | 142 | .sess_unsubscribe_folder = mhdriver_unsubscribe_folder, |
141 | 143 | ||
142 | .sess_append_message = mhdriver_append_message, | 144 | .sess_append_message = mhdriver_append_message, |
145 | .sess_append_message_flags = mhdriver_append_message_flags, | ||
143 | .sess_copy_message = mhdriver_copy_message, | 146 | .sess_copy_message = mhdriver_copy_message, |
144 | .sess_move_message = mhdriver_move_message, | 147 | .sess_move_message = mhdriver_move_message, |
145 | 148 | ||
146 | .sess_get_messages_list = mhdriver_get_messages_list, | 149 | .sess_get_messages_list = mhdriver_get_messages_list, |
147 | .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, | 150 | .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, |
148 | .sess_remove_message = mhdriver_remove_message, | 151 | .sess_remove_message = mhdriver_remove_message, |
149 | #if 0 | 152 | #if 0 |
150 | .sess_search_messages = maildriver_generic_search_messages, | 153 | .sess_search_messages = maildriver_generic_search_messages, |
151 | #endif | 154 | #endif |
152 | 155 | ||
153 | .sess_get_message = mhdriver_get_message, | 156 | .sess_get_message = mhdriver_get_message, |
154 | .sess_get_message_by_uid = mhdriver_get_message_by_uid, | 157 | .sess_get_message_by_uid = mhdriver_get_message_by_uid, |
155 | }; | 158 | }; |
156 | 159 | ||
157 | mailsession_driver * mh_session_driver = &local_mh_session_driver; | 160 | mailsession_driver * mh_session_driver = &local_mh_session_driver; |
158 | 161 | ||
159 | static inline struct mh_session_state_data * get_data(mailsession * session) | 162 | static inline struct mh_session_state_data * get_data(mailsession * session) |
160 | { | 163 | { |
161 | return session->sess_data; | 164 | return session->sess_data; |
162 | } | 165 | } |
163 | 166 | ||
164 | static inline struct mailmh * get_mh_session(mailsession * session) | 167 | static inline struct mailmh * get_mh_session(mailsession * session) |
165 | { | 168 | { |
166 | return get_data(session)->mh_session; | 169 | return get_data(session)->mh_session; |
167 | } | 170 | } |
168 | 171 | ||
169 | static inline struct mailmh_folder * get_mh_cur_folder(mailsession * session) | 172 | static inline struct mailmh_folder * get_mh_cur_folder(mailsession * session) |
170 | { | 173 | { |
171 | return get_data(session)->mh_cur_folder; | 174 | return get_data(session)->mh_cur_folder; |
172 | } | 175 | } |
173 | 176 | ||
174 | static int add_to_list(mailsession * session, char * mb) | 177 | static int add_to_list(mailsession * session, char * mb) |
@@ -655,64 +658,70 @@ static int mhdriver_unsubscribe_folder(mailsession * session, char * mb) | |||
655 | int r; | 658 | int r; |
656 | 659 | ||
657 | r = remove_from_list(session, mb); | 660 | r = remove_from_list(session, mb); |
658 | if (r < 0) | 661 | if (r < 0) |
659 | return MAIL_ERROR_UNSUBSCRIBE; | 662 | return MAIL_ERROR_UNSUBSCRIBE; |
660 | 663 | ||
661 | return MAIL_NO_ERROR; | 664 | return MAIL_NO_ERROR; |
662 | } | 665 | } |
663 | 666 | ||
664 | /* messages operations */ | 667 | /* messages operations */ |
665 | 668 | ||
666 | static int mhdriver_append_message(mailsession * session, | 669 | static int mhdriver_append_message(mailsession * session, |
667 | char * message, size_t size) | 670 | char * message, size_t size) |
668 | { | 671 | { |
669 | int r; | 672 | int r; |
670 | struct mailmh_folder * folder; | 673 | struct mailmh_folder * folder; |
671 | 674 | ||
672 | folder = get_mh_cur_folder(session); | 675 | folder = get_mh_cur_folder(session); |
673 | if (folder == NULL) | 676 | if (folder == NULL) |
674 | return MAIL_ERROR_BAD_STATE; | 677 | return MAIL_ERROR_BAD_STATE; |
675 | 678 | ||
676 | r = mailmh_folder_add_message(folder, message, size); | 679 | r = mailmh_folder_add_message(folder, message, size); |
677 | 680 | ||
678 | switch (r) { | 681 | switch (r) { |
679 | case MAILMH_ERROR_FILE: | 682 | case MAILMH_ERROR_FILE: |
680 | return MAIL_ERROR_DISKSPACE; | 683 | return MAIL_ERROR_DISKSPACE; |
681 | 684 | ||
682 | default: | 685 | default: |
683 | return mhdriver_mh_error_to_mail_error(r); | 686 | return mhdriver_mh_error_to_mail_error(r); |
684 | } | 687 | } |
685 | } | 688 | } |
686 | 689 | ||
690 | static int mhdriver_append_message_flags(mailsession * session, | ||
691 | char * message, size_t size, struct mail_flags * flags) | ||
692 | { | ||
693 | return mhdriver_append_message(session, message, size); | ||
694 | } | ||
695 | |||
687 | static int mhdriver_copy_message(mailsession * session, | 696 | static int mhdriver_copy_message(mailsession * session, |
688 | uint32_t num, char * mb) | 697 | uint32_t num, char * mb) |
689 | { | 698 | { |
690 | int fd; | 699 | int fd; |
691 | int r; | 700 | int r; |
692 | struct mailmh_folder * folder; | 701 | struct mailmh_folder * folder; |
693 | struct mailmh * mh; | 702 | struct mailmh * mh; |
694 | int res; | 703 | int res; |
695 | 704 | ||
696 | mh = get_mh_session(session); | 705 | mh = get_mh_session(session); |
697 | if (mh == NULL) { | 706 | if (mh == NULL) { |
698 | res = MAIL_ERROR_BAD_STATE; | 707 | res = MAIL_ERROR_BAD_STATE; |
699 | goto err; | 708 | goto err; |
700 | } | 709 | } |
701 | 710 | ||
702 | folder = get_mh_cur_folder(session); | 711 | folder = get_mh_cur_folder(session); |
703 | if (folder == NULL) { | 712 | if (folder == NULL) { |
704 | res = MAIL_ERROR_BAD_STATE; | 713 | res = MAIL_ERROR_BAD_STATE; |
705 | goto err; | 714 | goto err; |
706 | } | 715 | } |
707 | 716 | ||
708 | r = mailmh_folder_get_message_fd(folder, num, O_RDONLY, &fd); | 717 | r = mailmh_folder_get_message_fd(folder, num, O_RDONLY, &fd); |
709 | if (r != MAIL_NO_ERROR) { | 718 | if (r != MAIL_NO_ERROR) { |
710 | res = r; | 719 | res = r; |
711 | goto err; | 720 | goto err; |
712 | } | 721 | } |
713 | 722 | ||
714 | folder = mailmh_folder_find(mh->mh_main, mb); | 723 | folder = mailmh_folder_find(mh->mh_main, mb); |
715 | if (folder == NULL) { | 724 | if (folder == NULL) { |
716 | res = MAIL_ERROR_FOLDER_NOT_FOUND; | 725 | res = MAIL_ERROR_FOLDER_NOT_FOUND; |
717 | goto close; | 726 | goto close; |
718 | } | 727 | } |
diff --git a/kmicromail/libetpan/generic/mhdriver_cached.c b/kmicromail/libetpan/generic/mhdriver_cached.c index 5c35089..04aa523 100644 --- a/kmicromail/libetpan/generic/mhdriver_cached.c +++ b/kmicromail/libetpan/generic/mhdriver_cached.c | |||
@@ -79,121 +79,124 @@ static int mhdriver_cached_rename_folder(mailsession * session, char * mb, | |||
79 | char * new_name); | 79 | char * new_name); |
80 | 80 | ||
81 | static int mhdriver_cached_check_folder(mailsession * session); | 81 | static int mhdriver_cached_check_folder(mailsession * session); |
82 | 82 | ||
83 | static int mhdriver_cached_select_folder(mailsession * session, char * mb); | 83 | static int mhdriver_cached_select_folder(mailsession * session, char * mb); |
84 | 84 | ||
85 | static int mhdriver_cached_expunge_folder(mailsession * session); | 85 | static int mhdriver_cached_expunge_folder(mailsession * session); |
86 | 86 | ||
87 | static int mhdriver_cached_status_folder(mailsession * session, char * mb, | 87 | static int mhdriver_cached_status_folder(mailsession * session, char * mb, |
88 | uint32_t * result_messages, uint32_t * result_recent, | 88 | uint32_t * result_messages, uint32_t * result_recent, |
89 | uint32_t * result_unseen); | 89 | uint32_t * result_unseen); |
90 | 90 | ||
91 | static int mhdriver_cached_messages_number(mailsession * session, char * mb, | 91 | static int mhdriver_cached_messages_number(mailsession * session, char * mb, |
92 | uint32_t * result); | 92 | uint32_t * result); |
93 | static int mhdriver_cached_recent_number(mailsession * session, char * mb, | 93 | static int mhdriver_cached_recent_number(mailsession * session, char * mb, |
94 | uint32_t * result); | 94 | uint32_t * result); |
95 | static int mhdriver_cached_unseen_number(mailsession * session, char * mb, | 95 | static int mhdriver_cached_unseen_number(mailsession * session, char * mb, |
96 | uint32_t * result); | 96 | uint32_t * result); |
97 | 97 | ||
98 | static int mhdriver_cached_list_folders(mailsession * session, char * mb, | 98 | static int mhdriver_cached_list_folders(mailsession * session, char * mb, |
99 | struct mail_list ** result); | 99 | struct mail_list ** result); |
100 | 100 | ||
101 | static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, | 101 | static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, |
102 | struct mail_list ** result); | 102 | struct mail_list ** result); |
103 | 103 | ||
104 | static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb); | 104 | static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb); |
105 | 105 | ||
106 | static int mhdriver_cached_unsubscribe_folder(mailsession * session, | 106 | static int mhdriver_cached_unsubscribe_folder(mailsession * session, |
107 | char * mb); | 107 | char * mb); |
108 | 108 | ||
109 | static int mhdriver_cached_append_message(mailsession * session, | 109 | static int mhdriver_cached_append_message(mailsession * session, |
110 | char * message, size_t size); | 110 | char * message, size_t size); |
111 | static int mhdriver_cached_append_message_flags(mailsession * session, | ||
112 | char * message, size_t size, struct mail_flags * flags); | ||
111 | static int mhdriver_cached_copy_message(mailsession * session, | 113 | static int mhdriver_cached_copy_message(mailsession * session, |
112 | uint32_t num, char * mb); | 114 | uint32_t num, char * mb); |
113 | 115 | ||
114 | static int mhdriver_cached_remove_message(mailsession * session, | 116 | static int mhdriver_cached_remove_message(mailsession * session, |
115 | uint32_t num); | 117 | uint32_t num); |
116 | 118 | ||
117 | static int mhdriver_cached_move_message(mailsession * session, | 119 | static int mhdriver_cached_move_message(mailsession * session, |
118 | uint32_t num, char * mb); | 120 | uint32_t num, char * mb); |
119 | 121 | ||
120 | static int | 122 | static int |
121 | mhdriver_cached_get_messages_list(mailsession * session, | 123 | mhdriver_cached_get_messages_list(mailsession * session, |
122 | struct mailmessage_list ** result); | 124 | struct mailmessage_list ** result); |
123 | 125 | ||
124 | static int | 126 | static int |
125 | mhdriver_cached_get_envelopes_list(mailsession * session, | 127 | mhdriver_cached_get_envelopes_list(mailsession * session, |
126 | struct mailmessage_list * env_list); | 128 | struct mailmessage_list * env_list); |
127 | 129 | ||
128 | static int mhdriver_cached_get_message(mailsession * session, | 130 | static int mhdriver_cached_get_message(mailsession * session, |
129 | uint32_t num, mailmessage ** result); | 131 | uint32_t num, mailmessage ** result); |
130 | 132 | ||
131 | static int mhdriver_cached_get_message_by_uid(mailsession * session, | 133 | static int mhdriver_cached_get_message_by_uid(mailsession * session, |
132 | const char * uid, | 134 | const char * uid, |
133 | mailmessage ** result); | 135 | mailmessage ** result); |
134 | 136 | ||
135 | static mailsession_driver local_mh_cached_session_driver = { | 137 | static mailsession_driver local_mh_cached_session_driver = { |
136 | .sess_name = "mh-cached", | 138 | .sess_name = "mh-cached", |
137 | 139 | ||
138 | .sess_initialize = mhdriver_cached_initialize, | 140 | .sess_initialize = mhdriver_cached_initialize, |
139 | .sess_uninitialize = mhdriver_cached_uninitialize, | 141 | .sess_uninitialize = mhdriver_cached_uninitialize, |
140 | 142 | ||
141 | .sess_parameters = mhdriver_cached_parameters, | 143 | .sess_parameters = mhdriver_cached_parameters, |
142 | 144 | ||
143 | .sess_connect_stream = NULL, | 145 | .sess_connect_stream = NULL, |
144 | .sess_connect_path = mhdriver_cached_connect_path, | 146 | .sess_connect_path = mhdriver_cached_connect_path, |
145 | .sess_starttls = NULL, | 147 | .sess_starttls = NULL, |
146 | .sess_login = NULL, | 148 | .sess_login = NULL, |
147 | .sess_logout = mhdriver_cached_logout, | 149 | .sess_logout = mhdriver_cached_logout, |
148 | .sess_noop = NULL, | 150 | .sess_noop = NULL, |
149 | 151 | ||
150 | .sess_build_folder_name = mhdriver_cached_build_folder_name, | 152 | .sess_build_folder_name = mhdriver_cached_build_folder_name, |
151 | .sess_create_folder = mhdriver_cached_create_folder, | 153 | .sess_create_folder = mhdriver_cached_create_folder, |
152 | .sess_delete_folder = mhdriver_cached_delete_folder, | 154 | .sess_delete_folder = mhdriver_cached_delete_folder, |
153 | .sess_rename_folder = mhdriver_cached_rename_folder, | 155 | .sess_rename_folder = mhdriver_cached_rename_folder, |
154 | .sess_check_folder = mhdriver_cached_check_folder, | 156 | .sess_check_folder = mhdriver_cached_check_folder, |
155 | .sess_examine_folder = NULL, | 157 | .sess_examine_folder = NULL, |
156 | .sess_select_folder = mhdriver_cached_select_folder, | 158 | .sess_select_folder = mhdriver_cached_select_folder, |
157 | .sess_expunge_folder = mhdriver_cached_expunge_folder, | 159 | .sess_expunge_folder = mhdriver_cached_expunge_folder, |
158 | .sess_status_folder = mhdriver_cached_status_folder, | 160 | .sess_status_folder = mhdriver_cached_status_folder, |
159 | .sess_messages_number = mhdriver_cached_messages_number, | 161 | .sess_messages_number = mhdriver_cached_messages_number, |
160 | .sess_recent_number = mhdriver_cached_recent_number, | 162 | .sess_recent_number = mhdriver_cached_recent_number, |
161 | .sess_unseen_number = mhdriver_cached_unseen_number, | 163 | .sess_unseen_number = mhdriver_cached_unseen_number, |
162 | .sess_list_folders = mhdriver_cached_list_folders, | 164 | .sess_list_folders = mhdriver_cached_list_folders, |
163 | .sess_lsub_folders = mhdriver_cached_lsub_folders, | 165 | .sess_lsub_folders = mhdriver_cached_lsub_folders, |
164 | .sess_subscribe_folder = mhdriver_cached_subscribe_folder, | 166 | .sess_subscribe_folder = mhdriver_cached_subscribe_folder, |
165 | .sess_unsubscribe_folder = mhdriver_cached_unsubscribe_folder, | 167 | .sess_unsubscribe_folder = mhdriver_cached_unsubscribe_folder, |
166 | 168 | ||
167 | .sess_append_message = mhdriver_cached_append_message, | 169 | .sess_append_message = mhdriver_cached_append_message, |
170 | .sess_append_message_flags = mhdriver_cached_append_message_flags, | ||
168 | .sess_copy_message = mhdriver_cached_copy_message, | 171 | .sess_copy_message = mhdriver_cached_copy_message, |
169 | .sess_move_message = mhdriver_cached_move_message, | 172 | .sess_move_message = mhdriver_cached_move_message, |
170 | 173 | ||
171 | .sess_get_messages_list = mhdriver_cached_get_messages_list, | 174 | .sess_get_messages_list = mhdriver_cached_get_messages_list, |
172 | .sess_get_envelopes_list = mhdriver_cached_get_envelopes_list, | 175 | .sess_get_envelopes_list = mhdriver_cached_get_envelopes_list, |
173 | .sess_remove_message = mhdriver_cached_remove_message, | 176 | .sess_remove_message = mhdriver_cached_remove_message, |
174 | #if 0 | 177 | #if 0 |
175 | .sess_search_messages = maildriver_generic_search_messages, | 178 | .sess_search_messages = maildriver_generic_search_messages, |
176 | #endif | 179 | #endif |
177 | 180 | ||
178 | .sess_get_message = mhdriver_cached_get_message, | 181 | .sess_get_message = mhdriver_cached_get_message, |
179 | .sess_get_message_by_uid = mhdriver_cached_get_message_by_uid, | 182 | .sess_get_message_by_uid = mhdriver_cached_get_message_by_uid, |
180 | }; | 183 | }; |
181 | 184 | ||
182 | mailsession_driver * mh_cached_session_driver = | 185 | mailsession_driver * mh_cached_session_driver = |
183 | &local_mh_cached_session_driver; | 186 | &local_mh_cached_session_driver; |
184 | 187 | ||
185 | #define ENV_NAME "env.db" | 188 | #define ENV_NAME "env.db" |
186 | #define FLAGS_NAME "flags.db" | 189 | #define FLAGS_NAME "flags.db" |
187 | 190 | ||
188 | 191 | ||
189 | static inline struct mh_cached_session_state_data * | 192 | static inline struct mh_cached_session_state_data * |
190 | get_cached_data(mailsession * session) | 193 | get_cached_data(mailsession * session) |
191 | { | 194 | { |
192 | return session->sess_data; | 195 | return session->sess_data; |
193 | } | 196 | } |
194 | 197 | ||
195 | static inline mailsession * get_ancestor(mailsession * session) | 198 | static inline mailsession * get_ancestor(mailsession * session) |
196 | { | 199 | { |
197 | return get_cached_data(session)->mh_ancestor; | 200 | return get_cached_data(session)->mh_ancestor; |
198 | } | 201 | } |
199 | 202 | ||
@@ -854,65 +857,143 @@ static int mhdriver_cached_unseen_number(mailsession * session, char * mb, | |||
854 | return MAIL_NO_ERROR; | 857 | return MAIL_NO_ERROR; |
855 | } | 858 | } |
856 | 859 | ||
857 | 860 | ||
858 | static int mhdriver_cached_list_folders(mailsession * session, char * mb, | 861 | static int mhdriver_cached_list_folders(mailsession * session, char * mb, |
859 | struct mail_list ** result) | 862 | struct mail_list ** result) |
860 | { | 863 | { |
861 | return mailsession_list_folders(get_ancestor(session), mb, result); | 864 | return mailsession_list_folders(get_ancestor(session), mb, result); |
862 | } | 865 | } |
863 | 866 | ||
864 | static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, | 867 | static int mhdriver_cached_lsub_folders(mailsession * session, char * mb, |
865 | struct mail_list ** result) | 868 | struct mail_list ** result) |
866 | { | 869 | { |
867 | return mailsession_lsub_folders(get_ancestor(session), mb, result); | 870 | return mailsession_lsub_folders(get_ancestor(session), mb, result); |
868 | } | 871 | } |
869 | 872 | ||
870 | static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb) | 873 | static int mhdriver_cached_subscribe_folder(mailsession * session, char * mb) |
871 | { | 874 | { |
872 | return mailsession_subscribe_folder(get_ancestor(session), mb); | 875 | return mailsession_subscribe_folder(get_ancestor(session), mb); |
873 | } | 876 | } |
874 | 877 | ||
875 | static int mhdriver_cached_unsubscribe_folder(mailsession * session, | 878 | static int mhdriver_cached_unsubscribe_folder(mailsession * session, |
876 | char * mb) | 879 | char * mb) |
877 | { | 880 | { |
878 | return mailsession_unsubscribe_folder(get_ancestor(session), mb); | 881 | return mailsession_unsubscribe_folder(get_ancestor(session), mb); |
879 | } | 882 | } |
880 | 883 | ||
881 | /* messages operations */ | 884 | /* messages operations */ |
882 | 885 | ||
883 | static int mhdriver_cached_append_message(mailsession * session, | 886 | static int mhdriver_cached_append_message(mailsession * session, |
884 | char * message, size_t size) | 887 | char * message, size_t size) |
885 | { | 888 | { |
886 | return mailsession_append_message(get_ancestor(session), message, size); | 889 | return mhdriver_cached_append_message_flags(session, |
890 | message, size, NULL); | ||
891 | } | ||
892 | |||
893 | static int mhdriver_cached_append_message_flags(mailsession * session, | ||
894 | char * message, size_t size, struct mail_flags * flags) | ||
895 | { | ||
896 | int r; | ||
897 | struct mailmh_folder * folder; | ||
898 | struct mailmh_msg_info * msg_info; | ||
899 | chashdatum key; | ||
900 | chashdatum value; | ||
901 | uint32_t uid; | ||
902 | struct mh_cached_session_state_data * data; | ||
903 | char filename_flags[PATH_MAX]; | ||
904 | struct mail_cache_db * cache_db_flags; | ||
905 | MMAPString * mmapstr; | ||
906 | char keyname[PATH_MAX]; | ||
907 | |||
908 | folder = get_mh_cur_folder(session); | ||
909 | if (folder == NULL) | ||
910 | return MAIL_ERROR_BAD_STATE; | ||
911 | |||
912 | r = mailmh_folder_add_message_uid(folder, | ||
913 | message, size, &uid); | ||
914 | |||
915 | switch (r) { | ||
916 | case MAILMH_ERROR_FILE: | ||
917 | return MAIL_ERROR_DISKSPACE; | ||
918 | |||
919 | case MAILMH_NO_ERROR: | ||
920 | break; | ||
921 | |||
922 | default: | ||
923 | return mhdriver_mh_error_to_mail_error(r); | ||
924 | } | ||
925 | |||
926 | if (flags == NULL) | ||
927 | goto exit; | ||
928 | |||
929 | key.data = &uid; | ||
930 | key.len = sizeof(uid); | ||
931 | r = chash_get(folder->fl_msgs_hash, &key, &value); | ||
932 | if (r < 0) | ||
933 | return MAIL_ERROR_CACHE_MISS; | ||
934 | |||
935 | msg_info = value.data; | ||
936 | |||
937 | data = get_cached_data(session); | ||
938 | |||
939 | snprintf(filename_flags, PATH_MAX, "%s/%s/%s", | ||
940 | data->mh_flags_directory, data->mh_quoted_mb, FLAGS_NAME); | ||
941 | |||
942 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
943 | if (r < 0) | ||
944 | goto exit; | ||
945 | |||
946 | mmapstr = mmap_string_new(""); | ||
947 | if (mmapstr == NULL) | ||
948 | goto close_db_flags; | ||
949 | |||
950 | snprintf(keyname, PATH_MAX, "%u-%lu-%lu-flags", | ||
951 | uid, (unsigned long) msg_info->msg_mtime, | ||
952 | (unsigned long) msg_info->msg_size); | ||
953 | |||
954 | r = mhdriver_write_cached_flags(cache_db_flags, mmapstr, keyname, flags); | ||
955 | |||
956 | mmap_string_free(mmapstr); | ||
957 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
958 | |||
959 | if (r != MAIL_NO_ERROR) | ||
960 | goto exit; | ||
961 | |||
962 | return MAIL_NO_ERROR; | ||
963 | |||
964 | close_db_flags: | ||
965 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
966 | exit: | ||
967 | return MAIL_NO_ERROR; | ||
887 | } | 968 | } |
888 | 969 | ||
889 | static int mhdriver_cached_copy_message(mailsession * session, | 970 | static int mhdriver_cached_copy_message(mailsession * session, |
890 | uint32_t num, char * mb) | 971 | uint32_t num, char * mb) |
891 | { | 972 | { |
892 | return mailsession_copy_message(get_ancestor(session), num, mb); | 973 | return mailsession_copy_message(get_ancestor(session), num, mb); |
893 | } | 974 | } |
894 | 975 | ||
895 | static int mhdriver_cached_remove_message(mailsession * session, uint32_t num) | 976 | static int mhdriver_cached_remove_message(mailsession * session, uint32_t num) |
896 | { | 977 | { |
897 | return mailsession_remove_message(get_ancestor(session), num); | 978 | return mailsession_remove_message(get_ancestor(session), num); |
898 | } | 979 | } |
899 | 980 | ||
900 | static int mhdriver_cached_move_message(mailsession * session, | 981 | static int mhdriver_cached_move_message(mailsession * session, |
901 | uint32_t num, char * mb) | 982 | uint32_t num, char * mb) |
902 | { | 983 | { |
903 | return mailsession_move_message(get_ancestor(session), num, mb); | 984 | return mailsession_move_message(get_ancestor(session), num, mb); |
904 | } | 985 | } |
905 | 986 | ||
906 | static int | 987 | static int |
907 | mhdriver_cached_get_messages_list(mailsession * session, | 988 | mhdriver_cached_get_messages_list(mailsession * session, |
908 | struct mailmessage_list ** result) | 989 | struct mailmessage_list ** result) |
909 | { | 990 | { |
910 | struct mailmh_folder * folder; | 991 | struct mailmh_folder * folder; |
911 | int res; | 992 | int res; |
912 | 993 | ||
913 | folder = get_mh_cur_folder(session); | 994 | folder = get_mh_cur_folder(session); |
914 | if (folder == NULL) { | 995 | if (folder == NULL) { |
915 | res = MAIL_ERROR_BAD_STATE; | 996 | res = MAIL_ERROR_BAD_STATE; |
916 | goto err; | 997 | goto err; |
917 | } | 998 | } |
918 | 999 | ||
@@ -924,111 +1005,113 @@ mhdriver_cached_get_messages_list(mailsession * session, | |||
924 | } | 1005 | } |
925 | 1006 | ||
926 | 1007 | ||
927 | 1008 | ||
928 | static int | 1009 | static int |
929 | get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | 1010 | get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, |
930 | mailsession * session, uint32_t num, | 1011 | mailsession * session, uint32_t num, |
931 | struct mailimf_fields ** result) | 1012 | struct mailimf_fields ** result) |
932 | { | 1013 | { |
933 | int r; | 1014 | int r; |
934 | char keyname[PATH_MAX]; | 1015 | char keyname[PATH_MAX]; |
935 | struct mailimf_fields * fields; | 1016 | struct mailimf_fields * fields; |
936 | int res; | 1017 | int res; |
937 | struct mailmh_folder * folder; | 1018 | struct mailmh_folder * folder; |
938 | struct mailmh_msg_info * msg_info; | 1019 | struct mailmh_msg_info * msg_info; |
939 | chashdatum key; | 1020 | chashdatum key; |
940 | chashdatum data; | 1021 | chashdatum data; |
941 | 1022 | ||
942 | folder = get_mh_cur_folder(session); | 1023 | folder = get_mh_cur_folder(session); |
943 | 1024 | ||
944 | #if 0 | 1025 | #if 0 |
945 | msg_info = cinthash_find(mh_data->mh_cur_folder->fl_msgs_hash, num); | 1026 | msg_info = cinthash_find(mh_data->mh_cur_folder->fl_msgs_hash, num); |
946 | if (msg_info == NULL) | 1027 | if (msg_info == NULL) |
947 | return MAIL_ERROR_CACHE_MISS; | 1028 | return MAIL_ERROR_CACHE_MISS; |
948 | #endif | 1029 | #endif |
949 | key.data = # | 1030 | key.data = # |
950 | key.len = sizeof(num); | 1031 | key.len = sizeof(num); |
951 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 1032 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
952 | if (r < 0) | 1033 | if (r < 0) |
953 | return MAIL_ERROR_CACHE_MISS; | 1034 | return MAIL_ERROR_CACHE_MISS; |
954 | msg_info = data.data; | 1035 | msg_info = data.data; |
955 | 1036 | ||
956 | snprintf(keyname, PATH_MAX, "%u-%u-%u-envelope", | 1037 | snprintf(keyname, PATH_MAX, "%u-%lu-%lu-envelope", |
957 | num, (uint32_t) msg_info->msg_mtime, msg_info->msg_size); | 1038 | num, (unsigned long) msg_info->msg_mtime, |
1039 | (unsigned long) msg_info->msg_size); | ||
958 | 1040 | ||
959 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); | 1041 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); |
960 | if (r != MAIL_NO_ERROR) { | 1042 | if (r != MAIL_NO_ERROR) { |
961 | res = r; | 1043 | res = r; |
962 | goto err; | 1044 | goto err; |
963 | } | 1045 | } |
964 | 1046 | ||
965 | * result = fields; | 1047 | * result = fields; |
966 | 1048 | ||
967 | return MAIL_NO_ERROR; | 1049 | return MAIL_NO_ERROR; |
968 | 1050 | ||
969 | err: | 1051 | err: |
970 | return res; | 1052 | return res; |
971 | } | 1053 | } |
972 | 1054 | ||
973 | static int | 1055 | static int |
974 | write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | 1056 | write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, |
975 | mailsession * session, uint32_t num, | 1057 | mailsession * session, uint32_t num, |
976 | struct mailimf_fields * fields) | 1058 | struct mailimf_fields * fields) |
977 | { | 1059 | { |
978 | int r; | 1060 | int r; |
979 | char keyname[PATH_MAX]; | 1061 | char keyname[PATH_MAX]; |
980 | int res; | 1062 | int res; |
981 | struct mailmh_folder * folder; | 1063 | struct mailmh_folder * folder; |
982 | chashdatum key; | 1064 | chashdatum key; |
983 | chashdatum data; | 1065 | chashdatum data; |
984 | struct mailmh_msg_info * msg_info; | 1066 | struct mailmh_msg_info * msg_info; |
985 | 1067 | ||
986 | folder = get_mh_cur_folder(session); | 1068 | folder = get_mh_cur_folder(session); |
987 | #if 0 | 1069 | #if 0 |
988 | msg_info = cinthash_find(mh_data->mh_cur_folder->fl_msgs_hash, num); | 1070 | msg_info = cinthash_find(mh_data->mh_cur_folder->fl_msgs_hash, num); |
989 | if (msg_info == NULL) { | 1071 | if (msg_info == NULL) { |
990 | res = MAIL_ERROR_CACHE_MISS; | 1072 | res = MAIL_ERROR_CACHE_MISS; |
991 | goto err; | 1073 | goto err; |
992 | } | 1074 | } |
993 | #endif | 1075 | #endif |
994 | key.data = # | 1076 | key.data = # |
995 | key.len = sizeof(num); | 1077 | key.len = sizeof(num); |
996 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 1078 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
997 | if (r < 0) | 1079 | if (r < 0) |
998 | return MAIL_ERROR_CACHE_MISS; | 1080 | return MAIL_ERROR_CACHE_MISS; |
999 | msg_info = data.data; | 1081 | msg_info = data.data; |
1000 | 1082 | ||
1001 | snprintf(keyname, PATH_MAX, "%u-%u-%u-envelope", | 1083 | snprintf(keyname, PATH_MAX, "%u-%lu-%lu-envelope", |
1002 | num, (uint32_t) msg_info->msg_mtime, msg_info->msg_size); | 1084 | num, (unsigned long) msg_info->msg_mtime, |
1085 | (unsigned long) msg_info->msg_size); | ||
1003 | 1086 | ||
1004 | r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); | 1087 | r = generic_cache_fields_write(cache_db, mmapstr, keyname, fields); |
1005 | if (r != MAIL_NO_ERROR) { | 1088 | if (r != MAIL_NO_ERROR) { |
1006 | res = r; | 1089 | res = r; |
1007 | goto err; | 1090 | goto err; |
1008 | } | 1091 | } |
1009 | 1092 | ||
1010 | return MAIL_NO_ERROR; | 1093 | return MAIL_NO_ERROR; |
1011 | 1094 | ||
1012 | err: | 1095 | err: |
1013 | return res; | 1096 | return res; |
1014 | } | 1097 | } |
1015 | 1098 | ||
1016 | static int | 1099 | static int |
1017 | mhdriver_cached_get_envelopes_list(mailsession * session, | 1100 | mhdriver_cached_get_envelopes_list(mailsession * session, |
1018 | struct mailmessage_list * env_list) | 1101 | struct mailmessage_list * env_list) |
1019 | { | 1102 | { |
1020 | int r; | 1103 | int r; |
1021 | unsigned int i; | 1104 | unsigned int i; |
1022 | char filename_env[PATH_MAX]; | 1105 | char filename_env[PATH_MAX]; |
1023 | char filename_flags[PATH_MAX]; | 1106 | char filename_flags[PATH_MAX]; |
1024 | struct mail_cache_db * cache_db_env; | 1107 | struct mail_cache_db * cache_db_env; |
1025 | struct mail_cache_db * cache_db_flags; | 1108 | struct mail_cache_db * cache_db_flags; |
1026 | MMAPString * mmapstr; | 1109 | MMAPString * mmapstr; |
1027 | int res; | 1110 | int res; |
1028 | struct mh_cached_session_state_data * cached_data; | 1111 | struct mh_cached_session_state_data * cached_data; |
1029 | 1112 | ||
1030 | cached_data = get_cached_data(session); | 1113 | cached_data = get_cached_data(session); |
1031 | if (cached_data->mh_quoted_mb == NULL) { | 1114 | if (cached_data->mh_quoted_mb == NULL) { |
1032 | res = MAIL_ERROR_BAD_STATE; | 1115 | res = MAIL_ERROR_BAD_STATE; |
1033 | goto err; | 1116 | goto err; |
1034 | } | 1117 | } |
diff --git a/kmicromail/libetpan/generic/mhdriver_cached_message.c b/kmicromail/libetpan/generic/mhdriver_cached_message.c index f716fb9..f69868d 100644 --- a/kmicromail/libetpan/generic/mhdriver_cached_message.c +++ b/kmicromail/libetpan/generic/mhdriver_cached_message.c | |||
@@ -150,66 +150,66 @@ static int mh_prefetch(mailmessage * msg_info) | |||
150 | return MAIL_NO_ERROR; | 150 | return MAIL_NO_ERROR; |
151 | } | 151 | } |
152 | 152 | ||
153 | static void mh_prefetch_free(struct generic_message_t * msg) | 153 | static void mh_prefetch_free(struct generic_message_t * msg) |
154 | { | 154 | { |
155 | if (msg->msg_message != NULL) { | 155 | if (msg->msg_message != NULL) { |
156 | mmap_string_unref(msg->msg_message); | 156 | mmap_string_unref(msg->msg_message); |
157 | msg->msg_message = NULL; | 157 | msg->msg_message = NULL; |
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | static int mh_initialize(mailmessage * msg_info) | 161 | static int mh_initialize(mailmessage * msg_info) |
162 | { | 162 | { |
163 | struct generic_message_t * msg; | 163 | struct generic_message_t * msg; |
164 | int r; | 164 | int r; |
165 | char * uid; | 165 | char * uid; |
166 | char static_uid[PATH_MAX]; | 166 | char static_uid[PATH_MAX]; |
167 | struct mailmh_msg_info * mh_msg_info; | 167 | struct mailmh_msg_info * mh_msg_info; |
168 | chashdatum key; | 168 | chashdatum key; |
169 | chashdatum data; | 169 | chashdatum data; |
170 | struct mailmh_folder * folder; | 170 | struct mailmh_folder * folder; |
171 | 171 | ||
172 | folder = get_mh_cur_folder(msg_info); | 172 | folder = get_mh_cur_folder(msg_info); |
173 | 173 | ||
174 | key.data = &msg_info->msg_index; | 174 | key.data = &msg_info->msg_index; |
175 | key.len = sizeof(msg_info->msg_index); | 175 | key.len = sizeof(msg_info->msg_index); |
176 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 176 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
177 | if (r < 0) | 177 | if (r < 0) |
178 | return MAIL_ERROR_INVAL; | 178 | return MAIL_ERROR_INVAL; |
179 | 179 | ||
180 | mh_msg_info = data.data; | 180 | mh_msg_info = data.data; |
181 | 181 | ||
182 | snprintf(static_uid, PATH_MAX, "%u-%lu-%u", msg_info->msg_index, | 182 | snprintf(static_uid, PATH_MAX, "%u-%lu-%lu", msg_info->msg_index, |
183 | mh_msg_info->msg_mtime, mh_msg_info->msg_size); | 183 | mh_msg_info->msg_mtime, (unsigned long) mh_msg_info->msg_size); |
184 | uid = strdup(static_uid); | 184 | uid = strdup(static_uid); |
185 | if (uid == NULL) | 185 | if (uid == NULL) |
186 | return MAIL_ERROR_MEMORY; | 186 | return MAIL_ERROR_MEMORY; |
187 | 187 | ||
188 | r = mailmessage_generic_initialize(msg_info); | 188 | r = mailmessage_generic_initialize(msg_info); |
189 | if (r != MAIL_NO_ERROR) { | 189 | if (r != MAIL_NO_ERROR) { |
190 | free(uid); | 190 | free(uid); |
191 | return r; | 191 | return r; |
192 | } | 192 | } |
193 | 193 | ||
194 | msg = msg_info->msg_data; | 194 | msg = msg_info->msg_data; |
195 | msg->msg_prefetch = mh_prefetch; | 195 | msg->msg_prefetch = mh_prefetch; |
196 | msg->msg_prefetch_free = mh_prefetch_free; | 196 | msg->msg_prefetch_free = mh_prefetch_free; |
197 | msg_info->msg_uid = uid; | 197 | msg_info->msg_uid = uid; |
198 | 198 | ||
199 | return MAIL_NO_ERROR; | 199 | return MAIL_NO_ERROR; |
200 | } | 200 | } |
201 | 201 | ||
202 | static void mh_uninitialize(mailmessage * msg_info) | 202 | static void mh_uninitialize(mailmessage * msg_info) |
203 | { | 203 | { |
204 | mailmessage_generic_uninitialize(msg_info); | 204 | mailmessage_generic_uninitialize(msg_info); |
205 | } | 205 | } |
206 | 206 | ||
207 | 207 | ||
208 | #define FLAGS_NAME "flags.db" | 208 | #define FLAGS_NAME "flags.db" |
209 | 209 | ||
210 | static void mh_flush(mailmessage * msg_info) | 210 | static void mh_flush(mailmessage * msg_info) |
211 | { | 211 | { |
212 | mailmessage_generic_flush(msg_info); | 212 | mailmessage_generic_flush(msg_info); |
213 | } | 213 | } |
214 | 214 | ||
215 | static void mh_check(mailmessage * msg_info) | 215 | static void mh_check(mailmessage * msg_info) |
diff --git a/kmicromail/libetpan/generic/mhdriver_message.c b/kmicromail/libetpan/generic/mhdriver_message.c index 2c023e7..aafd2d9 100644 --- a/kmicromail/libetpan/generic/mhdriver_message.c +++ b/kmicromail/libetpan/generic/mhdriver_message.c | |||
@@ -115,66 +115,67 @@ static void mh_prefetch_free(struct generic_message_t * msg) | |||
115 | msg->msg_message = NULL; | 115 | msg->msg_message = NULL; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | static inline struct mh_session_state_data * get_data(mailmessage * msg) | 119 | static inline struct mh_session_state_data * get_data(mailmessage * msg) |
120 | { | 120 | { |
121 | return msg->msg_session->sess_data; | 121 | return msg->msg_session->sess_data; |
122 | } | 122 | } |
123 | 123 | ||
124 | static inline struct mailmh_folder * get_mh_cur_folder(mailmessage * msg) | 124 | static inline struct mailmh_folder * get_mh_cur_folder(mailmessage * msg) |
125 | { | 125 | { |
126 | return get_data(msg)->mh_cur_folder; | 126 | return get_data(msg)->mh_cur_folder; |
127 | } | 127 | } |
128 | 128 | ||
129 | static int mh_initialize(mailmessage * msg_info) | 129 | static int mh_initialize(mailmessage * msg_info) |
130 | { | 130 | { |
131 | struct generic_message_t * msg; | 131 | struct generic_message_t * msg; |
132 | int r; | 132 | int r; |
133 | char * uid; | 133 | char * uid; |
134 | char static_uid[PATH_MAX]; | 134 | char static_uid[PATH_MAX]; |
135 | struct mailmh_msg_info * mh_msg_info; | 135 | struct mailmh_msg_info * mh_msg_info; |
136 | chashdatum key; | 136 | chashdatum key; |
137 | chashdatum value; | 137 | chashdatum value; |
138 | 138 | ||
139 | key.data = &msg_info->msg_index; | 139 | key.data = &msg_info->msg_index; |
140 | key.len = sizeof(msg_info->msg_index); | 140 | key.len = sizeof(msg_info->msg_index); |
141 | r = chash_get(get_mh_cur_folder(msg_info)->fl_msgs_hash, &key, &value); | 141 | r = chash_get(get_mh_cur_folder(msg_info)->fl_msgs_hash, &key, &value); |
142 | if (r < 0) | 142 | if (r < 0) |
143 | return MAIL_ERROR_INVAL; | 143 | return MAIL_ERROR_INVAL; |
144 | 144 | ||
145 | mh_msg_info = value.data; | 145 | mh_msg_info = value.data; |
146 | 146 | ||
147 | snprintf(static_uid, PATH_MAX, "%u-%lu-%u", msg_info->msg_index, | 147 | snprintf(static_uid, PATH_MAX, "%u-%lu-%lu", msg_info->msg_index, |
148 | mh_msg_info->msg_mtime, mh_msg_info->msg_size); | 148 | (unsigned long) mh_msg_info->msg_mtime, |
149 | (unsigned long) mh_msg_info->msg_size); | ||
149 | uid = strdup(static_uid); | 150 | uid = strdup(static_uid); |
150 | if (uid == NULL) | 151 | if (uid == NULL) |
151 | return MAIL_ERROR_MEMORY; | 152 | return MAIL_ERROR_MEMORY; |
152 | 153 | ||
153 | r = mailmessage_generic_initialize(msg_info); | 154 | r = mailmessage_generic_initialize(msg_info); |
154 | if (r != MAIL_NO_ERROR) { | 155 | if (r != MAIL_NO_ERROR) { |
155 | free(uid); | 156 | free(uid); |
156 | return r; | 157 | return r; |
157 | } | 158 | } |
158 | 159 | ||
159 | msg = msg_info->msg_data; | 160 | msg = msg_info->msg_data; |
160 | msg->msg_prefetch = mh_prefetch; | 161 | msg->msg_prefetch = mh_prefetch; |
161 | msg->msg_prefetch_free = mh_prefetch_free; | 162 | msg->msg_prefetch_free = mh_prefetch_free; |
162 | msg_info->msg_uid = uid; | 163 | msg_info->msg_uid = uid; |
163 | 164 | ||
164 | return MAIL_NO_ERROR; | 165 | return MAIL_NO_ERROR; |
165 | } | 166 | } |
166 | 167 | ||
167 | 168 | ||
168 | static int mh_fetch_size(mailmessage * msg_info, | 169 | static int mh_fetch_size(mailmessage * msg_info, |
169 | size_t * result) | 170 | size_t * result) |
170 | { | 171 | { |
171 | int r; | 172 | int r; |
172 | size_t size; | 173 | size_t size; |
173 | 174 | ||
174 | r = mhdriver_fetch_size(msg_info->msg_session, msg_info->msg_index, &size); | 175 | r = mhdriver_fetch_size(msg_info->msg_session, msg_info->msg_index, &size); |
175 | if (r != MAIL_NO_ERROR) | 176 | if (r != MAIL_NO_ERROR) |
176 | return r; | 177 | return r; |
177 | 178 | ||
178 | * result = size; | 179 | * result = size; |
179 | 180 | ||
180 | return MAIL_NO_ERROR; | 181 | return MAIL_NO_ERROR; |
diff --git a/kmicromail/libetpan/generic/mhdriver_tools.c b/kmicromail/libetpan/generic/mhdriver_tools.c index cb863fa..c15bb6d 100644 --- a/kmicromail/libetpan/generic/mhdriver_tools.c +++ b/kmicromail/libetpan/generic/mhdriver_tools.c | |||
@@ -340,66 +340,67 @@ int mhdriver_fetch_size(mailsession * session, uint32_t index, | |||
340 | return MAIL_NO_ERROR; | 340 | return MAIL_NO_ERROR; |
341 | } | 341 | } |
342 | 342 | ||
343 | int | 343 | int |
344 | mhdriver_get_cached_flags(struct mail_cache_db * cache_db, | 344 | mhdriver_get_cached_flags(struct mail_cache_db * cache_db, |
345 | MMAPString * mmapstr, | 345 | MMAPString * mmapstr, |
346 | mailsession * session, | 346 | mailsession * session, |
347 | uint32_t num, | 347 | uint32_t num, |
348 | struct mail_flags ** result) | 348 | struct mail_flags ** result) |
349 | { | 349 | { |
350 | int r; | 350 | int r; |
351 | char keyname[PATH_MAX]; | 351 | char keyname[PATH_MAX]; |
352 | struct mail_flags * flags; | 352 | struct mail_flags * flags; |
353 | int res; | 353 | int res; |
354 | struct mailmh_msg_info * msg_info; | 354 | struct mailmh_msg_info * msg_info; |
355 | chashdatum key; | 355 | chashdatum key; |
356 | chashdatum data; | 356 | chashdatum data; |
357 | struct mailmh_folder * folder; | 357 | struct mailmh_folder * folder; |
358 | 358 | ||
359 | folder = cached_get_mh_cur_folder(session); | 359 | folder = cached_get_mh_cur_folder(session); |
360 | #if 0 | 360 | #if 0 |
361 | msg_info = cinthash_find(mh_data->cur_folder->fl_msgs_hash, num); | 361 | msg_info = cinthash_find(mh_data->cur_folder->fl_msgs_hash, num); |
362 | if (msg_info == NULL) | 362 | if (msg_info == NULL) |
363 | return MAIL_ERROR_CACHE_MISS; | 363 | return MAIL_ERROR_CACHE_MISS; |
364 | #endif | 364 | #endif |
365 | key.data = # | 365 | key.data = # |
366 | key.len = sizeof(num); | 366 | key.len = sizeof(num); |
367 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 367 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
368 | if (r < 0) | 368 | if (r < 0) |
369 | return MAIL_ERROR_CACHE_MISS; | 369 | return MAIL_ERROR_CACHE_MISS; |
370 | msg_info = data.data; | 370 | msg_info = data.data; |
371 | 371 | ||
372 | snprintf(keyname, PATH_MAX, "%u-%u-%u-flags", | 372 | snprintf(keyname, PATH_MAX, "%u-%lu-%lu-flags", |
373 | num, (uint32_t) msg_info->msg_mtime, msg_info->msg_size); | 373 | num, (unsigned long) msg_info->msg_mtime, |
374 | (unsigned long) msg_info->msg_size); | ||
374 | 375 | ||
375 | r = generic_cache_flags_read(cache_db, mmapstr, keyname, &flags); | 376 | r = generic_cache_flags_read(cache_db, mmapstr, keyname, &flags); |
376 | if (r != MAIL_NO_ERROR) { | 377 | if (r != MAIL_NO_ERROR) { |
377 | res = r; | 378 | res = r; |
378 | goto err; | 379 | goto err; |
379 | } | 380 | } |
380 | 381 | ||
381 | * result = flags; | 382 | * result = flags; |
382 | 383 | ||
383 | return MAIL_NO_ERROR; | 384 | return MAIL_NO_ERROR; |
384 | 385 | ||
385 | err: | 386 | err: |
386 | return res; | 387 | return res; |
387 | } | 388 | } |
388 | 389 | ||
389 | int | 390 | int |
390 | mhdriver_write_cached_flags(struct mail_cache_db * cache_db, | 391 | mhdriver_write_cached_flags(struct mail_cache_db * cache_db, |
391 | MMAPString * mmapstr, | 392 | MMAPString * mmapstr, |
392 | char * uid, | 393 | char * uid, |
393 | struct mail_flags * flags) | 394 | struct mail_flags * flags) |
394 | { | 395 | { |
395 | int r; | 396 | int r; |
396 | char keyname[PATH_MAX]; | 397 | char keyname[PATH_MAX]; |
397 | int res; | 398 | int res; |
398 | 399 | ||
399 | snprintf(keyname, PATH_MAX, "%s-flags", uid); | 400 | snprintf(keyname, PATH_MAX, "%s-flags", uid); |
400 | 401 | ||
401 | r = generic_cache_flags_write(cache_db, mmapstr, keyname, flags); | 402 | r = generic_cache_flags_write(cache_db, mmapstr, keyname, flags); |
402 | if (r != MAIL_NO_ERROR) { | 403 | if (r != MAIL_NO_ERROR) { |
403 | res = r; | 404 | res = r; |
404 | goto err; | 405 | goto err; |
405 | } | 406 | } |
diff --git a/kmicromail/libetpan/generic/mhstorage.c b/kmicromail/libetpan/generic/mhstorage.c index 32fc26b..715b961 100644 --- a/kmicromail/libetpan/generic/mhstorage.c +++ b/kmicromail/libetpan/generic/mhstorage.c | |||
@@ -33,65 +33,65 @@ | |||
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "mhstorage.h" | 36 | #include "mhstorage.h" |
37 | 37 | ||
38 | #include "mhdriver.h" | 38 | #include "mhdriver.h" |
39 | #include "mhdriver_cached.h" | 39 | #include "mhdriver_cached.h" |
40 | #include "mail.h" | 40 | #include "mail.h" |
41 | 41 | ||
42 | #include <stdlib.h> | 42 | #include <stdlib.h> |
43 | #include <string.h> | 43 | #include <string.h> |
44 | 44 | ||
45 | /* mh storage */ | 45 | /* mh storage */ |
46 | 46 | ||
47 | static int mh_mailstorage_connect(struct mailstorage * storage); | 47 | static int mh_mailstorage_connect(struct mailstorage * storage); |
48 | static int mh_mailstorage_get_folder_session(struct mailstorage * storage, | 48 | static int mh_mailstorage_get_folder_session(struct mailstorage * storage, |
49 | char * pathname, mailsession ** result); | 49 | char * pathname, mailsession ** result); |
50 | static void mh_mailstorage_uninitialize(struct mailstorage * storage); | 50 | static void mh_mailstorage_uninitialize(struct mailstorage * storage); |
51 | 51 | ||
52 | static mailstorage_driver mh_mailstorage_driver = { | 52 | static mailstorage_driver mh_mailstorage_driver = { |
53 | .sto_name = "mh", | 53 | .sto_name = "mh", |
54 | .sto_connect = mh_mailstorage_connect, | 54 | .sto_connect = mh_mailstorage_connect, |
55 | .sto_get_folder_session = mh_mailstorage_get_folder_session, | 55 | .sto_get_folder_session = mh_mailstorage_get_folder_session, |
56 | .sto_uninitialize = mh_mailstorage_uninitialize, | 56 | .sto_uninitialize = mh_mailstorage_uninitialize, |
57 | }; | 57 | }; |
58 | 58 | ||
59 | int mh_mailstorage_init(struct mailstorage * storage, | 59 | int mh_mailstorage_init(struct mailstorage * storage, |
60 | char * mh_pathname, int mh_cached, | 60 | char * mh_pathname, int mh_cached, |
61 | char * mh_cache_directory, char * mh_flags_directory) | 61 | char * mh_cache_directory, char * mh_flags_directory) |
62 | { | 62 | { |
63 | struct mh_mailstorage * mh_storage; | 63 | struct mh_mailstorage * mh_storage; |
64 | 64 | ||
65 | mh_storage = malloc(sizeof(struct mh_mailstorage)); | 65 | mh_storage = malloc(sizeof(* mh_storage)); |
66 | if (mh_storage == NULL) | 66 | if (mh_storage == NULL) |
67 | goto err; | 67 | goto err; |
68 | 68 | ||
69 | mh_storage->mh_pathname = strdup(mh_pathname); | 69 | mh_storage->mh_pathname = strdup(mh_pathname); |
70 | if (mh_storage->mh_pathname == NULL) | 70 | if (mh_storage->mh_pathname == NULL) |
71 | goto free; | 71 | goto free; |
72 | 72 | ||
73 | mh_storage->mh_cached = mh_cached; | 73 | mh_storage->mh_cached = mh_cached; |
74 | 74 | ||
75 | if (mh_cached && (mh_cache_directory != NULL) && | 75 | if (mh_cached && (mh_cache_directory != NULL) && |
76 | (mh_flags_directory != NULL)) { | 76 | (mh_flags_directory != NULL)) { |
77 | mh_storage->mh_cache_directory = strdup(mh_cache_directory); | 77 | mh_storage->mh_cache_directory = strdup(mh_cache_directory); |
78 | if (mh_storage->mh_cache_directory == NULL) | 78 | if (mh_storage->mh_cache_directory == NULL) |
79 | goto free_pathname; | 79 | goto free_pathname; |
80 | mh_storage->mh_flags_directory = strdup(mh_flags_directory); | 80 | mh_storage->mh_flags_directory = strdup(mh_flags_directory); |
81 | if (mh_storage->mh_flags_directory == NULL) | 81 | if (mh_storage->mh_flags_directory == NULL) |
82 | goto free_cache_directory; | 82 | goto free_cache_directory; |
83 | } | 83 | } |
84 | else { | 84 | else { |
85 | mh_storage->mh_cached = FALSE; | 85 | mh_storage->mh_cached = FALSE; |
86 | mh_storage->mh_cache_directory = NULL; | 86 | mh_storage->mh_cache_directory = NULL; |
87 | mh_storage->mh_flags_directory = NULL; | 87 | mh_storage->mh_flags_directory = NULL; |
88 | } | 88 | } |
89 | 89 | ||
90 | storage->sto_data = mh_storage; | 90 | storage->sto_data = mh_storage; |
91 | storage->sto_driver = &mh_mailstorage_driver; | 91 | storage->sto_driver = &mh_mailstorage_driver; |
92 | 92 | ||
93 | return MAIL_NO_ERROR; | 93 | return MAIL_NO_ERROR; |
94 | 94 | ||
95 | free_cache_directory: | 95 | free_cache_directory: |
96 | free(mh_storage->mh_cache_directory); | 96 | free(mh_storage->mh_cache_directory); |
97 | free_pathname: | 97 | free_pathname: |
diff --git a/kmicromail/libetpan/generic/nntpdriver.c b/kmicromail/libetpan/generic/nntpdriver.c index fde5f1a..1b65838 100644 --- a/kmicromail/libetpan/generic/nntpdriver.c +++ b/kmicromail/libetpan/generic/nntpdriver.c | |||
@@ -40,124 +40,128 @@ | |||
40 | 40 | ||
41 | #include "mail.h" | 41 | #include "mail.h" |
42 | #include "mailmessage.h" | 42 | #include "mailmessage.h" |
43 | #include "nntpdriver_tools.h" | 43 | #include "nntpdriver_tools.h" |
44 | #include "maildriver_tools.h" | 44 | #include "maildriver_tools.h" |
45 | #include "nntpdriver_message.h" | 45 | #include "nntpdriver_message.h" |
46 | 46 | ||
47 | static int nntpdriver_initialize(mailsession * session); | 47 | static int nntpdriver_initialize(mailsession * session); |
48 | 48 | ||
49 | static void nntpdriver_uninitialize(mailsession * session); | 49 | static void nntpdriver_uninitialize(mailsession * session); |
50 | 50 | ||
51 | static int nntpdriver_parameters(mailsession * session, | 51 | static int nntpdriver_parameters(mailsession * session, |
52 | int id, void * value); | 52 | int id, void * value); |
53 | 53 | ||
54 | static int nntpdriver_connect_stream(mailsession * session, mailstream * s); | 54 | static int nntpdriver_connect_stream(mailsession * session, mailstream * s); |
55 | 55 | ||
56 | static int nntpdriver_login(mailsession * session, | 56 | static int nntpdriver_login(mailsession * session, |
57 | char * userid, char * password); | 57 | char * userid, char * password); |
58 | 58 | ||
59 | static int nntpdriver_logout(mailsession * session); | 59 | static int nntpdriver_logout(mailsession * session); |
60 | 60 | ||
61 | static int nntpdriver_status_folder(mailsession * session, char * mb, | 61 | static int nntpdriver_status_folder(mailsession * session, char * mb, |
62 | uint32_t * result_messages, | 62 | uint32_t * result_messages, |
63 | uint32_t * result_recent, | 63 | uint32_t * result_recent, |
64 | uint32_t * result_unseen); | 64 | uint32_t * result_unseen); |
65 | 65 | ||
66 | static int nntpdriver_messages_number(mailsession * session, char * mb, | 66 | static int nntpdriver_messages_number(mailsession * session, char * mb, |
67 | uint32_t * result); | 67 | uint32_t * result); |
68 | 68 | ||
69 | static int nntpdriver_append_message(mailsession * session, | 69 | static int nntpdriver_append_message(mailsession * session, |
70 | char * message, size_t size); | 70 | char * message, size_t size); |
71 | 71 | ||
72 | static int nntpdriver_append_message_flags(mailsession * session, | ||
73 | char * message, size_t size, struct mail_flags * flags); | ||
74 | |||
72 | static int | 75 | static int |
73 | nntpdriver_get_envelopes_list(mailsession * session, | 76 | nntpdriver_get_envelopes_list(mailsession * session, |
74 | struct mailmessage_list * env_list); | 77 | struct mailmessage_list * env_list); |
75 | 78 | ||
76 | 79 | ||
77 | static int nntpdriver_get_messages_list(mailsession * session, | 80 | static int nntpdriver_get_messages_list(mailsession * session, |
78 | struct mailmessage_list ** result); | 81 | struct mailmessage_list ** result); |
79 | 82 | ||
80 | static int nntpdriver_list_folders(mailsession * session, char * mb, | 83 | static int nntpdriver_list_folders(mailsession * session, char * mb, |
81 | struct mail_list ** result); | 84 | struct mail_list ** result); |
82 | 85 | ||
83 | static int nntpdriver_lsub_folders(mailsession * session, char * mb, | 86 | static int nntpdriver_lsub_folders(mailsession * session, char * mb, |
84 | struct mail_list ** result); | 87 | struct mail_list ** result); |
85 | 88 | ||
86 | static int nntpdriver_subscribe_folder(mailsession * session, char * mb); | 89 | static int nntpdriver_subscribe_folder(mailsession * session, char * mb); |
87 | 90 | ||
88 | static int nntpdriver_unsubscribe_folder(mailsession * session, char * mb); | 91 | static int nntpdriver_unsubscribe_folder(mailsession * session, char * mb); |
89 | 92 | ||
90 | static int nntpdriver_get_message(mailsession * session, | 93 | static int nntpdriver_get_message(mailsession * session, |
91 | uint32_t num, mailmessage ** result); | 94 | uint32_t num, mailmessage ** result); |
92 | 95 | ||
93 | static int nntpdriver_get_message_by_uid(mailsession * session, | 96 | static int nntpdriver_get_message_by_uid(mailsession * session, |
94 | const char * uid, | 97 | const char * uid, |
95 | mailmessage ** result); | 98 | mailmessage ** result); |
96 | 99 | ||
97 | static int nntpdriver_noop(mailsession * session); | 100 | static int nntpdriver_noop(mailsession * session); |
98 | 101 | ||
99 | static mailsession_driver local_nntp_session_driver = { | 102 | static mailsession_driver local_nntp_session_driver = { |
100 | .sess_name = "nntp", | 103 | .sess_name = "nntp", |
101 | 104 | ||
102 | .sess_initialize = nntpdriver_initialize, | 105 | .sess_initialize = nntpdriver_initialize, |
103 | .sess_uninitialize = nntpdriver_uninitialize, | 106 | .sess_uninitialize = nntpdriver_uninitialize, |
104 | 107 | ||
105 | .sess_parameters = nntpdriver_parameters, | 108 | .sess_parameters = nntpdriver_parameters, |
106 | 109 | ||
107 | .sess_connect_stream = nntpdriver_connect_stream, | 110 | .sess_connect_stream = nntpdriver_connect_stream, |
108 | .sess_connect_path = NULL, | 111 | .sess_connect_path = NULL, |
109 | .sess_starttls = NULL, | 112 | .sess_starttls = NULL, |
110 | .sess_login = nntpdriver_login, | 113 | .sess_login = nntpdriver_login, |
111 | .sess_logout = nntpdriver_logout, | 114 | .sess_logout = nntpdriver_logout, |
112 | .sess_noop = nntpdriver_noop, | 115 | .sess_noop = nntpdriver_noop, |
113 | 116 | ||
114 | .sess_build_folder_name = NULL, | 117 | .sess_build_folder_name = NULL, |
115 | .sess_create_folder = NULL, | 118 | .sess_create_folder = NULL, |
116 | .sess_delete_folder = NULL, | 119 | .sess_delete_folder = NULL, |
117 | .sess_rename_folder = NULL, | 120 | .sess_rename_folder = NULL, |
118 | .sess_check_folder = NULL, | 121 | .sess_check_folder = NULL, |
119 | .sess_examine_folder = NULL, | 122 | .sess_examine_folder = NULL, |
120 | .sess_select_folder = nntpdriver_select_folder, | 123 | .sess_select_folder = nntpdriver_select_folder, |
121 | .sess_expunge_folder = NULL, | 124 | .sess_expunge_folder = NULL, |
122 | .sess_status_folder = nntpdriver_status_folder, | 125 | .sess_status_folder = nntpdriver_status_folder, |
123 | .sess_messages_number = nntpdriver_messages_number, | 126 | .sess_messages_number = nntpdriver_messages_number, |
124 | .sess_recent_number = nntpdriver_messages_number, | 127 | .sess_recent_number = nntpdriver_messages_number, |
125 | .sess_unseen_number = nntpdriver_messages_number, | 128 | .sess_unseen_number = nntpdriver_messages_number, |
126 | .sess_list_folders = nntpdriver_list_folders, | 129 | .sess_list_folders = nntpdriver_list_folders, |
127 | .sess_lsub_folders = nntpdriver_lsub_folders, | 130 | .sess_lsub_folders = nntpdriver_lsub_folders, |
128 | .sess_subscribe_folder = nntpdriver_subscribe_folder, | 131 | .sess_subscribe_folder = nntpdriver_subscribe_folder, |
129 | .sess_unsubscribe_folder = nntpdriver_unsubscribe_folder, | 132 | .sess_unsubscribe_folder = nntpdriver_unsubscribe_folder, |
130 | 133 | ||
131 | .sess_append_message = nntpdriver_append_message, | 134 | .sess_append_message = nntpdriver_append_message, |
135 | .sess_append_message_flags = nntpdriver_append_message_flags, | ||
132 | .sess_copy_message = NULL, | 136 | .sess_copy_message = NULL, |
133 | .sess_move_message = NULL, | 137 | .sess_move_message = NULL, |
134 | 138 | ||
135 | .sess_get_messages_list = nntpdriver_get_messages_list, | 139 | .sess_get_messages_list = nntpdriver_get_messages_list, |
136 | .sess_get_envelopes_list = nntpdriver_get_envelopes_list, | 140 | .sess_get_envelopes_list = nntpdriver_get_envelopes_list, |
137 | .sess_remove_message = NULL, | 141 | .sess_remove_message = NULL, |
138 | #if 0 | 142 | #if 0 |
139 | .sess_search_messages = maildriver_generic_search_messages, | 143 | .sess_search_messages = maildriver_generic_search_messages, |
140 | #endif | 144 | #endif |
141 | 145 | ||
142 | .sess_get_message = nntpdriver_get_message, | 146 | .sess_get_message = nntpdriver_get_message, |
143 | .sess_get_message_by_uid = nntpdriver_get_message_by_uid, | 147 | .sess_get_message_by_uid = nntpdriver_get_message_by_uid, |
144 | }; | 148 | }; |
145 | 149 | ||
146 | 150 | ||
147 | mailsession_driver * nntp_session_driver = &local_nntp_session_driver; | 151 | mailsession_driver * nntp_session_driver = &local_nntp_session_driver; |
148 | 152 | ||
149 | static inline struct nntp_session_state_data * | 153 | static inline struct nntp_session_state_data * |
150 | get_data(mailsession * session) | 154 | get_data(mailsession * session) |
151 | { | 155 | { |
152 | return session->sess_data; | 156 | return session->sess_data; |
153 | } | 157 | } |
154 | 158 | ||
155 | static inline newsnntp * get_nntp_session(mailsession * session) | 159 | static inline newsnntp * get_nntp_session(mailsession * session) |
156 | { | 160 | { |
157 | return get_data(session)->nntp_session; | 161 | return get_data(session)->nntp_session; |
158 | } | 162 | } |
159 | 163 | ||
160 | static int nntpdriver_initialize(mailsession * session) | 164 | static int nntpdriver_initialize(mailsession * session) |
161 | { | 165 | { |
162 | struct nntp_session_state_data * data; | 166 | struct nntp_session_state_data * data; |
163 | newsnntp * nntp; | 167 | newsnntp * nntp; |
@@ -601,64 +605,70 @@ static int nntpdriver_unsubscribe_folder(mailsession * session, char * mb) | |||
601 | /* messages operations */ | 605 | /* messages operations */ |
602 | 606 | ||
603 | static int nntpdriver_append_message(mailsession * session, | 607 | static int nntpdriver_append_message(mailsession * session, |
604 | char * message, size_t size) | 608 | char * message, size_t size) |
605 | { | 609 | { |
606 | int r; | 610 | int r; |
607 | struct nntp_session_state_data * data; | 611 | struct nntp_session_state_data * data; |
608 | 612 | ||
609 | data = get_data(session); | 613 | data = get_data(session); |
610 | 614 | ||
611 | do { | 615 | do { |
612 | r = newsnntp_post(get_nntp_session(session), message, size); | 616 | r = newsnntp_post(get_nntp_session(session), message, size); |
613 | switch (r) { | 617 | switch (r) { |
614 | case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_USERNAME: | 618 | case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_USERNAME: |
615 | r = nntpdriver_authenticate_user(session); | 619 | r = nntpdriver_authenticate_user(session); |
616 | if (r != MAIL_NO_ERROR) | 620 | if (r != MAIL_NO_ERROR) |
617 | return r; | 621 | return r; |
618 | break; | 622 | break; |
619 | 623 | ||
620 | case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD: | 624 | case NEWSNNTP_WARNING_REQUEST_AUTHORIZATION_PASSWORD: |
621 | r = nntpdriver_authenticate_password(session); | 625 | r = nntpdriver_authenticate_password(session); |
622 | if (r != MAIL_NO_ERROR) | 626 | if (r != MAIL_NO_ERROR) |
623 | return r; | 627 | return r; |
624 | break; | 628 | break; |
625 | 629 | ||
626 | default: | 630 | default: |
627 | return nntpdriver_nntp_error_to_mail_error(r); | 631 | return nntpdriver_nntp_error_to_mail_error(r); |
628 | } | 632 | } |
629 | } | 633 | } |
630 | while (1); | 634 | while (1); |
631 | } | 635 | } |
632 | 636 | ||
637 | static int nntpdriver_append_message_flags(mailsession * session, | ||
638 | char * message, size_t size, struct mail_flags * flags) | ||
639 | { | ||
640 | return nntpdriver_append_message(session, message, size); | ||
641 | } | ||
642 | |||
633 | 643 | ||
634 | static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, | 644 | static int xover_resp_to_fields(struct newsnntp_xover_resp_item * item, |
635 | struct mailimf_fields ** result); | 645 | struct mailimf_fields ** result); |
636 | 646 | ||
637 | 647 | ||
638 | static int | 648 | static int |
639 | nntpdriver_get_envelopes_list(mailsession * session, | 649 | nntpdriver_get_envelopes_list(mailsession * session, |
640 | struct mailmessage_list * env_list) | 650 | struct mailmessage_list * env_list) |
641 | { | 651 | { |
642 | newsnntp * nntp; | 652 | newsnntp * nntp; |
643 | int r; | 653 | int r; |
644 | struct nntp_session_state_data * data; | 654 | struct nntp_session_state_data * data; |
645 | clist * list; | 655 | clist * list; |
646 | int done; | 656 | int done; |
647 | clistiter * cur; | 657 | clistiter * cur; |
648 | uint32_t first_seq; | 658 | uint32_t first_seq; |
649 | unsigned int i; | 659 | unsigned int i; |
650 | 660 | ||
651 | nntp = get_nntp_session(session); | 661 | nntp = get_nntp_session(session); |
652 | 662 | ||
653 | data = get_data(session); | 663 | data = get_data(session); |
654 | 664 | ||
655 | if (data->nntp_group_info == NULL) | 665 | if (data->nntp_group_info == NULL) |
656 | return MAIL_ERROR_BAD_STATE; | 666 | return MAIL_ERROR_BAD_STATE; |
657 | 667 | ||
658 | first_seq = data->nntp_group_info->grp_first; | 668 | first_seq = data->nntp_group_info->grp_first; |
659 | 669 | ||
660 | if (carray_count(env_list->msg_tab) > 0) { | 670 | if (carray_count(env_list->msg_tab) > 0) { |
661 | mailmessage * msg; | 671 | mailmessage * msg; |
662 | 672 | ||
663 | msg = carray_get(env_list->msg_tab, 0); | 673 | msg = carray_get(env_list->msg_tab, 0); |
664 | 674 | ||
diff --git a/kmicromail/libetpan/generic/nntpdriver_cached.c b/kmicromail/libetpan/generic/nntpdriver_cached.c index 1f8a8af..0343a65 100644 --- a/kmicromail/libetpan/generic/nntpdriver_cached.c +++ b/kmicromail/libetpan/generic/nntpdriver_cached.c | |||
@@ -67,127 +67,131 @@ static int nntpdriver_cached_parameters(mailsession * session, | |||
67 | int id, void * value); | 67 | int id, void * value); |
68 | 68 | ||
69 | static int nntpdriver_cached_connect_stream(mailsession * session, | 69 | static int nntpdriver_cached_connect_stream(mailsession * session, |
70 | mailstream * s); | 70 | mailstream * s); |
71 | 71 | ||
72 | static int nntpdriver_cached_login(mailsession * session, | 72 | static int nntpdriver_cached_login(mailsession * session, |
73 | char * userid, char * password); | 73 | char * userid, char * password); |
74 | 74 | ||
75 | static int nntpdriver_cached_logout(mailsession * session); | 75 | static int nntpdriver_cached_logout(mailsession * session); |
76 | 76 | ||
77 | static int nntpdriver_cached_check_folder(mailsession * session); | 77 | static int nntpdriver_cached_check_folder(mailsession * session); |
78 | 78 | ||
79 | static int nntpdriver_cached_select_folder(mailsession * session, char * mb); | 79 | static int nntpdriver_cached_select_folder(mailsession * session, char * mb); |
80 | 80 | ||
81 | static int nntpdriver_cached_status_folder(mailsession * session, | 81 | static int nntpdriver_cached_status_folder(mailsession * session, |
82 | char * mb, | 82 | char * mb, |
83 | uint32_t * result_messages, | 83 | uint32_t * result_messages, |
84 | uint32_t * result_recent, | 84 | uint32_t * result_recent, |
85 | uint32_t * result_unseen); | 85 | uint32_t * result_unseen); |
86 | 86 | ||
87 | static int nntpdriver_cached_messages_number(mailsession * session, char * mb, | 87 | static int nntpdriver_cached_messages_number(mailsession * session, char * mb, |
88 | uint32_t * result); | 88 | uint32_t * result); |
89 | 89 | ||
90 | static int nntpdriver_cached_recent_number(mailsession * session, char * mb, | 90 | static int nntpdriver_cached_recent_number(mailsession * session, char * mb, |
91 | uint32_t * result); | 91 | uint32_t * result); |
92 | 92 | ||
93 | static int nntpdriver_cached_unseen_number(mailsession * session, char * mb, | 93 | static int nntpdriver_cached_unseen_number(mailsession * session, char * mb, |
94 | uint32_t * result); | 94 | uint32_t * result); |
95 | 95 | ||
96 | static int nntpdriver_cached_append_message(mailsession * session, | 96 | static int nntpdriver_cached_append_message(mailsession * session, |
97 | char * message, size_t size); | 97 | char * message, size_t size); |
98 | 98 | ||
99 | static int nntpdriver_cached_append_message_flags(mailsession * session, | ||
100 | char * message, size_t size, struct mail_flags * flags); | ||
101 | |||
99 | static int | 102 | static int |
100 | nntpdriver_cached_get_envelopes_list(mailsession * session, | 103 | nntpdriver_cached_get_envelopes_list(mailsession * session, |
101 | struct mailmessage_list * env_list); | 104 | struct mailmessage_list * env_list); |
102 | 105 | ||
103 | 106 | ||
104 | static int | 107 | static int |
105 | nntpdriver_cached_get_messages_list(mailsession * session, | 108 | nntpdriver_cached_get_messages_list(mailsession * session, |
106 | struct mailmessage_list ** result); | 109 | struct mailmessage_list ** result); |
107 | 110 | ||
108 | static int nntpdriver_cached_list_folders(mailsession * session, char * mb, | 111 | static int nntpdriver_cached_list_folders(mailsession * session, char * mb, |
109 | struct mail_list ** result); | 112 | struct mail_list ** result); |
110 | 113 | ||
111 | static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb, | 114 | static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb, |
112 | struct mail_list ** result); | 115 | struct mail_list ** result); |
113 | 116 | ||
114 | static int nntpdriver_cached_subscribe_folder(mailsession * session, | 117 | static int nntpdriver_cached_subscribe_folder(mailsession * session, |
115 | char * mb); | 118 | char * mb); |
116 | 119 | ||
117 | static int nntpdriver_cached_unsubscribe_folder(mailsession * session, | 120 | static int nntpdriver_cached_unsubscribe_folder(mailsession * session, |
118 | char * mb); | 121 | char * mb); |
119 | 122 | ||
120 | static int nntpdriver_cached_get_message(mailsession * session, | 123 | static int nntpdriver_cached_get_message(mailsession * session, |
121 | uint32_t num, mailmessage ** result); | 124 | uint32_t num, mailmessage ** result); |
122 | 125 | ||
123 | static int nntpdriver_cached_noop(mailsession * session); | 126 | static int nntpdriver_cached_noop(mailsession * session); |
124 | 127 | ||
125 | static int nntpdriver_cached_get_message_by_uid(mailsession * session, | 128 | static int nntpdriver_cached_get_message_by_uid(mailsession * session, |
126 | const char * uid, | 129 | const char * uid, |
127 | mailmessage ** result); | 130 | mailmessage ** result); |
128 | 131 | ||
129 | static mailsession_driver local_nntp_cached_session_driver = { | 132 | static mailsession_driver local_nntp_cached_session_driver = { |
130 | .sess_name = "nntp-cached", | 133 | .sess_name = "nntp-cached", |
131 | 134 | ||
132 | .sess_initialize = nntpdriver_cached_initialize, | 135 | .sess_initialize = nntpdriver_cached_initialize, |
133 | .sess_uninitialize = nntpdriver_cached_uninitialize, | 136 | .sess_uninitialize = nntpdriver_cached_uninitialize, |
134 | 137 | ||
135 | .sess_parameters = nntpdriver_cached_parameters, | 138 | .sess_parameters = nntpdriver_cached_parameters, |
136 | 139 | ||
137 | .sess_connect_stream = nntpdriver_cached_connect_stream, | 140 | .sess_connect_stream = nntpdriver_cached_connect_stream, |
138 | .sess_connect_path = NULL, | 141 | .sess_connect_path = NULL, |
139 | .sess_starttls = NULL, | 142 | .sess_starttls = NULL, |
140 | .sess_login = nntpdriver_cached_login, | 143 | .sess_login = nntpdriver_cached_login, |
141 | .sess_logout = nntpdriver_cached_logout, | 144 | .sess_logout = nntpdriver_cached_logout, |
142 | .sess_noop = nntpdriver_cached_noop, | 145 | .sess_noop = nntpdriver_cached_noop, |
143 | 146 | ||
144 | .sess_build_folder_name = NULL, | 147 | .sess_build_folder_name = NULL, |
145 | .sess_create_folder = NULL, | 148 | .sess_create_folder = NULL, |
146 | .sess_delete_folder = NULL, | 149 | .sess_delete_folder = NULL, |
147 | .sess_rename_folder = NULL, | 150 | .sess_rename_folder = NULL, |
148 | .sess_check_folder = nntpdriver_cached_check_folder, | 151 | .sess_check_folder = nntpdriver_cached_check_folder, |
149 | .sess_examine_folder = NULL, | 152 | .sess_examine_folder = NULL, |
150 | .sess_select_folder = nntpdriver_cached_select_folder, | 153 | .sess_select_folder = nntpdriver_cached_select_folder, |
151 | .sess_expunge_folder = NULL, | 154 | .sess_expunge_folder = NULL, |
152 | .sess_status_folder = nntpdriver_cached_status_folder, | 155 | .sess_status_folder = nntpdriver_cached_status_folder, |
153 | .sess_messages_number = nntpdriver_cached_messages_number, | 156 | .sess_messages_number = nntpdriver_cached_messages_number, |
154 | .sess_recent_number = nntpdriver_cached_recent_number, | 157 | .sess_recent_number = nntpdriver_cached_recent_number, |
155 | .sess_unseen_number = nntpdriver_cached_unseen_number, | 158 | .sess_unseen_number = nntpdriver_cached_unseen_number, |
156 | .sess_list_folders = nntpdriver_cached_list_folders, | 159 | .sess_list_folders = nntpdriver_cached_list_folders, |
157 | .sess_lsub_folders = nntpdriver_cached_lsub_folders, | 160 | .sess_lsub_folders = nntpdriver_cached_lsub_folders, |
158 | .sess_subscribe_folder = nntpdriver_cached_subscribe_folder, | 161 | .sess_subscribe_folder = nntpdriver_cached_subscribe_folder, |
159 | .sess_unsubscribe_folder = nntpdriver_cached_unsubscribe_folder, | 162 | .sess_unsubscribe_folder = nntpdriver_cached_unsubscribe_folder, |
160 | 163 | ||
161 | .sess_append_message = nntpdriver_cached_append_message, | 164 | .sess_append_message = nntpdriver_cached_append_message, |
165 | .sess_append_message_flags = nntpdriver_cached_append_message_flags, | ||
162 | .sess_copy_message = NULL, | 166 | .sess_copy_message = NULL, |
163 | .sess_move_message = NULL, | 167 | .sess_move_message = NULL, |
164 | 168 | ||
165 | .sess_get_messages_list = nntpdriver_cached_get_messages_list, | 169 | .sess_get_messages_list = nntpdriver_cached_get_messages_list, |
166 | .sess_get_envelopes_list = nntpdriver_cached_get_envelopes_list, | 170 | .sess_get_envelopes_list = nntpdriver_cached_get_envelopes_list, |
167 | .sess_remove_message = NULL, | 171 | .sess_remove_message = NULL, |
168 | #if 0 | 172 | #if 0 |
169 | .sess_search_messages = maildriver_generic_search_messages, | 173 | .sess_search_messages = maildriver_generic_search_messages, |
170 | #endif | 174 | #endif |
171 | 175 | ||
172 | .sess_get_message = nntpdriver_cached_get_message, | 176 | .sess_get_message = nntpdriver_cached_get_message, |
173 | .sess_get_message_by_uid = nntpdriver_cached_get_message_by_uid, | 177 | .sess_get_message_by_uid = nntpdriver_cached_get_message_by_uid, |
174 | }; | 178 | }; |
175 | 179 | ||
176 | 180 | ||
177 | mailsession_driver * nntp_cached_session_driver = | 181 | mailsession_driver * nntp_cached_session_driver = |
178 | &local_nntp_cached_session_driver; | 182 | &local_nntp_cached_session_driver; |
179 | 183 | ||
180 | #define ENV_NAME "env.db" | 184 | #define ENV_NAME "env.db" |
181 | #define FLAGS_NAME "flags.db" | 185 | #define FLAGS_NAME "flags.db" |
182 | 186 | ||
183 | 187 | ||
184 | 188 | ||
185 | static void read_article_seq(mailsession * session, | 189 | static void read_article_seq(mailsession * session, |
186 | uint32_t * pfirst, uint32_t * plast); | 190 | uint32_t * pfirst, uint32_t * plast); |
187 | 191 | ||
188 | static void write_article_seq(mailsession * session, | 192 | static void write_article_seq(mailsession * session, |
189 | uint32_t first, uint32_t last); | 193 | uint32_t first, uint32_t last); |
190 | 194 | ||
191 | 195 | ||
192 | static inline struct nntp_cached_session_state_data * | 196 | static inline struct nntp_cached_session_state_data * |
193 | get_cached_data(mailsession * session) | 197 | get_cached_data(mailsession * session) |
@@ -602,64 +606,70 @@ static int nntpdriver_cached_list_folders(mailsession * session, char * mb, | |||
602 | { | 606 | { |
603 | return mailsession_list_folders(get_ancestor(session), mb, result); | 607 | return mailsession_list_folders(get_ancestor(session), mb, result); |
604 | } | 608 | } |
605 | 609 | ||
606 | static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb, | 610 | static int nntpdriver_cached_lsub_folders(mailsession * session, char * mb, |
607 | struct mail_list ** result) | 611 | struct mail_list ** result) |
608 | { | 612 | { |
609 | return mailsession_lsub_folders(get_ancestor(session), mb, result); | 613 | return mailsession_lsub_folders(get_ancestor(session), mb, result); |
610 | } | 614 | } |
611 | 615 | ||
612 | static int nntpdriver_cached_subscribe_folder(mailsession * session, | 616 | static int nntpdriver_cached_subscribe_folder(mailsession * session, |
613 | char * mb) | 617 | char * mb) |
614 | { | 618 | { |
615 | return mailsession_subscribe_folder(get_ancestor(session), mb); | 619 | return mailsession_subscribe_folder(get_ancestor(session), mb); |
616 | } | 620 | } |
617 | 621 | ||
618 | static int nntpdriver_cached_unsubscribe_folder(mailsession * session, | 622 | static int nntpdriver_cached_unsubscribe_folder(mailsession * session, |
619 | char * mb) | 623 | char * mb) |
620 | { | 624 | { |
621 | return mailsession_unsubscribe_folder(get_ancestor(session), mb); | 625 | return mailsession_unsubscribe_folder(get_ancestor(session), mb); |
622 | } | 626 | } |
623 | 627 | ||
624 | 628 | ||
625 | 629 | ||
626 | /* messages operations */ | 630 | /* messages operations */ |
627 | 631 | ||
628 | static int nntpdriver_cached_append_message(mailsession * session, | 632 | static int nntpdriver_cached_append_message(mailsession * session, |
629 | char * message, size_t size) | 633 | char * message, size_t size) |
630 | { | 634 | { |
631 | return mailsession_append_message(get_ancestor(session), message, size); | 635 | return mailsession_append_message(get_ancestor(session), message, size); |
632 | } | 636 | } |
633 | 637 | ||
638 | static int nntpdriver_cached_append_message_flags(mailsession * session, | ||
639 | char * message, size_t size, struct mail_flags * flags) | ||
640 | { | ||
641 | return nntpdriver_cached_append_message(session, message, size); | ||
642 | } | ||
643 | |||
634 | 644 | ||
635 | 645 | ||
636 | static int | 646 | static int |
637 | get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | 647 | get_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, |
638 | mailsession * session, uint32_t num, | 648 | mailsession * session, uint32_t num, |
639 | struct mailimf_fields ** result) | 649 | struct mailimf_fields ** result) |
640 | { | 650 | { |
641 | char keyname[PATH_MAX]; | 651 | char keyname[PATH_MAX]; |
642 | int r; | 652 | int r; |
643 | struct mailimf_fields * fields; | 653 | struct mailimf_fields * fields; |
644 | int res; | 654 | int res; |
645 | 655 | ||
646 | snprintf(keyname, PATH_MAX, "%i-envelope", num); | 656 | snprintf(keyname, PATH_MAX, "%i-envelope", num); |
647 | 657 | ||
648 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); | 658 | r = generic_cache_fields_read(cache_db, mmapstr, keyname, &fields); |
649 | if (r != MAIL_NO_ERROR) { | 659 | if (r != MAIL_NO_ERROR) { |
650 | res = r; | 660 | res = r; |
651 | goto err; | 661 | goto err; |
652 | } | 662 | } |
653 | 663 | ||
654 | * result = fields; | 664 | * result = fields; |
655 | 665 | ||
656 | return MAIL_NO_ERROR; | 666 | return MAIL_NO_ERROR; |
657 | 667 | ||
658 | err: | 668 | err: |
659 | return res; | 669 | return res; |
660 | } | 670 | } |
661 | 671 | ||
662 | static int | 672 | static int |
663 | write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, | 673 | write_cached_envelope(struct mail_cache_db * cache_db, MMAPString * mmapstr, |
664 | mailsession * session, uint32_t num, | 674 | mailsession * session, uint32_t num, |
665 | struct mailimf_fields * fields) | 675 | struct mailimf_fields * fields) |
diff --git a/kmicromail/libetpan/generic/nntpstorage.c b/kmicromail/libetpan/generic/nntpstorage.c index 5ba333b..89974cd 100644 --- a/kmicromail/libetpan/generic/nntpstorage.c +++ b/kmicromail/libetpan/generic/nntpstorage.c | |||
@@ -42,65 +42,65 @@ | |||
42 | #include "nntpdriver.h" | 42 | #include "nntpdriver.h" |
43 | #include "nntpdriver_cached.h" | 43 | #include "nntpdriver_cached.h" |
44 | #include "mailstorage_tools.h" | 44 | #include "mailstorage_tools.h" |
45 | #include "mail.h" | 45 | #include "mail.h" |
46 | 46 | ||
47 | /* nntp storage */ | 47 | /* nntp storage */ |
48 | 48 | ||
49 | #define NNTP_DEFAULT_PORT 119 | 49 | #define NNTP_DEFAULT_PORT 119 |
50 | #define NNTPS_DEFAULT_PORT 563 | 50 | #define NNTPS_DEFAULT_PORT 563 |
51 | 51 | ||
52 | static int nntp_mailstorage_connect(struct mailstorage * storage); | 52 | static int nntp_mailstorage_connect(struct mailstorage * storage); |
53 | static int nntp_mailstorage_get_folder_session(struct mailstorage * storage, | 53 | static int nntp_mailstorage_get_folder_session(struct mailstorage * storage, |
54 | char * pathname, mailsession ** result); | 54 | char * pathname, mailsession ** result); |
55 | static void nntp_mailstorage_uninitialize(struct mailstorage * storage); | 55 | static void nntp_mailstorage_uninitialize(struct mailstorage * storage); |
56 | 56 | ||
57 | static mailstorage_driver nntp_mailstorage_driver = { | 57 | static mailstorage_driver nntp_mailstorage_driver = { |
58 | .sto_name = "nntp", | 58 | .sto_name = "nntp", |
59 | .sto_connect = nntp_mailstorage_connect, | 59 | .sto_connect = nntp_mailstorage_connect, |
60 | .sto_get_folder_session = nntp_mailstorage_get_folder_session, | 60 | .sto_get_folder_session = nntp_mailstorage_get_folder_session, |
61 | .sto_uninitialize = nntp_mailstorage_uninitialize, | 61 | .sto_uninitialize = nntp_mailstorage_uninitialize, |
62 | }; | 62 | }; |
63 | 63 | ||
64 | int nntp_mailstorage_init(struct mailstorage * storage, | 64 | int nntp_mailstorage_init(struct mailstorage * storage, |
65 | char * nn_servername, uint16_t nn_port, | 65 | char * nn_servername, uint16_t nn_port, |
66 | char * nn_command, | 66 | char * nn_command, |
67 | int nn_connection_type, int nn_auth_type, | 67 | int nn_connection_type, int nn_auth_type, |
68 | char * nn_login, char * nn_password, | 68 | char * nn_login, char * nn_password, |
69 | int nn_cached, char * nn_cache_directory, char * nn_flags_directory) | 69 | int nn_cached, char * nn_cache_directory, char * nn_flags_directory) |
70 | { | 70 | { |
71 | struct nntp_mailstorage * nntp_storage; | 71 | struct nntp_mailstorage * nntp_storage; |
72 | int res; | 72 | int res; |
73 | 73 | ||
74 | nntp_storage = malloc(sizeof(struct nntp_mailstorage)); | 74 | nntp_storage = malloc(sizeof(* nntp_storage)); |
75 | if (nntp_storage == NULL) { | 75 | if (nntp_storage == NULL) { |
76 | res = MAIL_ERROR_MEMORY; | 76 | res = MAIL_ERROR_MEMORY; |
77 | goto err; | 77 | goto err; |
78 | } | 78 | } |
79 | 79 | ||
80 | nntp_storage->nntp_servername = strdup(nn_servername); | 80 | nntp_storage->nntp_servername = strdup(nn_servername); |
81 | if (nntp_storage->nntp_servername == NULL) { | 81 | if (nntp_storage->nntp_servername == NULL) { |
82 | res = MAIL_ERROR_MEMORY; | 82 | res = MAIL_ERROR_MEMORY; |
83 | goto free; | 83 | goto free; |
84 | } | 84 | } |
85 | 85 | ||
86 | nntp_storage->nntp_connection_type = nn_connection_type; | 86 | nntp_storage->nntp_connection_type = nn_connection_type; |
87 | 87 | ||
88 | if (nn_port == 0) { | 88 | if (nn_port == 0) { |
89 | switch (nn_connection_type) { | 89 | switch (nn_connection_type) { |
90 | case CONNECTION_TYPE_PLAIN: | 90 | case CONNECTION_TYPE_PLAIN: |
91 | case CONNECTION_TYPE_COMMAND: | 91 | case CONNECTION_TYPE_COMMAND: |
92 | nn_port = NNTP_DEFAULT_PORT; | 92 | nn_port = NNTP_DEFAULT_PORT; |
93 | break; | 93 | break; |
94 | 94 | ||
95 | case CONNECTION_TYPE_TLS: | 95 | case CONNECTION_TYPE_TLS: |
96 | case CONNECTION_TYPE_COMMAND_TLS: | 96 | case CONNECTION_TYPE_COMMAND_TLS: |
97 | nn_port = NNTPS_DEFAULT_PORT; | 97 | nn_port = NNTPS_DEFAULT_PORT; |
98 | break; | 98 | break; |
99 | 99 | ||
100 | default: | 100 | default: |
101 | res = MAIL_ERROR_INVAL; | 101 | res = MAIL_ERROR_INVAL; |
102 | goto free_servername; | 102 | goto free_servername; |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | nntp_storage->nntp_port = nn_port; | 106 | nntp_storage->nntp_port = nn_port; |
diff --git a/kmicromail/libetpan/generic/pop3driver.c b/kmicromail/libetpan/generic/pop3driver.c index 20b0fc2..375879e 100644 --- a/kmicromail/libetpan/generic/pop3driver.c +++ b/kmicromail/libetpan/generic/pop3driver.c | |||
@@ -80,64 +80,65 @@ static mailsession_driver local_pop3_session_driver = { | |||
80 | .sess_name = "pop3", | 80 | .sess_name = "pop3", |
81 | 81 | ||
82 | .sess_initialize = pop3driver_initialize, | 82 | .sess_initialize = pop3driver_initialize, |
83 | .sess_uninitialize = pop3driver_uninitialize, | 83 | .sess_uninitialize = pop3driver_uninitialize, |
84 | 84 | ||
85 | .sess_parameters = pop3driver_parameters, | 85 | .sess_parameters = pop3driver_parameters, |
86 | 86 | ||
87 | .sess_connect_stream = pop3driver_connect_stream, | 87 | .sess_connect_stream = pop3driver_connect_stream, |
88 | .sess_connect_path = NULL, | 88 | .sess_connect_path = NULL, |
89 | .sess_starttls = pop3driver_starttls, | 89 | .sess_starttls = pop3driver_starttls, |
90 | .sess_login = pop3driver_login, | 90 | .sess_login = pop3driver_login, |
91 | .sess_logout = pop3driver_logout, | 91 | .sess_logout = pop3driver_logout, |
92 | .sess_noop = pop3driver_noop, | 92 | .sess_noop = pop3driver_noop, |
93 | 93 | ||
94 | .sess_build_folder_name = NULL, | 94 | .sess_build_folder_name = NULL, |
95 | .sess_create_folder = NULL, | 95 | .sess_create_folder = NULL, |
96 | .sess_delete_folder = NULL, | 96 | .sess_delete_folder = NULL, |
97 | .sess_rename_folder = NULL, | 97 | .sess_rename_folder = NULL, |
98 | .sess_check_folder = NULL, | 98 | .sess_check_folder = NULL, |
99 | .sess_examine_folder = NULL, | 99 | .sess_examine_folder = NULL, |
100 | .sess_select_folder = NULL, | 100 | .sess_select_folder = NULL, |
101 | .sess_expunge_folder = NULL, | 101 | .sess_expunge_folder = NULL, |
102 | .sess_status_folder = pop3driver_status_folder, | 102 | .sess_status_folder = pop3driver_status_folder, |
103 | .sess_messages_number = pop3driver_messages_number, | 103 | .sess_messages_number = pop3driver_messages_number, |
104 | .sess_recent_number = pop3driver_messages_number, | 104 | .sess_recent_number = pop3driver_messages_number, |
105 | .sess_unseen_number = pop3driver_messages_number, | 105 | .sess_unseen_number = pop3driver_messages_number, |
106 | .sess_list_folders = NULL, | 106 | .sess_list_folders = NULL, |
107 | .sess_lsub_folders = NULL, | 107 | .sess_lsub_folders = NULL, |
108 | .sess_subscribe_folder = NULL, | 108 | .sess_subscribe_folder = NULL, |
109 | .sess_unsubscribe_folder = NULL, | 109 | .sess_unsubscribe_folder = NULL, |
110 | 110 | ||
111 | .sess_append_message = NULL, | 111 | .sess_append_message = NULL, |
112 | .sess_append_message_flags = NULL, | ||
112 | .sess_copy_message = NULL, | 113 | .sess_copy_message = NULL, |
113 | .sess_move_message = NULL, | 114 | .sess_move_message = NULL, |
114 | 115 | ||
115 | .sess_get_messages_list = pop3driver_get_messages_list, | 116 | .sess_get_messages_list = pop3driver_get_messages_list, |
116 | .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, | 117 | .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, |
117 | .sess_remove_message = pop3driver_remove_message, | 118 | .sess_remove_message = pop3driver_remove_message, |
118 | #if 0 | 119 | #if 0 |
119 | .sess_search_messages = maildriver_generic_search_messages, | 120 | .sess_search_messages = maildriver_generic_search_messages, |
120 | #endif | 121 | #endif |
121 | 122 | ||
122 | .sess_get_message = pop3driver_get_message, | 123 | .sess_get_message = pop3driver_get_message, |
123 | .sess_get_message_by_uid = NULL, | 124 | .sess_get_message_by_uid = NULL, |
124 | }; | 125 | }; |
125 | 126 | ||
126 | mailsession_driver * pop3_session_driver = &local_pop3_session_driver; | 127 | mailsession_driver * pop3_session_driver = &local_pop3_session_driver; |
127 | 128 | ||
128 | static inline struct pop3_session_state_data * | 129 | static inline struct pop3_session_state_data * |
129 | get_data(mailsession * session) | 130 | get_data(mailsession * session) |
130 | { | 131 | { |
131 | return session->sess_data; | 132 | return session->sess_data; |
132 | } | 133 | } |
133 | 134 | ||
134 | static mailpop3 * get_pop3_session(mailsession * session) | 135 | static mailpop3 * get_pop3_session(mailsession * session) |
135 | { | 136 | { |
136 | return get_data(session)->pop3_session; | 137 | return get_data(session)->pop3_session; |
137 | } | 138 | } |
138 | 139 | ||
139 | static int pop3driver_initialize(mailsession * session) | 140 | static int pop3driver_initialize(mailsession * session) |
140 | { | 141 | { |
141 | struct pop3_session_state_data * data; | 142 | struct pop3_session_state_data * data; |
142 | mailpop3 * pop3; | 143 | mailpop3 * pop3; |
143 | 144 | ||
diff --git a/kmicromail/libetpan/generic/pop3driver_cached.c b/kmicromail/libetpan/generic/pop3driver_cached.c index 6f97303..24f624b 100644 --- a/kmicromail/libetpan/generic/pop3driver_cached.c +++ b/kmicromail/libetpan/generic/pop3driver_cached.c | |||
@@ -81,109 +81,113 @@ static int pop3driver_cached_noop(mailsession * session); | |||
81 | static int pop3driver_cached_expunge_folder(mailsession * session); | 81 | static int pop3driver_cached_expunge_folder(mailsession * session); |
82 | 82 | ||
83 | static int pop3driver_cached_status_folder(mailsession * session, | 83 | static int pop3driver_cached_status_folder(mailsession * session, |
84 | char * mb, uint32_t * result_messages, uint32_t * result_recent, | 84 | char * mb, uint32_t * result_messages, uint32_t * result_recent, |
85 | uint32_t * result_unseen); | 85 | uint32_t * result_unseen); |
86 | 86 | ||
87 | static int pop3driver_cached_messages_number(mailsession * session, | 87 | static int pop3driver_cached_messages_number(mailsession * session, |
88 | char * mb, | 88 | char * mb, |
89 | uint32_t * result); | 89 | uint32_t * result); |
90 | 90 | ||
91 | static int pop3driver_cached_recent_number(mailsession * session, | 91 | static int pop3driver_cached_recent_number(mailsession * session, |
92 | char * mb, | 92 | char * mb, |
93 | uint32_t * result); | 93 | uint32_t * result); |
94 | 94 | ||
95 | static int pop3driver_cached_unseen_number(mailsession * session, | 95 | static int pop3driver_cached_unseen_number(mailsession * session, |
96 | char * mb, | 96 | char * mb, |
97 | uint32_t * result); | 97 | uint32_t * result); |
98 | 98 | ||
99 | static int pop3driver_cached_remove_message(mailsession * session, | 99 | static int pop3driver_cached_remove_message(mailsession * session, |
100 | uint32_t num); | 100 | uint32_t num); |
101 | 101 | ||
102 | static int | 102 | static int |
103 | pop3driver_cached_get_messages_list(mailsession * session, | 103 | pop3driver_cached_get_messages_list(mailsession * session, |
104 | struct mailmessage_list ** result); | 104 | struct mailmessage_list ** result); |
105 | 105 | ||
106 | static int | 106 | static int |
107 | pop3driver_cached_get_envelopes_list(mailsession * session, | 107 | pop3driver_cached_get_envelopes_list(mailsession * session, |
108 | struct mailmessage_list * env_list); | 108 | struct mailmessage_list * env_list); |
109 | 109 | ||
110 | static int pop3driver_cached_get_message(mailsession * session, | 110 | static int pop3driver_cached_get_message(mailsession * session, |
111 | uint32_t num, mailmessage ** result); | 111 | uint32_t num, mailmessage ** result); |
112 | 112 | ||
113 | static int pop3driver_cached_get_message_by_uid(mailsession * session, | ||
114 | const char * uid, mailmessage ** result); | ||
115 | |||
113 | static mailsession_driver local_pop3_cached_session_driver = { | 116 | static mailsession_driver local_pop3_cached_session_driver = { |
114 | .sess_name = "pop3-cached", | 117 | .sess_name = "pop3-cached", |
115 | 118 | ||
116 | .sess_initialize = pop3driver_cached_initialize, | 119 | .sess_initialize = pop3driver_cached_initialize, |
117 | .sess_uninitialize = pop3driver_cached_uninitialize, | 120 | .sess_uninitialize = pop3driver_cached_uninitialize, |
118 | 121 | ||
119 | .sess_parameters = pop3driver_cached_parameters, | 122 | .sess_parameters = pop3driver_cached_parameters, |
120 | 123 | ||
121 | .sess_connect_stream = pop3driver_cached_connect_stream, | 124 | .sess_connect_stream = pop3driver_cached_connect_stream, |
122 | .sess_connect_path = NULL, | 125 | .sess_connect_path = NULL, |
123 | .sess_starttls = pop3driver_cached_starttls, | 126 | .sess_starttls = pop3driver_cached_starttls, |
124 | .sess_login = pop3driver_cached_login, | 127 | .sess_login = pop3driver_cached_login, |
125 | .sess_logout = pop3driver_cached_logout, | 128 | .sess_logout = pop3driver_cached_logout, |
126 | .sess_noop = pop3driver_cached_noop, | 129 | .sess_noop = pop3driver_cached_noop, |
127 | 130 | ||
128 | .sess_build_folder_name = NULL, | 131 | .sess_build_folder_name = NULL, |
129 | .sess_create_folder = NULL, | 132 | .sess_create_folder = NULL, |
130 | .sess_delete_folder = NULL, | 133 | .sess_delete_folder = NULL, |
131 | .sess_rename_folder = NULL, | 134 | .sess_rename_folder = NULL, |
132 | .sess_check_folder = pop3driver_cached_check_folder, | 135 | .sess_check_folder = pop3driver_cached_check_folder, |
133 | .sess_examine_folder = NULL, | 136 | .sess_examine_folder = NULL, |
134 | .sess_select_folder = NULL, | 137 | .sess_select_folder = NULL, |
135 | .sess_expunge_folder = pop3driver_cached_expunge_folder, | 138 | .sess_expunge_folder = pop3driver_cached_expunge_folder, |
136 | .sess_status_folder = pop3driver_cached_status_folder, | 139 | .sess_status_folder = pop3driver_cached_status_folder, |
137 | .sess_messages_number = pop3driver_cached_messages_number, | 140 | .sess_messages_number = pop3driver_cached_messages_number, |
138 | .sess_recent_number = pop3driver_cached_recent_number, | 141 | .sess_recent_number = pop3driver_cached_recent_number, |
139 | .sess_unseen_number = pop3driver_cached_unseen_number, | 142 | .sess_unseen_number = pop3driver_cached_unseen_number, |
140 | .sess_list_folders = NULL, | 143 | .sess_list_folders = NULL, |
141 | .sess_lsub_folders = NULL, | 144 | .sess_lsub_folders = NULL, |
142 | .sess_subscribe_folder = NULL, | 145 | .sess_subscribe_folder = NULL, |
143 | .sess_unsubscribe_folder = NULL, | 146 | .sess_unsubscribe_folder = NULL, |
144 | 147 | ||
145 | .sess_append_message = NULL, | 148 | .sess_append_message = NULL, |
149 | .sess_append_message_flags = NULL, | ||
146 | .sess_copy_message = NULL, | 150 | .sess_copy_message = NULL, |
147 | .sess_move_message = NULL, | 151 | .sess_move_message = NULL, |
148 | 152 | ||
149 | .sess_get_messages_list = pop3driver_cached_get_messages_list, | 153 | .sess_get_messages_list = pop3driver_cached_get_messages_list, |
150 | .sess_get_envelopes_list = pop3driver_cached_get_envelopes_list, | 154 | .sess_get_envelopes_list = pop3driver_cached_get_envelopes_list, |
151 | .sess_remove_message = pop3driver_cached_remove_message, | 155 | .sess_remove_message = pop3driver_cached_remove_message, |
152 | #if 0 | 156 | #if 0 |
153 | .sess_search_messages = maildriver_generic_search_messages, | 157 | .sess_search_messages = maildriver_generic_search_messages, |
154 | #endif | 158 | #endif |
155 | 159 | ||
156 | .sess_get_message = pop3driver_cached_get_message, | 160 | .sess_get_message = pop3driver_cached_get_message, |
157 | .sess_get_message_by_uid = NULL, | 161 | .sess_get_message_by_uid = pop3driver_cached_get_message_by_uid, |
158 | }; | 162 | }; |
159 | 163 | ||
160 | mailsession_driver * pop3_cached_session_driver = | 164 | mailsession_driver * pop3_cached_session_driver = |
161 | &local_pop3_cached_session_driver; | 165 | &local_pop3_cached_session_driver; |
162 | 166 | ||
163 | #define ENV_NAME "env.db" | 167 | #define ENV_NAME "env.db" |
164 | #define FLAGS_NAME "flags.db" | 168 | #define FLAGS_NAME "flags.db" |
165 | 169 | ||
166 | 170 | ||
167 | static inline struct pop3_cached_session_state_data * | 171 | static inline struct pop3_cached_session_state_data * |
168 | get_cached_data(mailsession * session) | 172 | get_cached_data(mailsession * session) |
169 | { | 173 | { |
170 | return session->sess_data; | 174 | return session->sess_data; |
171 | } | 175 | } |
172 | 176 | ||
173 | static inline mailsession * get_ancestor(mailsession * session) | 177 | static inline mailsession * get_ancestor(mailsession * session) |
174 | { | 178 | { |
175 | return get_cached_data(session)->pop3_ancestor; | 179 | return get_cached_data(session)->pop3_ancestor; |
176 | } | 180 | } |
177 | 181 | ||
178 | static inline struct pop3_session_state_data * | 182 | static inline struct pop3_session_state_data * |
179 | get_ancestor_data(mailsession * session) | 183 | get_ancestor_data(mailsession * session) |
180 | { | 184 | { |
181 | return get_ancestor(session)->sess_data; | 185 | return get_ancestor(session)->sess_data; |
182 | } | 186 | } |
183 | 187 | ||
184 | static inline mailpop3 * get_pop3_session(mailsession * session) | 188 | static inline mailpop3 * get_pop3_session(mailsession * session) |
185 | { | 189 | { |
186 | return get_ancestor_data(session)->pop3_session; | 190 | return get_ancestor_data(session)->pop3_session; |
187 | } | 191 | } |
188 | 192 | ||
189 | static int pop3driver_cached_initialize(mailsession * session) | 193 | static int pop3driver_cached_initialize(mailsession * session) |
@@ -826,32 +830,70 @@ pop3driver_cached_get_envelopes_list(mailsession * session, | |||
826 | env_list, get_uid_from_filename); | 830 | env_list, get_uid_from_filename); |
827 | 831 | ||
828 | return MAIL_NO_ERROR; | 832 | return MAIL_NO_ERROR; |
829 | 833 | ||
830 | close_db_env: | 834 | close_db_env: |
831 | mail_cache_db_close_unlock(filename_env, cache_db_env); | 835 | mail_cache_db_close_unlock(filename_env, cache_db_env); |
832 | free_mmapstr: | 836 | free_mmapstr: |
833 | mmap_string_free(mmapstr); | 837 | mmap_string_free(mmapstr); |
834 | err: | 838 | err: |
835 | return res; | 839 | return res; |
836 | } | 840 | } |
837 | 841 | ||
838 | static int pop3driver_cached_get_message(mailsession * session, | 842 | static int pop3driver_cached_get_message(mailsession * session, |
839 | uint32_t num, mailmessage ** result) | 843 | uint32_t num, mailmessage ** result) |
840 | { | 844 | { |
841 | mailmessage * msg_info; | 845 | mailmessage * msg_info; |
842 | int r; | 846 | int r; |
843 | 847 | ||
844 | msg_info = mailmessage_new(); | 848 | msg_info = mailmessage_new(); |
845 | if (msg_info == NULL) | 849 | if (msg_info == NULL) |
846 | return MAIL_ERROR_MEMORY; | 850 | return MAIL_ERROR_MEMORY; |
847 | 851 | ||
848 | r = mailmessage_init(msg_info, session, pop3_cached_message_driver, num, 0); | 852 | r = mailmessage_init(msg_info, session, pop3_cached_message_driver, num, 0); |
849 | if (r != MAIL_NO_ERROR) { | 853 | if (r != MAIL_NO_ERROR) { |
850 | mailmessage_free(msg_info); | 854 | mailmessage_free(msg_info); |
851 | return r; | 855 | return r; |
852 | } | 856 | } |
853 | 857 | ||
854 | * result = msg_info; | 858 | * result = msg_info; |
855 | 859 | ||
856 | return MAIL_NO_ERROR; | 860 | return MAIL_NO_ERROR; |
857 | } | 861 | } |
862 | |||
863 | static int pop3driver_cached_get_message_by_uid(mailsession * session, | ||
864 | const char * uid, mailmessage ** result) | ||
865 | { | ||
866 | mailpop3 * pop3; | ||
867 | struct mailpop3_msg_info * msg_info; | ||
868 | int found; | ||
869 | unsigned int i; | ||
870 | |||
871 | if (uid == NULL) | ||
872 | return MAIL_ERROR_INVAL; | ||
873 | |||
874 | pop3 = get_pop3_session(session); | ||
875 | |||
876 | found = 0; | ||
877 | |||
878 | /* iterate all messages and look for uid */ | ||
879 | for(i = 0 ; i < carray_count(pop3->pop3_msg_tab) ; i++) { | ||
880 | msg_info = carray_get(pop3->pop3_msg_tab, i); | ||
881 | |||
882 | if (msg_info == NULL) | ||
883 | continue; | ||
884 | |||
885 | if (msg_info->msg_deleted) | ||
886 | continue; | ||
887 | |||
888 | /* uid found, stop looking */ | ||
889 | if (strcmp(msg_info->msg_uidl, uid) == 0) { | ||
890 | found = 1; | ||
891 | break; | ||
892 | } | ||
893 | } | ||
894 | |||
895 | if (!found) | ||
896 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
897 | |||
898 | return pop3driver_cached_get_message(session, msg_info->msg_index, result); | ||
899 | } | ||
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 | |||
@@ -10,146 +10,180 @@ | |||
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
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, |
54 | size_t * result); | 56 | size_t * result); |
55 | 57 | ||
56 | static mailmessage_driver local_pop3_message_driver = { | 58 | static mailmessage_driver local_pop3_message_driver = { |
57 | .msg_name = "pop3", | 59 | .msg_name = "pop3", |
58 | 60 | ||
59 | .msg_initialize = pop3_initialize, | 61 | .msg_initialize = pop3_initialize, |
60 | .msg_uninitialize = mailmessage_generic_uninitialize, | 62 | .msg_uninitialize = mailmessage_generic_uninitialize, |
61 | 63 | ||
62 | .msg_flush = mailmessage_generic_flush, | 64 | .msg_flush = mailmessage_generic_flush, |
63 | .msg_check = NULL, | 65 | .msg_check = NULL, |
64 | 66 | ||
65 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, | 67 | .msg_fetch_result_free = mailmessage_generic_fetch_result_free, |
66 | 68 | ||
67 | .msg_fetch = mailmessage_generic_fetch, | 69 | .msg_fetch = mailmessage_generic_fetch, |
68 | .msg_fetch_header = pop3_fetch_header, | 70 | .msg_fetch_header = pop3_fetch_header, |
69 | .msg_fetch_body = mailmessage_generic_fetch_body, | 71 | .msg_fetch_body = mailmessage_generic_fetch_body, |
70 | .msg_fetch_size = pop3_fetch_size, | 72 | .msg_fetch_size = pop3_fetch_size, |
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; |
95 | 109 | ||
96 | msg = msg_info->msg_data; | 110 | msg = msg_info->msg_data; |
97 | 111 | ||
98 | msg->msg_message = msg_content; | 112 | msg->msg_message = msg_content; |
99 | msg->msg_length = msg_length; | 113 | msg->msg_length = msg_length; |
100 | 114 | ||
101 | return MAIL_NO_ERROR; | 115 | return MAIL_NO_ERROR; |
102 | } | 116 | } |
103 | 117 | ||
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; |
136 | int r; | 170 | int r; |
137 | 171 | ||
138 | msg = msg_info->msg_data; | 172 | msg = msg_info->msg_data; |
139 | 173 | ||
140 | if (msg->msg_message != NULL) | 174 | if (msg->msg_message != NULL) |
141 | return mailmessage_generic_fetch_header(msg_info, | 175 | return mailmessage_generic_fetch_header(msg_info, |
142 | result, result_len); | 176 | result, result_len); |
143 | 177 | ||
144 | r = pop3driver_header(msg_info->msg_session, msg_info->msg_index, | 178 | r = pop3driver_header(msg_info->msg_session, msg_info->msg_index, |
145 | &headers, &headers_length); | 179 | &headers, &headers_length); |
146 | if (r != MAIL_NO_ERROR) | 180 | if (r != MAIL_NO_ERROR) |
147 | return r; | 181 | return r; |
148 | 182 | ||
149 | * result = headers; | 183 | * result = headers; |
150 | * result_len = headers_length; | 184 | * result_len = headers_length; |
151 | 185 | ||
152 | return MAIL_NO_ERROR; | 186 | return MAIL_NO_ERROR; |
153 | } | 187 | } |
154 | 188 | ||
155 | static int pop3_fetch_size(mailmessage * msg_info, | 189 | static int pop3_fetch_size(mailmessage * msg_info, |
diff --git a/kmicromail/libetpan/generic/pop3storage.c b/kmicromail/libetpan/generic/pop3storage.c index 8e7a94e..375aeaf 100644 --- a/kmicromail/libetpan/generic/pop3storage.c +++ b/kmicromail/libetpan/generic/pop3storage.c | |||
@@ -39,65 +39,65 @@ | |||
39 | #include <string.h> | 39 | #include <string.h> |
40 | 40 | ||
41 | #include "mail.h" | 41 | #include "mail.h" |
42 | #include "mailstorage_tools.h" | 42 | #include "mailstorage_tools.h" |
43 | #include "maildriver.h" | 43 | #include "maildriver.h" |
44 | 44 | ||
45 | /* pop3 storage */ | 45 | /* pop3 storage */ |
46 | 46 | ||
47 | #define POP3_DEFAULT_PORT 110 | 47 | #define POP3_DEFAULT_PORT 110 |
48 | #define POP3S_DEFAULT_PORT 995 | 48 | #define POP3S_DEFAULT_PORT 995 |
49 | 49 | ||
50 | static int pop3_mailstorage_connect(struct mailstorage * storage); | 50 | static int pop3_mailstorage_connect(struct mailstorage * storage); |
51 | static int pop3_mailstorage_get_folder_session(struct mailstorage * storage, | 51 | static int pop3_mailstorage_get_folder_session(struct mailstorage * storage, |
52 | char * pathname, mailsession ** result); | 52 | char * pathname, mailsession ** result); |
53 | static void pop3_mailstorage_uninitialize(struct mailstorage * storage); | 53 | static void pop3_mailstorage_uninitialize(struct mailstorage * storage); |
54 | 54 | ||
55 | static mailstorage_driver pop3_mailstorage_driver = { | 55 | static mailstorage_driver pop3_mailstorage_driver = { |
56 | .sto_name = "pop3", | 56 | .sto_name = "pop3", |
57 | .sto_connect = pop3_mailstorage_connect, | 57 | .sto_connect = pop3_mailstorage_connect, |
58 | .sto_get_folder_session = pop3_mailstorage_get_folder_session, | 58 | .sto_get_folder_session = pop3_mailstorage_get_folder_session, |
59 | .sto_uninitialize = pop3_mailstorage_uninitialize, | 59 | .sto_uninitialize = pop3_mailstorage_uninitialize, |
60 | }; | 60 | }; |
61 | 61 | ||
62 | int pop3_mailstorage_init(struct mailstorage * storage, | 62 | int pop3_mailstorage_init(struct mailstorage * storage, |
63 | char * pop3_servername, uint16_t pop3_port, | 63 | char * pop3_servername, uint16_t pop3_port, |
64 | char * pop3_command, | 64 | char * pop3_command, |
65 | int pop3_connection_type, int pop3_auth_type, | 65 | int pop3_connection_type, int pop3_auth_type, |
66 | char * pop3_login, char * pop3_password, | 66 | char * pop3_login, char * pop3_password, |
67 | int pop3_cached, char * pop3_cache_directory, char * pop3_flags_directory) | 67 | int pop3_cached, char * pop3_cache_directory, char * pop3_flags_directory) |
68 | { | 68 | { |
69 | struct pop3_mailstorage * pop3_storage; | 69 | struct pop3_mailstorage * pop3_storage; |
70 | 70 | ||
71 | pop3_storage = malloc(sizeof(struct pop3_mailstorage)); | 71 | pop3_storage = malloc(sizeof(* pop3_storage)); |
72 | if (pop3_storage == NULL) | 72 | if (pop3_storage == NULL) |
73 | goto err; | 73 | goto err; |
74 | 74 | ||
75 | pop3_storage->pop3_servername = strdup(pop3_servername); | 75 | pop3_storage->pop3_servername = strdup(pop3_servername); |
76 | if (pop3_storage->pop3_servername == NULL) | 76 | if (pop3_storage->pop3_servername == NULL) |
77 | goto free; | 77 | goto free; |
78 | 78 | ||
79 | pop3_storage->pop3_connection_type = pop3_connection_type; | 79 | pop3_storage->pop3_connection_type = pop3_connection_type; |
80 | 80 | ||
81 | if (pop3_port == 0) { | 81 | if (pop3_port == 0) { |
82 | switch (pop3_connection_type) { | 82 | switch (pop3_connection_type) { |
83 | case CONNECTION_TYPE_PLAIN: | 83 | case CONNECTION_TYPE_PLAIN: |
84 | case CONNECTION_TYPE_TRY_STARTTLS: | 84 | case CONNECTION_TYPE_TRY_STARTTLS: |
85 | case CONNECTION_TYPE_STARTTLS: | 85 | case CONNECTION_TYPE_STARTTLS: |
86 | case CONNECTION_TYPE_COMMAND: | 86 | case CONNECTION_TYPE_COMMAND: |
87 | case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: | 87 | case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: |
88 | case CONNECTION_TYPE_COMMAND_STARTTLS: | 88 | case CONNECTION_TYPE_COMMAND_STARTTLS: |
89 | pop3_port = POP3_DEFAULT_PORT; | 89 | pop3_port = POP3_DEFAULT_PORT; |
90 | break; | 90 | break; |
91 | 91 | ||
92 | case CONNECTION_TYPE_TLS: | 92 | case CONNECTION_TYPE_TLS: |
93 | case CONNECTION_TYPE_COMMAND_TLS: | 93 | case CONNECTION_TYPE_COMMAND_TLS: |
94 | pop3_port = POP3S_DEFAULT_PORT; | 94 | pop3_port = POP3S_DEFAULT_PORT; |
95 | break; | 95 | break; |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | pop3_storage->pop3_port = pop3_port; | 99 | pop3_storage->pop3_port = pop3_port; |
100 | 100 | ||
101 | if (pop3_command != NULL) { | 101 | if (pop3_command != NULL) { |
102 | pop3_storage->pop3_command = strdup(pop3_command); | 102 | pop3_storage->pop3_command = strdup(pop3_command); |
103 | if (pop3_storage->pop3_command == NULL) | 103 | if (pop3_storage->pop3_command == NULL) |
diff --git a/kmicromail/libetpan/imap/mailimap.c b/kmicromail/libetpan/imap/mailimap.c index c8fbfee..76d9454 100644 --- a/kmicromail/libetpan/imap/mailimap.c +++ b/kmicromail/libetpan/imap/mailimap.c | |||
@@ -1878,65 +1878,65 @@ int mailimap_subscribe(mailimap * session, const char * mb) | |||
1878 | 1878 | ||
1879 | r = parse_response(session, &response); | 1879 | r = parse_response(session, &response); |
1880 | if (r != MAILIMAP_NO_ERROR) | 1880 | if (r != MAILIMAP_NO_ERROR) |
1881 | return r; | 1881 | return r; |
1882 | 1882 | ||
1883 | error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; | 1883 | error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; |
1884 | 1884 | ||
1885 | mailimap_response_free(response); | 1885 | mailimap_response_free(response); |
1886 | 1886 | ||
1887 | switch (error_code) { | 1887 | switch (error_code) { |
1888 | case MAILIMAP_RESP_COND_STATE_OK: | 1888 | case MAILIMAP_RESP_COND_STATE_OK: |
1889 | return MAILIMAP_NO_ERROR; | 1889 | return MAILIMAP_NO_ERROR; |
1890 | 1890 | ||
1891 | default: | 1891 | default: |
1892 | return MAILIMAP_ERROR_SUBSCRIBE; | 1892 | return MAILIMAP_ERROR_SUBSCRIBE; |
1893 | } | 1893 | } |
1894 | } | 1894 | } |
1895 | 1895 | ||
1896 | int mailimap_unsubscribe(mailimap * session, const char * mb) | 1896 | int mailimap_unsubscribe(mailimap * session, const char * mb) |
1897 | { | 1897 | { |
1898 | struct mailimap_response * response; | 1898 | struct mailimap_response * response; |
1899 | int r; | 1899 | int r; |
1900 | int error_code; | 1900 | int error_code; |
1901 | 1901 | ||
1902 | if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) && | 1902 | if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) && |
1903 | (session->imap_state != MAILIMAP_STATE_SELECTED)) | 1903 | (session->imap_state != MAILIMAP_STATE_SELECTED)) |
1904 | return MAILIMAP_ERROR_BAD_STATE; | 1904 | return MAILIMAP_ERROR_BAD_STATE; |
1905 | 1905 | ||
1906 | r = send_current_tag(session); | 1906 | r = send_current_tag(session); |
1907 | if (r != MAILIMAP_NO_ERROR) | 1907 | if (r != MAILIMAP_NO_ERROR) |
1908 | return r; | 1908 | return r; |
1909 | 1909 | ||
1910 | r = mailimap_subscribe_send(session->imap_stream, mb); | 1910 | r = mailimap_unsubscribe_send(session->imap_stream, mb); |
1911 | if (r != MAILIMAP_NO_ERROR) | 1911 | if (r != MAILIMAP_NO_ERROR) |
1912 | return r; | 1912 | return r; |
1913 | 1913 | ||
1914 | r = mailimap_crlf_send(session->imap_stream); | 1914 | r = mailimap_crlf_send(session->imap_stream); |
1915 | if (r != MAILIMAP_NO_ERROR) | 1915 | if (r != MAILIMAP_NO_ERROR) |
1916 | return r; | 1916 | return r; |
1917 | 1917 | ||
1918 | if (mailstream_flush(session->imap_stream) == -1) | 1918 | if (mailstream_flush(session->imap_stream) == -1) |
1919 | return MAILIMAP_ERROR_STREAM; | 1919 | return MAILIMAP_ERROR_STREAM; |
1920 | 1920 | ||
1921 | if (read_line(session) == NULL) | 1921 | if (read_line(session) == NULL) |
1922 | return MAILIMAP_ERROR_STREAM; | 1922 | return MAILIMAP_ERROR_STREAM; |
1923 | 1923 | ||
1924 | r = parse_response(session, &response); | 1924 | r = parse_response(session, &response); |
1925 | if (r != MAILIMAP_NO_ERROR) | 1925 | if (r != MAILIMAP_NO_ERROR) |
1926 | return r; | 1926 | return r; |
1927 | 1927 | ||
1928 | error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; | 1928 | error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type; |
1929 | 1929 | ||
1930 | mailimap_response_free(response); | 1930 | mailimap_response_free(response); |
1931 | 1931 | ||
1932 | switch (error_code) { | 1932 | switch (error_code) { |
1933 | case MAILIMAP_RESP_COND_STATE_OK: | 1933 | case MAILIMAP_RESP_COND_STATE_OK: |
1934 | return MAILIMAP_NO_ERROR; | 1934 | return MAILIMAP_NO_ERROR; |
1935 | 1935 | ||
1936 | default: | 1936 | default: |
1937 | return MAILIMAP_ERROR_UNSUBSCRIBE; | 1937 | return MAILIMAP_ERROR_UNSUBSCRIBE; |
1938 | } | 1938 | } |
1939 | } | 1939 | } |
1940 | 1940 | ||
1941 | 1941 | ||
1942 | int mailimap_starttls(mailimap * session) | 1942 | int mailimap_starttls(mailimap * session) |
diff --git a/kmicromail/libetpan/imap/mailimap_keywords.c b/kmicromail/libetpan/imap/mailimap_keywords.c index b277aed..4ec156e 100644 --- a/kmicromail/libetpan/imap/mailimap_keywords.c +++ b/kmicromail/libetpan/imap/mailimap_keywords.c | |||
@@ -24,65 +24,65 @@ | |||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "mailimap_keywords.h" | 36 | #include "mailimap_keywords.h" |
37 | #include "mailimap_types.h" | 37 | #include "mailimap_types.h" |
38 | #include <string.h> | 38 | #include <string.h> |
39 | #include <stdio.h> | 39 | #include <stdio.h> |
40 | 40 | ||
41 | #ifndef UNSTRICT_SYNTAX | 41 | #ifndef UNSTRICT_SYNTAX |
42 | #define UNSTRICT_SYNTAX | 42 | #define UNSTRICT_SYNTAX |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | struct mailimap_token_value { | 45 | struct mailimap_token_value { |
46 | int value; | 46 | int value; |
47 | const char * str; | 47 | const char * str; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | int mailimap_token_case_insensitive_parse(mailstream * fd, | 50 | int mailimap_token_case_insensitive_parse(mailstream * fd, |
51 | MMAPString * buffer, | 51 | MMAPString * buffer, |
52 | size_t * index, | 52 | size_t * index, |
53 | const char * token) | 53 | const char * token) |
54 | { | 54 | { |
55 | int len; | 55 | int len; |
56 | int cur_token; | 56 | size_t cur_token; |
57 | int r; | 57 | int r; |
58 | 58 | ||
59 | cur_token = * index; | 59 | cur_token = * index; |
60 | len = strlen(token); | 60 | len = strlen(token); |
61 | 61 | ||
62 | #ifdef UNSTRICT_SYNTAX | 62 | #ifdef UNSTRICT_SYNTAX |
63 | r = mailimap_space_parse(fd, buffer, &cur_token); | 63 | r = mailimap_space_parse(fd, buffer, &cur_token); |
64 | if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) | 64 | if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) |
65 | return r; | 65 | return r; |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | if (strncasecmp(buffer->str + cur_token, token, len) == 0) { | 68 | if (strncasecmp(buffer->str + cur_token, token, len) == 0) { |
69 | cur_token += len; | 69 | cur_token += len; |
70 | * index = cur_token; | 70 | * index = cur_token; |
71 | return MAILIMAP_NO_ERROR; | 71 | return MAILIMAP_NO_ERROR; |
72 | } | 72 | } |
73 | else | 73 | else |
74 | return MAILIMAP_ERROR_PARSE; | 74 | return MAILIMAP_ERROR_PARSE; |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | static int is_space_or_tab(char ch) | 78 | static int is_space_or_tab(char ch) |
79 | { | 79 | { |
80 | return (ch == ' ') || (ch == '\t'); | 80 | return (ch == ' ') || (ch == '\t'); |
81 | } | 81 | } |
82 | 82 | ||
83 | int mailimap_char_parse(mailstream * fd, MMAPString * buffer, | 83 | int mailimap_char_parse(mailstream * fd, MMAPString * buffer, |
84 | size_t * index, char token) | 84 | size_t * index, char token) |
85 | { | 85 | { |
86 | int cur_token; | 86 | int cur_token; |
87 | 87 | ||
88 | cur_token = * index; | 88 | cur_token = * index; |
diff --git a/kmicromail/libetpan/imf/mailimf.c b/kmicromail/libetpan/imf/mailimf.c index 84d81a1..e0164b8 100644 --- a/kmicromail/libetpan/imf/mailimf.c +++ b/kmicromail/libetpan/imf/mailimf.c | |||
@@ -19,65 +19,65 @@ | |||
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "mailimf.h" | 36 | #include "mailimf.h" |
37 | 37 | ||
38 | /* | 38 | /* |
39 | RFC 2822 | 39 | RFC 2822 |
40 | 40 | ||
41 | RFC 2821 ... | 41 | RFC 2821 ... |
42 | A message-originating SMTP system SHOULD NOT send a message that | 42 | A message-originating SMTP system SHOULD NOT send a message that |
43 | already contains a Return-path header. SMTP servers performing a | 43 | already contains a Return-path header. SMTP servers performing a |
44 | relay function MUST NOT inspect the message data, and especially not | 44 | relay function MUST NOT inspect the message data, and especially not |
45 | to the extent needed to determine if Return-path headers are present. | 45 | to the extent needed to determine if Return-path headers are present. |
46 | SMTP servers making final delivery MAY remove Return-path headers | 46 | SMTP servers making final delivery MAY remove Return-path headers |
47 | before adding their own. | 47 | before adding their own. |
48 | */ | 48 | */ |
49 | 49 | ||
50 | #include <ctype.h> | 50 | #include <ctype.h> |
51 | #include <mmapstring.h> | 51 | #include "mmapstring.h" |
52 | #include <stdlib.h> | 52 | #include <stdlib.h> |
53 | #include <string.h> | 53 | #include <string.h> |
54 | 54 | ||
55 | #ifndef TRUE | 55 | #ifndef TRUE |
56 | #define TRUE 1 | 56 | #define TRUE 1 |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | #ifndef FALSE | 59 | #ifndef FALSE |
60 | #define FALSE 0 | 60 | #define FALSE 0 |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | 63 | ||
64 | 64 | ||
65 | 65 | ||
66 | 66 | ||
67 | 67 | ||
68 | 68 | ||
69 | static inline int is_dtext(char ch); | 69 | static inline int is_dtext(char ch); |
70 | 70 | ||
71 | static int mailimf_quoted_pair_parse(const char * message, size_t length, | 71 | static int mailimf_quoted_pair_parse(const char * message, size_t length, |
72 | size_t * index, char * result); | 72 | size_t * index, char * result); |
73 | 73 | ||
74 | static int mailimf_ccontent_parse(const char * message, size_t length, | 74 | static int mailimf_ccontent_parse(const char * message, size_t length, |
75 | size_t * index); | 75 | size_t * index); |
76 | 76 | ||
77 | static int | 77 | static int |
78 | mailimf_comment_fws_ccontent_parse(const char * message, size_t length, | 78 | mailimf_comment_fws_ccontent_parse(const char * message, size_t length, |
79 | size_t * index); | 79 | size_t * index); |
80 | 80 | ||
81 | static inline int mailimf_comment_parse(const char * message, size_t length, | 81 | static inline int mailimf_comment_parse(const char * message, size_t length, |
82 | size_t * index); | 82 | size_t * index); |
83 | 83 | ||
diff --git a/kmicromail/libetpan/include/libetpan/libetpan.h b/kmicromail/libetpan/include/libetpan/libetpan.h index 3b4a107..fe5637d 100644 --- a/kmicromail/libetpan/include/libetpan/libetpan.h +++ b/kmicromail/libetpan/include/libetpan/libetpan.h | |||
@@ -15,90 +15,102 @@ | |||
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef LIBETPAN_H | 36 | #ifndef LIBETPAN_H |
37 | 37 | ||
38 | #define LIBETPAN_H | 38 | #define LIBETPAN_H |
39 | 39 | ||
40 | #ifdef __cplusplus | 40 | #ifdef __cplusplus |
41 | extern "C" { | 41 | extern "C" { |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | #include <libetpan/libetpan_version.h> | 44 | #include <libetpan/libetpan_version.h> |
45 | #include <libetpan/maildriver.h> | 45 | #include <libetpan/maildriver.h> |
46 | #include <libetpan/mailmessage.h> | 46 | #include <libetpan/mailmessage.h> |
47 | #include <libetpan/mailfolder.h> | ||
47 | #include <libetpan/mailstorage.h> | 48 | #include <libetpan/mailstorage.h> |
48 | #include <libetpan/mailthread.h> | 49 | #include <libetpan/mailthread.h> |
49 | #include <libetpan/mailsmtp.h> | 50 | #include <libetpan/mailsmtp.h> |
50 | #include <libetpan/charconv.h> | 51 | #include <libetpan/charconv.h> |
51 | 52 | ||
52 | /* mbox driver */ | 53 | /* mbox driver */ |
53 | #include <libetpan/mboxdriver.h> | 54 | #include <libetpan/mboxdriver.h> |
54 | #include <libetpan/mboxdriver_message.h> | 55 | #include <libetpan/mboxdriver_message.h> |
55 | #include <libetpan/mboxdriver_cached.h> | 56 | #include <libetpan/mboxdriver_cached.h> |
56 | #include <libetpan/mboxdriver_cached_message.h> | 57 | #include <libetpan/mboxdriver_cached_message.h> |
57 | #include <libetpan/mboxstorage.h> | 58 | #include <libetpan/mboxstorage.h> |
58 | 59 | ||
59 | /* MH driver */ | 60 | /* MH driver */ |
60 | #include <libetpan/mhdriver.h> | 61 | #include <libetpan/mhdriver.h> |
61 | #include <libetpan/mhdriver_message.h> | 62 | #include <libetpan/mhdriver_message.h> |
62 | #include <libetpan/mhdriver_cached.h> | 63 | #include <libetpan/mhdriver_cached.h> |
63 | #include <libetpan/mhdriver_cached_message.h> | 64 | #include <libetpan/mhdriver_cached_message.h> |
64 | #include <libetpan/mhstorage.h> | 65 | #include <libetpan/mhstorage.h> |
65 | 66 | ||
66 | /* IMAP4rev1 driver */ | 67 | /* IMAP4rev1 driver */ |
67 | #include <libetpan/imapdriver.h> | 68 | #include <libetpan/imapdriver.h> |
68 | #include <libetpan/imapdriver_message.h> | 69 | #include <libetpan/imapdriver_message.h> |
69 | #include <libetpan/imapdriver_cached.h> | 70 | #include <libetpan/imapdriver_cached.h> |
70 | #include <libetpan/imapdriver_cached_message.h> | 71 | #include <libetpan/imapdriver_cached_message.h> |
71 | #include <libetpan/imapstorage.h> | 72 | #include <libetpan/imapstorage.h> |
72 | 73 | ||
73 | /* POP3 driver */ | 74 | /* POP3 driver */ |
74 | #include <libetpan/pop3driver.h> | 75 | #include <libetpan/pop3driver.h> |
75 | #include <libetpan/pop3driver_message.h> | 76 | #include <libetpan/pop3driver_message.h> |
76 | #include <libetpan/pop3driver_cached.h> | 77 | #include <libetpan/pop3driver_cached.h> |
77 | #include <libetpan/pop3driver_cached_message.h> | 78 | #include <libetpan/pop3driver_cached_message.h> |
78 | #include <libetpan/pop3storage.h> | 79 | #include <libetpan/pop3storage.h> |
79 | 80 | ||
80 | /* NNTP driver */ | 81 | /* NNTP driver */ |
81 | #include <libetpan/nntpdriver.h> | 82 | #include <libetpan/nntpdriver.h> |
82 | #include <libetpan/nntpdriver_message.h> | 83 | #include <libetpan/nntpdriver_message.h> |
83 | #include <libetpan/nntpdriver_cached.h> | 84 | #include <libetpan/nntpdriver_cached.h> |
84 | #include <libetpan/nntpdriver_cached_message.h> | 85 | #include <libetpan/nntpdriver_cached_message.h> |
85 | #include <libetpan/nntpstorage.h> | 86 | #include <libetpan/nntpstorage.h> |
86 | 87 | ||
87 | /* maildir driver */ | 88 | /* maildir driver */ |
88 | #include <libetpan/maildirdriver.h> | 89 | #include <libetpan/maildirdriver.h> |
89 | #include <libetpan/maildirdriver_message.h> | 90 | #include <libetpan/maildirdriver_message.h> |
90 | #include <libetpan/maildirdriver_cached.h> | 91 | #include <libetpan/maildirdriver_cached.h> |
91 | #include <libetpan/maildirdriver_cached_message.h> | 92 | #include <libetpan/maildirdriver_cached_message.h> |
92 | #include <libetpan/maildirstorage.h> | 93 | #include <libetpan/maildirstorage.h> |
93 | 94 | ||
95 | /* db driver */ | ||
96 | #include <libetpan/dbdriver.h> | ||
97 | #include <libetpan/dbdriver_message.h> | ||
98 | #include <libetpan/dbstorage.h> | ||
99 | |||
94 | /* message which content is given by a MIME structure */ | 100 | /* message which content is given by a MIME structure */ |
95 | #include <libetpan/mime_message_driver.h> | 101 | #include <libetpan/mime_message_driver.h> |
96 | 102 | ||
97 | /* message which content given by a string */ | 103 | /* message which content given by a string */ |
98 | #include <libetpan/data_message_driver.h> | 104 | #include <libetpan/data_message_driver.h> |
99 | 105 | ||
106 | /* engine */ | ||
107 | #include <libetpan/mailprivacy.h> | ||
108 | #include <libetpan/mailengine.h> | ||
109 | #include <libetpan/mailprivacy_gnupg.h> | ||
110 | #include <libetpan/mailprivacy_smime.h> | ||
111 | |||
100 | #ifdef __cplusplus | 112 | #ifdef __cplusplus |
101 | } | 113 | } |
102 | #endif | 114 | #endif |
103 | 115 | ||
104 | #endif | 116 | #endif |
diff --git a/kmicromail/libetpan/include/libetpan/maildir.h b/kmicromail/libetpan/include/libetpan/maildir.h index b782484..268dda1 100644 --- a/kmicromail/libetpan/include/libetpan/maildir.h +++ b/kmicromail/libetpan/include/libetpan/maildir.h | |||
@@ -16,45 +16,52 @@ | |||
16 | * contributors may be used to endorse or promote products derived | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef MAILDIR_H | 36 | #ifndef MAILDIR_H |
37 | 37 | ||
38 | #define MAILDIR_H | 38 | #define MAILDIR_H |
39 | 39 | ||
40 | #include <libetpan/maildir_types.h> | 40 | #include <libetpan/maildir_types.h> |
41 | 41 | ||
42 | struct maildir * maildir_new(const char * path); | 42 | struct maildir * maildir_new(const char * path); |
43 | 43 | ||
44 | void maildir_free(struct maildir * md); | 44 | void maildir_free(struct maildir * md); |
45 | 45 | ||
46 | int maildir_update(struct maildir * md); | 46 | int maildir_update(struct maildir * md); |
47 | 47 | ||
48 | int maildir_message_add_uid(struct maildir * md, | ||
49 | const char * message, size_t size, | ||
50 | char * uid, size_t max_uid_len); | ||
51 | |||
48 | int maildir_message_add(struct maildir * md, | 52 | int maildir_message_add(struct maildir * md, |
49 | const char * message, size_t size); | 53 | const char * message, size_t size); |
50 | 54 | ||
55 | int maildir_message_add_file_uid(struct maildir * md, int fd, | ||
56 | char * uid, size_t max_uid_len); | ||
57 | |||
51 | int maildir_message_add_file(struct maildir * md, int fd); | 58 | int maildir_message_add_file(struct maildir * md, int fd); |
52 | 59 | ||
53 | char * maildir_message_get(struct maildir * md, const char * uid); | 60 | char * maildir_message_get(struct maildir * md, const char * uid); |
54 | 61 | ||
55 | int maildir_message_remove(struct maildir * md, const char * uid); | 62 | int maildir_message_remove(struct maildir * md, const char * uid); |
56 | 63 | ||
57 | int maildir_message_change_flags(struct maildir * md, | 64 | int maildir_message_change_flags(struct maildir * md, |
58 | const char * uid, int new_flags); | 65 | const char * uid, int new_flags); |
59 | 66 | ||
60 | #endif | 67 | #endif |
diff --git a/kmicromail/libetpan/include/libetpan/maildirstorage.h b/kmicromail/libetpan/include/libetpan/maildirstorage.h index d17ea2c..73d7b20 100644 --- a/kmicromail/libetpan/include/libetpan/maildirstorage.h +++ b/kmicromail/libetpan/include/libetpan/maildirstorage.h | |||
@@ -15,55 +15,55 @@ | |||
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef MAILDIRSTORAGE_H | 36 | #ifndef MAILDIRSTORAGE_H |
37 | 37 | ||
38 | #define MAILDIRSTORAGE_H | 38 | #define MAILDIRSTORAGE_H |
39 | 39 | ||
40 | #include <libetpan/maildirdriver_types.h> | 40 | #include <libetpan/maildirdriver_types.h> |
41 | 41 | ||
42 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
43 | extern "C" { | 43 | extern "C" { |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | /* | 46 | /* |
47 | maildir_mailstorage_init is the constructor for a mbox storage. | 47 | maildir_mailstorage_init is the constructor for a maildir storage. |
48 | 48 | ||
49 | @param storage this is the storage to initialize. | 49 | @param storage this is the storage to initialize. |
50 | 50 | ||
51 | @param pathname is the directory that contains the mailbox. | 51 | @param pathname is the directory that contains the mailbox. |
52 | 52 | ||
53 | @param cached if this value is != 0, a persistant cache will be | 53 | @param cached if this value is != 0, a persistant cache will be |
54 | stored on local system. | 54 | stored on local system. |
55 | 55 | ||
56 | @param cache_directory is the location of the cache | 56 | @param cache_directory is the location of the cache |
57 | 57 | ||
58 | @param flags_directory is the location of the flags | 58 | @param flags_directory is the location of the flags |
59 | */ | 59 | */ |
60 | 60 | ||
61 | int maildir_mailstorage_init(struct mailstorage * storage, | 61 | int maildir_mailstorage_init(struct mailstorage * storage, |
62 | char * md_pathname, int md_cached, | 62 | char * md_pathname, int md_cached, |
63 | char * md_cache_directory, char * md_flags_directory); | 63 | char * md_cache_directory, char * md_flags_directory); |
64 | 64 | ||
65 | #ifdef __cplusplus | 65 | #ifdef __cplusplus |
66 | } | 66 | } |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | #endif | 69 | #endif |
diff --git a/kmicromail/libetpan/include/libetpan/maildriver.h b/kmicromail/libetpan/include/libetpan/maildriver.h index 7da9aea..c773190 100644 --- a/kmicromail/libetpan/include/libetpan/maildriver.h +++ b/kmicromail/libetpan/include/libetpan/maildriver.h | |||
@@ -371,64 +371,67 @@ int mailsession_lsub_folders(mailsession * session, char * mb, | |||
371 | 371 | ||
372 | int mailsession_subscribe_folder(mailsession * session, char * mb); | 372 | int mailsession_subscribe_folder(mailsession * session, char * mb); |
373 | 373 | ||
374 | /* | 374 | /* |
375 | NOTE: driver's specific should be used | 375 | NOTE: driver's specific should be used |
376 | 376 | ||
377 | mailsession_unsubscribe_folder unsubscribes to the given mailbox | 377 | mailsession_unsubscribe_folder unsubscribes to the given mailbox |
378 | 378 | ||
379 | @param session the session | 379 | @param session the session |
380 | @param mb the mailbox | 380 | @param mb the mailbox |
381 | 381 | ||
382 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 382 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
383 | on error | 383 | on error |
384 | */ | 384 | */ |
385 | 385 | ||
386 | int mailsession_unsubscribe_folder(mailsession * session, char * mb); | 386 | int mailsession_unsubscribe_folder(mailsession * session, char * mb); |
387 | 387 | ||
388 | /* | 388 | /* |
389 | mailsession_append_message adds a RFC 2822 message to the current | 389 | mailsession_append_message adds a RFC 2822 message to the current |
390 | given mailbox | 390 | given mailbox |
391 | 391 | ||
392 | @param session the session | 392 | @param session the session |
393 | @param message is a string that contains the RFC 2822 message | 393 | @param message is a string that contains the RFC 2822 message |
394 | @param size this is the size of the message | 394 | @param size this is the size of the message |
395 | 395 | ||
396 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 396 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
397 | on error | 397 | on error |
398 | */ | 398 | */ |
399 | 399 | ||
400 | int mailsession_append_message(mailsession * session, | 400 | int mailsession_append_message(mailsession * session, |
401 | char * message, size_t size); | 401 | char * message, size_t size); |
402 | 402 | ||
403 | int mailsession_append_message_flags(mailsession * session, | ||
404 | char * message, size_t size, struct mail_flags * flags); | ||
405 | |||
403 | /* | 406 | /* |
404 | NOTE: some drivers does not implement this | 407 | NOTE: some drivers does not implement this |
405 | 408 | ||
406 | mailsession_copy_message copies a message whose number is given to | 409 | mailsession_copy_message copies a message whose number is given to |
407 | a given mailbox. The mailbox must be accessible from the same session. | 410 | a given mailbox. The mailbox must be accessible from the same session. |
408 | 411 | ||
409 | @param session the session | 412 | @param session the session |
410 | @param num the message number | 413 | @param num the message number |
411 | @param mb the destination mailbox | 414 | @param mb the destination mailbox |
412 | 415 | ||
413 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 416 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
414 | on error | 417 | on error |
415 | */ | 418 | */ |
416 | 419 | ||
417 | int mailsession_copy_message(mailsession * session, | 420 | int mailsession_copy_message(mailsession * session, |
418 | uint32_t num, char * mb); | 421 | uint32_t num, char * mb); |
419 | 422 | ||
420 | /* | 423 | /* |
421 | NOTE: some drivers does not implement this | 424 | NOTE: some drivers does not implement this |
422 | 425 | ||
423 | mailsession_move_message copies a message whose number is given to | 426 | mailsession_move_message copies a message whose number is given to |
424 | a given mailbox. The mailbox must be accessible from the same session. | 427 | a given mailbox. The mailbox must be accessible from the same session. |
425 | 428 | ||
426 | @param session the session | 429 | @param session the session |
427 | @param num the message number | 430 | @param num the message number |
428 | @param mb the destination mailbox | 431 | @param mb the destination mailbox |
429 | 432 | ||
430 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned | 433 | @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned |
431 | on error | 434 | on error |
432 | */ | 435 | */ |
433 | 436 | ||
434 | int mailsession_move_message(mailsession * session, | 437 | int mailsession_move_message(mailsession * session, |
diff --git a/kmicromail/libetpan/include/libetpan/maildriver_types.h b/kmicromail/libetpan/include/libetpan/maildriver_types.h index 3ff9440..9eab4d6 100644 --- a/kmicromail/libetpan/include/libetpan/maildriver_types.h +++ b/kmicromail/libetpan/include/libetpan/maildriver_types.h | |||
@@ -478,64 +478,66 @@ struct mailsession_driver { | |||
478 | char * name, char ** result); | 478 | char * name, char ** result); |
479 | 479 | ||
480 | int (* sess_create_folder)(mailsession * session, char * mb); | 480 | int (* sess_create_folder)(mailsession * session, char * mb); |
481 | int (* sess_delete_folder)(mailsession * session, char * mb); | 481 | int (* sess_delete_folder)(mailsession * session, char * mb); |
482 | int (* sess_rename_folder)(mailsession * session, char * mb, | 482 | int (* sess_rename_folder)(mailsession * session, char * mb, |
483 | char * new_name); | 483 | char * new_name); |
484 | int (* sess_check_folder)(mailsession * session); | 484 | int (* sess_check_folder)(mailsession * session); |
485 | int (* sess_examine_folder)(mailsession * session, char * mb); | 485 | int (* sess_examine_folder)(mailsession * session, char * mb); |
486 | int (* sess_select_folder)(mailsession * session, char * mb); | 486 | int (* sess_select_folder)(mailsession * session, char * mb); |
487 | int (* sess_expunge_folder)(mailsession * session); | 487 | int (* sess_expunge_folder)(mailsession * session); |
488 | int (* sess_status_folder)(mailsession * session, char * mb, | 488 | int (* sess_status_folder)(mailsession * session, char * mb, |
489 | uint32_t * result_num, uint32_t * result_recent, | 489 | uint32_t * result_num, uint32_t * result_recent, |
490 | uint32_t * result_unseen); | 490 | uint32_t * result_unseen); |
491 | int (* sess_messages_number)(mailsession * session, char * mb, | 491 | int (* sess_messages_number)(mailsession * session, char * mb, |
492 | uint32_t * result); | 492 | uint32_t * result); |
493 | int (* sess_recent_number)(mailsession * session, char * mb, | 493 | int (* sess_recent_number)(mailsession * session, char * mb, |
494 | uint32_t * result); | 494 | uint32_t * result); |
495 | int (* sess_unseen_number)(mailsession * session, char * mb, | 495 | int (* sess_unseen_number)(mailsession * session, char * mb, |
496 | uint32_t * result); | 496 | uint32_t * result); |
497 | 497 | ||
498 | int (* sess_list_folders)(mailsession * session, char * mb, | 498 | int (* sess_list_folders)(mailsession * session, char * mb, |
499 | struct mail_list ** result); | 499 | struct mail_list ** result); |
500 | int (* sess_lsub_folders)(mailsession * session, char * mb, | 500 | int (* sess_lsub_folders)(mailsession * session, char * mb, |
501 | struct mail_list ** result); | 501 | struct mail_list ** result); |
502 | 502 | ||
503 | int (* sess_subscribe_folder)(mailsession * session, char * mb); | 503 | int (* sess_subscribe_folder)(mailsession * session, char * mb); |
504 | int (* sess_unsubscribe_folder)(mailsession * session, char * mb); | 504 | int (* sess_unsubscribe_folder)(mailsession * session, char * mb); |
505 | 505 | ||
506 | /* messages operations */ | 506 | /* messages operations */ |
507 | 507 | ||
508 | int (* sess_append_message)(mailsession * session, | 508 | int (* sess_append_message)(mailsession * session, |
509 | char * message, size_t size); | 509 | char * message, size_t size); |
510 | int (* sess_append_message_flags)(mailsession * session, | ||
511 | char * message, size_t size, struct mail_flags * flags); | ||
510 | int (* sess_copy_message)(mailsession * session, | 512 | int (* sess_copy_message)(mailsession * session, |
511 | uint32_t num, char * mb); | 513 | uint32_t num, char * mb); |
512 | int (* sess_move_message)(mailsession * session, | 514 | int (* sess_move_message)(mailsession * session, |
513 | uint32_t num, char * mb); | 515 | uint32_t num, char * mb); |
514 | 516 | ||
515 | int (* sess_get_message)(mailsession * session, | 517 | int (* sess_get_message)(mailsession * session, |
516 | uint32_t num, mailmessage ** result); | 518 | uint32_t num, mailmessage ** result); |
517 | 519 | ||
518 | int (* sess_get_message_by_uid)(mailsession * session, | 520 | int (* sess_get_message_by_uid)(mailsession * session, |
519 | const char * uid, mailmessage ** result); | 521 | const char * uid, mailmessage ** result); |
520 | 522 | ||
521 | int (* sess_get_messages_list)(mailsession * session, | 523 | int (* sess_get_messages_list)(mailsession * session, |
522 | struct mailmessage_list ** result); | 524 | struct mailmessage_list ** result); |
523 | int (* sess_get_envelopes_list)(mailsession * session, | 525 | int (* sess_get_envelopes_list)(mailsession * session, |
524 | struct mailmessage_list * env_list); | 526 | struct mailmessage_list * env_list); |
525 | int (* sess_remove_message)(mailsession * session, uint32_t num); | 527 | int (* sess_remove_message)(mailsession * session, uint32_t num); |
526 | #if 0 | 528 | #if 0 |
527 | int (* sess_search_messages)(mailsession * session, char * charset, | 529 | int (* sess_search_messages)(mailsession * session, char * charset, |
528 | struct mail_search_key * key, | 530 | struct mail_search_key * key, |
529 | struct mail_search_result ** result); | 531 | struct mail_search_result ** result); |
530 | #endif | 532 | #endif |
531 | }; | 533 | }; |
532 | 534 | ||
533 | 535 | ||
534 | /* | 536 | /* |
535 | session is the data structure for a mail session. | 537 | session is the data structure for a mail session. |
536 | 538 | ||
537 | - data is the internal data structure used by the driver | 539 | - data is the internal data structure used by the driver |
538 | It is called when initializing the mailsession structure. | 540 | It is called when initializing the mailsession structure. |
539 | 541 | ||
540 | - driver is the driver used for the session | 542 | - driver is the driver used for the session |
541 | */ | 543 | */ |
diff --git a/kmicromail/libetpan/include/libetpan/mailfolder.h b/kmicromail/libetpan/include/libetpan/mailfolder.h index 3ecad23..ff53470 100644 --- a/kmicromail/libetpan/include/libetpan/mailfolder.h +++ b/kmicromail/libetpan/include/libetpan/mailfolder.h | |||
@@ -1,32 +1,35 @@ | |||
1 | #ifndef MAILFOLDER_H | 1 | #ifndef MAILFOLDER_H |
2 | 2 | ||
3 | #define MAILFOLDER_H | 3 | #define MAILFOLDER_H |
4 | 4 | ||
5 | #include "mailstorage_types.h" | 5 | #include "mailstorage_types.h" |
6 | 6 | ||
7 | int mailfolder_noop(struct mailfolder * folder); | 7 | int mailfolder_noop(struct mailfolder * folder); |
8 | 8 | ||
9 | int mailfolder_check(struct mailfolder * folder); | 9 | int mailfolder_check(struct mailfolder * folder); |
10 | 10 | ||
11 | int mailfolder_expunge(struct mailfolder * folder); | 11 | int mailfolder_expunge(struct mailfolder * folder); |
12 | 12 | ||
13 | int mailfolder_status(struct mailfolder * folder, | 13 | int mailfolder_status(struct mailfolder * folder, |
14 | uint32_t * result_messages, uint32_t * result_recent, | 14 | uint32_t * result_messages, uint32_t * result_recent, |
15 | uint32_t * result_unseen); | 15 | uint32_t * result_unseen); |
16 | 16 | ||
17 | int mailfolder_append_message(struct mailfolder * folder, | 17 | int mailfolder_append_message(struct mailfolder * folder, |
18 | char * message, size_t size); | 18 | char * message, size_t size); |
19 | 19 | ||
20 | int mailfolder_append_message_flags(struct mailfolder * folder, | ||
21 | char * message, size_t size, struct mail_flags * flags); | ||
22 | |||
20 | int mailfolder_get_messages_list(struct mailfolder * folder, | 23 | int mailfolder_get_messages_list(struct mailfolder * folder, |
21 | struct mailmessage_list ** result); | 24 | struct mailmessage_list ** result); |
22 | 25 | ||
23 | int mailfolder_get_envelopes_list(struct mailfolder * folder, | 26 | int mailfolder_get_envelopes_list(struct mailfolder * folder, |
24 | struct mailmessage_list * result); | 27 | struct mailmessage_list * result); |
25 | 28 | ||
26 | int mailfolder_get_message(struct mailfolder * folder, | 29 | int mailfolder_get_message(struct mailfolder * folder, |
27 | uint32_t num, mailmessage ** result); | 30 | uint32_t num, mailmessage ** result); |
28 | 31 | ||
29 | int mailfolder_get_message_by_uid(struct mailfolder * folder, | 32 | int mailfolder_get_message_by_uid(struct mailfolder * folder, |
30 | const char * uid, mailmessage ** result); | 33 | const char * uid, mailmessage ** result); |
31 | 34 | ||
32 | #endif | 35 | #endif |
diff --git a/kmicromail/libetpan/include/libetpan/mailmbox.h b/kmicromail/libetpan/include/libetpan/mailmbox.h index 8be086c..0427f1f 100644 --- a/kmicromail/libetpan/include/libetpan/mailmbox.h +++ b/kmicromail/libetpan/include/libetpan/mailmbox.h | |||
@@ -22,64 +22,68 @@ | |||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef MAILMBOX_H | 36 | #ifndef MAILMBOX_H |
37 | 37 | ||
38 | #define MAILMBOX_H | 38 | #define MAILMBOX_H |
39 | 39 | ||
40 | #ifdef __cplusplus | 40 | #ifdef __cplusplus |
41 | extern "C" { | 41 | extern "C" { |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | #include <libetpan/mailmbox_types.h> | 44 | #include <libetpan/mailmbox_types.h> |
45 | 45 | ||
46 | int | 46 | int |
47 | mailmbox_append_message_list(struct mailmbox_folder * folder, | 47 | mailmbox_append_message_list(struct mailmbox_folder * folder, |
48 | carray * append_tab); | 48 | carray * append_tab); |
49 | 49 | ||
50 | int | 50 | int |
51 | mailmbox_append_message(struct mailmbox_folder * folder, | 51 | mailmbox_append_message(struct mailmbox_folder * folder, |
52 | const char * data, size_t len); | 52 | const char * data, size_t len); |
53 | 53 | ||
54 | int | ||
55 | mailmbox_append_message_uid(struct mailmbox_folder * folder, | ||
56 | const char * data, size_t len, unsigned int * puid); | ||
57 | |||
54 | int mailmbox_fetch_msg(struct mailmbox_folder * folder, | 58 | int mailmbox_fetch_msg(struct mailmbox_folder * folder, |
55 | uint32_t num, char ** result, | 59 | uint32_t num, char ** result, |
56 | size_t * result_len); | 60 | size_t * result_len); |
57 | 61 | ||
58 | int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder, | 62 | int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder, |
59 | uint32_t num, char ** result, | 63 | uint32_t num, char ** result, |
60 | size_t * result_len); | 64 | size_t * result_len); |
61 | 65 | ||
62 | void mailmbox_fetch_result_free(char * msg); | 66 | void mailmbox_fetch_result_free(char * msg); |
63 | 67 | ||
64 | int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder, | 68 | int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder, |
65 | struct mailmbox_folder * src_folder, | 69 | struct mailmbox_folder * src_folder, |
66 | carray * tab); | 70 | carray * tab); |
67 | 71 | ||
68 | int mailmbox_copy_msg(struct mailmbox_folder * dest_folder, | 72 | int mailmbox_copy_msg(struct mailmbox_folder * dest_folder, |
69 | struct mailmbox_folder * src_folder, | 73 | struct mailmbox_folder * src_folder, |
70 | uint32_t uid); | 74 | uint32_t uid); |
71 | 75 | ||
72 | int mailmbox_expunge(struct mailmbox_folder * folder); | 76 | int mailmbox_expunge(struct mailmbox_folder * folder); |
73 | 77 | ||
74 | int mailmbox_delete_msg(struct mailmbox_folder * folder, uint32_t uid); | 78 | int mailmbox_delete_msg(struct mailmbox_folder * folder, uint32_t uid); |
75 | 79 | ||
76 | int mailmbox_init(const char * filename, | 80 | int mailmbox_init(const char * filename, |
77 | int force_readonly, | 81 | int force_readonly, |
78 | int force_no_uid, | 82 | int force_no_uid, |
79 | uint32_t default_written_uid, | 83 | uint32_t default_written_uid, |
80 | struct mailmbox_folder ** result_folder); | 84 | struct mailmbox_folder ** result_folder); |
81 | 85 | ||
82 | void mailmbox_done(struct mailmbox_folder * folder); | 86 | void mailmbox_done(struct mailmbox_folder * folder); |
83 | 87 | ||
84 | /* low-level access primitives */ | 88 | /* low-level access primitives */ |
85 | 89 | ||
diff --git a/kmicromail/libetpan/include/libetpan/mailmbox_types.h b/kmicromail/libetpan/include/libetpan/mailmbox_types.h index dd6758c..bd6ee30 100644 --- a/kmicromail/libetpan/include/libetpan/mailmbox_types.h +++ b/kmicromail/libetpan/include/libetpan/mailmbox_types.h | |||
@@ -99,44 +99,45 @@ struct mailmbox_msg_info { | |||
99 | 99 | ||
100 | size_t msg_headers; | 100 | size_t msg_headers; |
101 | size_t msg_headers_len; | 101 | size_t msg_headers_len; |
102 | 102 | ||
103 | size_t msg_body; | 103 | size_t msg_body; |
104 | size_t msg_body_len; | 104 | size_t msg_body_len; |
105 | 105 | ||
106 | size_t msg_size; | 106 | size_t msg_size; |
107 | 107 | ||
108 | size_t msg_padding; | 108 | size_t msg_padding; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
112 | int mailmbox_msg_info_update(struct mailmbox_folder * folder, | 112 | int mailmbox_msg_info_update(struct mailmbox_folder * folder, |
113 | size_t msg_start, size_t msg_start_len, | 113 | size_t msg_start, size_t msg_start_len, |
114 | size_t msg_headers, size_t msg_headers_len, | 114 | size_t msg_headers, size_t msg_headers_len, |
115 | size_t msg_body, size_t msg_body_len, | 115 | size_t msg_body, size_t msg_body_len, |
116 | size_t msg_size, size_t msg_padding, | 116 | size_t msg_size, size_t msg_padding, |
117 | uint32_t msg_uid); | 117 | uint32_t msg_uid); |
118 | 118 | ||
119 | struct mailmbox_msg_info * | 119 | struct mailmbox_msg_info * |
120 | mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len, | 120 | mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len, |
121 | size_t msg_headers, size_t msg_headers_len, | 121 | size_t msg_headers, size_t msg_headers_len, |
122 | size_t msg_body, size_t msg_body_len, | 122 | size_t msg_body, size_t msg_body_len, |
123 | size_t msg_size, size_t msg_padding, | 123 | size_t msg_size, size_t msg_padding, |
124 | uint32_t msg_uid); | 124 | uint32_t msg_uid); |
125 | 125 | ||
126 | void mailmbox_msg_info_free(struct mailmbox_msg_info * info); | 126 | void mailmbox_msg_info_free(struct mailmbox_msg_info * info); |
127 | 127 | ||
128 | struct mailmbox_append_info { | 128 | struct mailmbox_append_info { |
129 | const char * ai_message; | 129 | const char * ai_message; |
130 | size_t ai_size; | 130 | size_t ai_size; |
131 | unsigned int ai_uid; | ||
131 | }; | 132 | }; |
132 | 133 | ||
133 | struct mailmbox_append_info * | 134 | struct mailmbox_append_info * |
134 | mailmbox_append_info_new(const char * ai_message, size_t ai_size); | 135 | mailmbox_append_info_new(const char * ai_message, size_t ai_size); |
135 | 136 | ||
136 | void mailmbox_append_info_free(struct mailmbox_append_info * info); | 137 | void mailmbox_append_info_free(struct mailmbox_append_info * info); |
137 | 138 | ||
138 | #ifdef __cplusplus | 139 | #ifdef __cplusplus |
139 | } | 140 | } |
140 | #endif | 141 | #endif |
141 | 142 | ||
142 | #endif | 143 | #endif |
diff --git a/kmicromail/libetpan/include/libetpan/mailmh.h b/kmicromail/libetpan/include/libetpan/mailmh.h index 40432cb..00199b8 100644 --- a/kmicromail/libetpan/include/libetpan/mailmh.h +++ b/kmicromail/libetpan/include/libetpan/mailmh.h | |||
@@ -90,54 +90,61 @@ struct mailmh_folder { | |||
90 | struct mailmh * mailmh_new(const char * foldername); | 90 | struct mailmh * mailmh_new(const char * foldername); |
91 | void mailmh_free(struct mailmh * f); | 91 | void mailmh_free(struct mailmh * f); |
92 | 92 | ||
93 | struct mailmh_msg_info * | 93 | struct mailmh_msg_info * |
94 | mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime); | 94 | mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime); |
95 | void mailmh_msg_info_free(struct mailmh_msg_info * msg_info); | 95 | void mailmh_msg_info_free(struct mailmh_msg_info * msg_info); |
96 | 96 | ||
97 | struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent, | 97 | struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent, |
98 | const char * name); | 98 | const char * name); |
99 | void mailmh_folder_free(struct mailmh_folder * folder); | 99 | void mailmh_folder_free(struct mailmh_folder * folder); |
100 | 100 | ||
101 | int mailmh_folder_add_subfolder(struct mailmh_folder * parent, | 101 | int mailmh_folder_add_subfolder(struct mailmh_folder * parent, |
102 | const char * name); | 102 | const char * name); |
103 | 103 | ||
104 | struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root, | 104 | struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root, |
105 | const char * filename); | 105 | const char * filename); |
106 | 106 | ||
107 | int mailmh_folder_remove_subfolder(struct mailmh_folder * folder); | 107 | int mailmh_folder_remove_subfolder(struct mailmh_folder * folder); |
108 | 108 | ||
109 | int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder, | 109 | int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder, |
110 | struct mailmh_folder * dst_folder, | 110 | struct mailmh_folder * dst_folder, |
111 | const char * new_name); | 111 | const char * new_name); |
112 | 112 | ||
113 | int mailmh_folder_get_message_filename(struct mailmh_folder * folder, | 113 | int mailmh_folder_get_message_filename(struct mailmh_folder * folder, |
114 | uint32_t index, char ** result); | 114 | uint32_t index, char ** result); |
115 | 115 | ||
116 | int mailmh_folder_get_message_fd(struct mailmh_folder * folder, | 116 | int mailmh_folder_get_message_fd(struct mailmh_folder * folder, |
117 | uint32_t index, int flags, int * result); | 117 | uint32_t index, int flags, int * result); |
118 | 118 | ||
119 | int mailmh_folder_get_message_size(struct mailmh_folder * folder, | 119 | int mailmh_folder_get_message_size(struct mailmh_folder * folder, |
120 | uint32_t index, size_t * result); | 120 | uint32_t index, size_t * result); |
121 | 121 | ||
122 | int mailmh_folder_add_message_uid(struct mailmh_folder * folder, | ||
123 | const char * message, size_t size, | ||
124 | uint32_t * pindex); | ||
125 | |||
122 | int mailmh_folder_add_message(struct mailmh_folder * folder, | 126 | int mailmh_folder_add_message(struct mailmh_folder * folder, |
123 | const char * message, size_t size); | 127 | const char * message, size_t size); |
124 | 128 | ||
129 | int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder, | ||
130 | int fd, uint32_t * pindex); | ||
131 | |||
125 | int mailmh_folder_add_message_file(struct mailmh_folder * folder, | 132 | int mailmh_folder_add_message_file(struct mailmh_folder * folder, |
126 | int fd); | 133 | int fd); |
127 | 134 | ||
128 | int mailmh_folder_remove_message(struct mailmh_folder * folder, | 135 | int mailmh_folder_remove_message(struct mailmh_folder * folder, |
129 | uint32_t index); | 136 | uint32_t index); |
130 | 137 | ||
131 | int mailmh_folder_move_message(struct mailmh_folder * dest_folder, | 138 | int mailmh_folder_move_message(struct mailmh_folder * dest_folder, |
132 | struct mailmh_folder * src_folder, | 139 | struct mailmh_folder * src_folder, |
133 | uint32_t index); | 140 | uint32_t index); |
134 | 141 | ||
135 | int mailmh_folder_update(struct mailmh_folder * folder); | 142 | int mailmh_folder_update(struct mailmh_folder * folder); |
136 | 143 | ||
137 | unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder); | 144 | unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder); |
138 | 145 | ||
139 | #ifdef __cplusplus | 146 | #ifdef __cplusplus |
140 | } | 147 | } |
141 | #endif | 148 | #endif |
142 | 149 | ||
143 | #endif | 150 | #endif |
diff --git a/kmicromail/libetpan/include/libetpan/mailstorage.h b/kmicromail/libetpan/include/libetpan/mailstorage.h index d56aef1..4c57883 100644 --- a/kmicromail/libetpan/include/libetpan/mailstorage.h +++ b/kmicromail/libetpan/include/libetpan/mailstorage.h | |||
@@ -42,57 +42,58 @@ | |||
42 | 42 | ||
43 | #ifdef __cplusplus | 43 | #ifdef __cplusplus |
44 | extern "C" { | 44 | extern "C" { |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | /* storage */ | 47 | /* storage */ |
48 | 48 | ||
49 | /* | 49 | /* |
50 | mailstorage_new | 50 | mailstorage_new |
51 | 51 | ||
52 | This function creates an empty storage. This storage have to be initialized. | 52 | This function creates an empty storage. This storage have to be initialized. |
53 | The "driver" and "data" fields should be initialized. | 53 | The "driver" and "data" fields should be initialized. |
54 | 54 | ||
55 | @param id is the name of the storage. It can be NULL. | 55 | @param id is the name of the storage. It can be NULL. |
56 | The given parameter is no more needed when the creation is finished. | 56 | The given parameter is no more needed when the creation is finished. |
57 | The given string is duplicated. | 57 | The given string is duplicated. |
58 | 58 | ||
59 | @return The mail storage is returned. | 59 | @return The mail storage is returned. |
60 | */ | 60 | */ |
61 | 61 | ||
62 | struct mailstorage * mailstorage_new(char * sto_id); | 62 | struct mailstorage * mailstorage_new(char * sto_id); |
63 | 63 | ||
64 | void mailstorage_free(struct mailstorage * storage); | 64 | void mailstorage_free(struct mailstorage * storage); |
65 | 65 | ||
66 | /* | 66 | /* |
67 | session will be initialized on success. | 67 | session will be initialized on success. |
68 | */ | 68 | */ |
69 | 69 | ||
70 | int mailstorage_connect(struct mailstorage * storage); | 70 | int mailstorage_connect(struct mailstorage * storage); |
71 | 71 | ||
72 | void mailstorage_disconnect(struct mailstorage * storage); | 72 | void mailstorage_disconnect(struct mailstorage * storage); |
73 | 73 | ||
74 | int mailstorage_noop(struct mailstorage * storage); | ||
75 | |||
74 | 76 | ||
75 | /* folder */ | 77 | /* folder */ |
76 | 78 | ||
77 | struct mailfolder * mailfolder_new(struct mailstorage * fld_storage, | 79 | struct mailfolder * mailfolder_new(struct mailstorage * fld_storage, |
78 | char * fld_pathname, char * fld_virtual_name); | 80 | char * fld_pathname, char * fld_virtual_name); |
79 | 81 | ||
80 | void mailfolder_free(struct mailfolder * folder); | 82 | void mailfolder_free(struct mailfolder * folder); |
81 | 83 | ||
82 | int mailfolder_add_child(struct mailfolder * parent, | 84 | int mailfolder_add_child(struct mailfolder * parent, |
83 | struct mailfolder * child); | 85 | struct mailfolder * child); |
84 | 86 | ||
85 | int mailfolder_detach_parent(struct mailfolder * folder); | 87 | int mailfolder_detach_parent(struct mailfolder * folder); |
86 | 88 | ||
87 | int mailfolder_connect(struct mailfolder * folder); | 89 | int mailfolder_connect(struct mailfolder * folder); |
88 | 90 | ||
89 | void mailfolder_disconnect(struct mailfolder * folder); | 91 | void mailfolder_disconnect(struct mailfolder * folder); |
90 | 92 | ||
91 | |||
92 | #ifdef __cplusplus | 93 | #ifdef __cplusplus |
93 | } | 94 | } |
94 | #endif | 95 | #endif |
95 | 96 | ||
96 | #endif | 97 | #endif |
97 | 98 | ||
98 | 99 | ||
diff --git a/kmicromail/libetpan/maildir/maildir.c b/kmicromail/libetpan/maildir/maildir.c index 320ef81..0e038b1 100644 --- a/kmicromail/libetpan/maildir/maildir.c +++ b/kmicromail/libetpan/maildir/maildir.c | |||
@@ -401,88 +401,90 @@ int maildir_update(struct maildir * md) | |||
401 | 401 | ||
402 | free: | 402 | free: |
403 | maildir_flush(md, 0); | 403 | maildir_flush(md, 0); |
404 | maildir_flush(md, 1); | 404 | maildir_flush(md, 1); |
405 | md->mdir_mtime_cur = (time_t) -1; | 405 | md->mdir_mtime_cur = (time_t) -1; |
406 | md->mdir_mtime_new = (time_t) -1; | 406 | md->mdir_mtime_new = (time_t) -1; |
407 | return res; | 407 | return res; |
408 | } | 408 | } |
409 | 409 | ||
410 | #ifndef LIBETPAN_SYSTEM_BASENAME | 410 | #ifndef LIBETPAN_SYSTEM_BASENAME |
411 | static char * libetpan_basename(char * filename) | 411 | static char * libetpan_basename(char * filename) |
412 | { | 412 | { |
413 | char * next; | 413 | char * next; |
414 | char * p; | 414 | char * p; |
415 | 415 | ||
416 | p = filename; | 416 | p = filename; |
417 | next = strchr(p, '/'); | 417 | next = strchr(p, '/'); |
418 | 418 | ||
419 | while (next != NULL) { | 419 | while (next != NULL) { |
420 | p = next; | 420 | p = next; |
421 | next = strchr(p + 1, '/'); | 421 | next = strchr(p + 1, '/'); |
422 | } | 422 | } |
423 | 423 | ||
424 | if (p == filename) | 424 | if (p == filename) |
425 | return filename; | 425 | return filename; |
426 | else | 426 | else |
427 | return p + 1; | 427 | return p + 1; |
428 | } | 428 | } |
429 | #else | 429 | #else |
430 | #define libetpan_basename(a) basename(a) | 430 | #define libetpan_basename(a) basename(a) |
431 | #endif | 431 | #endif |
432 | 432 | ||
433 | int maildir_message_add(struct maildir * md, | 433 | int maildir_message_add_uid(struct maildir * md, |
434 | const char * message, size_t size) | 434 | const char * message, size_t size, |
435 | char * uid, size_t max_uid_len) | ||
435 | { | 436 | { |
436 | char path_new[PATH_MAX]; | 437 | char path_new[PATH_MAX]; |
437 | char tmpname[PATH_MAX]; | 438 | char tmpname[PATH_MAX]; |
438 | int fd; | 439 | int fd; |
439 | int r; | 440 | int r; |
440 | char * mapping; | 441 | char * mapping; |
441 | char * delivery_tmp_name; | 442 | char * delivery_tmp_name; |
442 | char * delivery_tmp_basename; | 443 | char * delivery_tmp_basename; |
443 | char delivery_new_name[PATH_MAX]; | 444 | char delivery_new_name[PATH_MAX]; |
444 | char * delivery_new_basename; | 445 | char * delivery_new_basename; |
445 | int res; | 446 | int res; |
446 | struct stat stat_info; | 447 | struct stat stat_info; |
447 | 448 | ||
448 | r = maildir_update(md); | 449 | r = maildir_update(md); |
449 | if (r != MAILDIR_NO_ERROR) { | 450 | if (r != MAILDIR_NO_ERROR) { |
450 | res = r; | 451 | res = r; |
451 | goto err; | 452 | goto err; |
452 | } | 453 | } |
453 | 454 | ||
454 | /* write to tmp/ with a classic temporary file */ | 455 | /* write to tmp/ with a classic temporary file */ |
455 | 456 | ||
456 | snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX", md->mdir_path); | 457 | snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX", |
458 | md->mdir_path); | ||
457 | fd = mkstemp(tmpname); | 459 | fd = mkstemp(tmpname); |
458 | if (fd < 0) { | 460 | if (fd < 0) { |
459 | res = MAILDIR_ERROR_FILE; | 461 | res = MAILDIR_ERROR_FILE; |
460 | goto err; | 462 | goto err; |
461 | } | 463 | } |
462 | 464 | ||
463 | r = ftruncate(fd, size); | 465 | r = ftruncate(fd, size); |
464 | if (r < 0) { | 466 | if (r < 0) { |
465 | res = MAILDIR_ERROR_FILE; | 467 | res = MAILDIR_ERROR_FILE; |
466 | goto close; | 468 | goto close; |
467 | } | 469 | } |
468 | 470 | ||
469 | mapping = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | 471 | mapping = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
470 | if (mapping == MAP_FAILED) { | 472 | if (mapping == MAP_FAILED) { |
471 | res = MAILDIR_ERROR_FILE; | 473 | res = MAILDIR_ERROR_FILE; |
472 | goto close; | 474 | goto close; |
473 | } | 475 | } |
474 | 476 | ||
475 | memcpy(mapping, message, size); | 477 | memcpy(mapping, message, size); |
476 | 478 | ||
477 | msync(mapping, size, MS_SYNC); | 479 | msync(mapping, size, MS_SYNC); |
478 | munmap(mapping, size); | 480 | munmap(mapping, size); |
479 | 481 | ||
480 | close(fd); | 482 | close(fd); |
481 | 483 | ||
482 | /* write to tmp/ with maildir standard name */ | 484 | /* write to tmp/ with maildir standard name */ |
483 | 485 | ||
484 | delivery_tmp_name = maildir_get_new_message_filename(md, tmpname); | 486 | delivery_tmp_name = maildir_get_new_message_filename(md, tmpname); |
485 | if (delivery_tmp_name == NULL) { | 487 | if (delivery_tmp_name == NULL) { |
486 | res = MAILDIR_ERROR_FILE; | 488 | res = MAILDIR_ERROR_FILE; |
487 | goto unlink; | 489 | goto unlink; |
488 | } | 490 | } |
@@ -492,102 +494,119 @@ int maildir_message_add(struct maildir * md, | |||
492 | strncpy(tmpname, delivery_tmp_name, sizeof(tmpname)); | 494 | strncpy(tmpname, delivery_tmp_name, sizeof(tmpname)); |
493 | tmpname[sizeof(tmpname) - 1] = '\0'; | 495 | tmpname[sizeof(tmpname) - 1] = '\0'; |
494 | 496 | ||
495 | delivery_tmp_basename = libetpan_basename(tmpname); | 497 | delivery_tmp_basename = libetpan_basename(tmpname); |
496 | 498 | ||
497 | snprintf(delivery_new_name, sizeof(delivery_new_name), "%s/new/%s", | 499 | snprintf(delivery_new_name, sizeof(delivery_new_name), "%s/new/%s", |
498 | md->mdir_path, delivery_tmp_basename); | 500 | md->mdir_path, delivery_tmp_basename); |
499 | 501 | ||
500 | r = link(delivery_tmp_name, delivery_new_name); | 502 | r = link(delivery_tmp_name, delivery_new_name); |
501 | if (r < 0) { | 503 | if (r < 0) { |
502 | res = MAILDIR_ERROR_FILE; | 504 | res = MAILDIR_ERROR_FILE; |
503 | goto unlink_tmp; | 505 | goto unlink_tmp; |
504 | } | 506 | } |
505 | 507 | ||
506 | snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path); | 508 | snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path); |
507 | r = stat(path_new, &stat_info); | 509 | r = stat(path_new, &stat_info); |
508 | if (r < 0) { | 510 | if (r < 0) { |
509 | unlink(delivery_new_name); | 511 | unlink(delivery_new_name); |
510 | res = MAILDIR_ERROR_FILE; | 512 | res = MAILDIR_ERROR_FILE; |
511 | goto unlink_tmp; | 513 | goto unlink_tmp; |
512 | } | 514 | } |
513 | 515 | ||
514 | md->mdir_mtime_new = stat_info.st_mtime; | 516 | md->mdir_mtime_new = stat_info.st_mtime; |
515 | 517 | ||
516 | delivery_new_basename = libetpan_basename(delivery_new_name); | 518 | delivery_new_basename = libetpan_basename(delivery_new_name); |
517 | 519 | ||
518 | r = add_message(md, delivery_new_basename, 1); | 520 | r = add_message(md, delivery_new_basename, 1); |
519 | if (r != MAILDIR_NO_ERROR) { | 521 | if (r != MAILDIR_NO_ERROR) { |
520 | unlink(delivery_new_name); | 522 | unlink(delivery_new_name); |
521 | res = MAILDIR_ERROR_FILE; | 523 | res = MAILDIR_ERROR_FILE; |
522 | goto unlink_tmp; | 524 | goto unlink_tmp; |
523 | } | 525 | } |
524 | 526 | ||
527 | if (uid != NULL) | ||
528 | strncpy(uid, delivery_new_basename, max_uid_len); | ||
529 | |||
525 | unlink(delivery_tmp_name); | 530 | unlink(delivery_tmp_name); |
526 | free(delivery_tmp_name); | 531 | free(delivery_tmp_name); |
527 | 532 | ||
528 | return MAILDIR_NO_ERROR; | 533 | return MAILDIR_NO_ERROR; |
529 | 534 | ||
530 | unlink_tmp: | 535 | unlink_tmp: |
531 | unlink(delivery_tmp_name); | 536 | unlink(delivery_tmp_name); |
532 | free(delivery_tmp_name); | 537 | free(delivery_tmp_name); |
533 | goto err; | 538 | goto err; |
534 | close: | 539 | close: |
535 | close(fd); | 540 | close(fd); |
536 | unlink: | 541 | unlink: |
537 | unlink(tmpname); | 542 | unlink(tmpname); |
538 | err: | 543 | err: |
539 | return res; | 544 | return res; |
540 | } | 545 | } |
541 | 546 | ||
542 | int maildir_message_add_file(struct maildir * md, int fd) | 547 | int maildir_message_add(struct maildir * md, |
548 | const char * message, size_t size) | ||
549 | { | ||
550 | return maildir_message_add_uid(md, message, size, | ||
551 | NULL, 0); | ||
552 | } | ||
553 | |||
554 | int maildir_message_add_file_uid(struct maildir * md, int fd, | ||
555 | char * uid, size_t max_uid_len) | ||
543 | { | 556 | { |
544 | char * message; | 557 | char * message; |
545 | struct stat buf; | 558 | struct stat buf; |
546 | int r; | 559 | int r; |
547 | 560 | ||
548 | if (fstat(fd, &buf) == -1) | 561 | if (fstat(fd, &buf) == -1) |
549 | return MAILDIR_ERROR_FILE; | 562 | return MAILDIR_ERROR_FILE; |
550 | 563 | ||
551 | message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | 564 | message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
552 | if (message == MAP_FAILED) | 565 | if (message == MAP_FAILED) |
553 | return MAILDIR_ERROR_FILE; | 566 | return MAILDIR_ERROR_FILE; |
554 | 567 | ||
555 | r = maildir_message_add(md, message, buf.st_size); | 568 | r = maildir_message_add_uid(md, message, buf.st_size, uid, max_uid_len); |
556 | 569 | ||
557 | munmap(message, buf.st_size); | 570 | munmap(message, buf.st_size); |
558 | 571 | ||
559 | return r; | 572 | return r; |
560 | } | 573 | } |
561 | 574 | ||
575 | int maildir_message_add_file(struct maildir * md, int fd) | ||
576 | { | ||
577 | return maildir_message_add_file_uid(md, fd, | ||
578 | NULL, 0); | ||
579 | } | ||
580 | |||
562 | char * maildir_message_get(struct maildir * md, const char * uid) | 581 | char * maildir_message_get(struct maildir * md, const char * uid) |
563 | { | 582 | { |
564 | chashdatum key; | 583 | chashdatum key; |
565 | chashdatum value; | 584 | chashdatum value; |
566 | char filename[PATH_MAX]; | 585 | char filename[PATH_MAX]; |
567 | char * dup_filename; | 586 | char * dup_filename; |
568 | struct maildir_msg * msg; | 587 | struct maildir_msg * msg; |
569 | char * dir; | 588 | char * dir; |
570 | int r; | 589 | int r; |
571 | 590 | ||
572 | key.data = (void *) uid; | 591 | key.data = (void *) uid; |
573 | key.len = strlen(uid); | 592 | key.len = strlen(uid); |
574 | r = chash_get(md->mdir_msg_hash, &key, &value); | 593 | r = chash_get(md->mdir_msg_hash, &key, &value); |
575 | if (r < 0) | 594 | if (r < 0) |
576 | return NULL; | 595 | return NULL; |
577 | 596 | ||
578 | msg = value.data; | 597 | msg = value.data; |
579 | if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) | 598 | if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) |
580 | dir = "new"; | 599 | dir = "new"; |
581 | else | 600 | else |
582 | dir = "cur"; | 601 | dir = "cur"; |
583 | 602 | ||
584 | snprintf(filename, sizeof(filename), "%s/%s/%s", | 603 | snprintf(filename, sizeof(filename), "%s/%s/%s", |
585 | md->mdir_path, dir, msg->msg_filename); | 604 | md->mdir_path, dir, msg->msg_filename); |
586 | 605 | ||
587 | dup_filename = strdup(filename); | 606 | dup_filename = strdup(filename); |
588 | if (dup_filename == NULL) | 607 | if (dup_filename == NULL) |
589 | return NULL; | 608 | return NULL; |
590 | 609 | ||
591 | return dup_filename; | 610 | return dup_filename; |
592 | } | 611 | } |
593 | 612 | ||
diff --git a/kmicromail/libetpan/maildir/maildir.h b/kmicromail/libetpan/maildir/maildir.h index b782484..268dda1 100644 --- a/kmicromail/libetpan/maildir/maildir.h +++ b/kmicromail/libetpan/maildir/maildir.h | |||
@@ -16,45 +16,52 @@ | |||
16 | * contributors may be used to endorse or promote products derived | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef MAILDIR_H | 36 | #ifndef MAILDIR_H |
37 | 37 | ||
38 | #define MAILDIR_H | 38 | #define MAILDIR_H |
39 | 39 | ||
40 | #include <libetpan/maildir_types.h> | 40 | #include <libetpan/maildir_types.h> |
41 | 41 | ||
42 | struct maildir * maildir_new(const char * path); | 42 | struct maildir * maildir_new(const char * path); |
43 | 43 | ||
44 | void maildir_free(struct maildir * md); | 44 | void maildir_free(struct maildir * md); |
45 | 45 | ||
46 | int maildir_update(struct maildir * md); | 46 | int maildir_update(struct maildir * md); |
47 | 47 | ||
48 | int maildir_message_add_uid(struct maildir * md, | ||
49 | const char * message, size_t size, | ||
50 | char * uid, size_t max_uid_len); | ||
51 | |||
48 | int maildir_message_add(struct maildir * md, | 52 | int maildir_message_add(struct maildir * md, |
49 | const char * message, size_t size); | 53 | const char * message, size_t size); |
50 | 54 | ||
55 | int maildir_message_add_file_uid(struct maildir * md, int fd, | ||
56 | char * uid, size_t max_uid_len); | ||
57 | |||
51 | int maildir_message_add_file(struct maildir * md, int fd); | 58 | int maildir_message_add_file(struct maildir * md, int fd); |
52 | 59 | ||
53 | char * maildir_message_get(struct maildir * md, const char * uid); | 60 | char * maildir_message_get(struct maildir * md, const char * uid); |
54 | 61 | ||
55 | int maildir_message_remove(struct maildir * md, const char * uid); | 62 | int maildir_message_remove(struct maildir * md, const char * uid); |
56 | 63 | ||
57 | int maildir_message_change_flags(struct maildir * md, | 64 | int maildir_message_change_flags(struct maildir * md, |
58 | const char * uid, int new_flags); | 65 | const char * uid, int new_flags); |
59 | 66 | ||
60 | #endif | 67 | #endif |
diff --git a/kmicromail/libetpan/mbox/mailmbox.c b/kmicromail/libetpan/mbox/mailmbox.c index 280c313..b3fce02 100644 --- a/kmicromail/libetpan/mbox/mailmbox.c +++ b/kmicromail/libetpan/mbox/mailmbox.c | |||
@@ -168,64 +168,67 @@ void mailmbox_unmap(struct mailmbox_folder * folder) | |||
168 | { | 168 | { |
169 | munmap(folder->mb_mapping, folder->mb_mapping_size); | 169 | munmap(folder->mb_mapping, folder->mb_mapping_size); |
170 | folder->mb_mapping = NULL; | 170 | folder->mb_mapping = NULL; |
171 | folder->mb_mapping_size = 0; | 171 | folder->mb_mapping_size = 0; |
172 | } | 172 | } |
173 | 173 | ||
174 | void mailmbox_sync(struct mailmbox_folder * folder) | 174 | void mailmbox_sync(struct mailmbox_folder * folder) |
175 | { | 175 | { |
176 | msync(folder->mb_mapping, folder->mb_mapping_size, MS_SYNC); | 176 | msync(folder->mb_mapping, folder->mb_mapping_size, MS_SYNC); |
177 | } | 177 | } |
178 | 178 | ||
179 | void mailmbox_timestamp(struct mailmbox_folder * folder) | 179 | void mailmbox_timestamp(struct mailmbox_folder * folder) |
180 | { | 180 | { |
181 | int r; | 181 | int r; |
182 | struct stat buf; | 182 | struct stat buf; |
183 | 183 | ||
184 | r = stat(folder->mb_filename, &buf); | 184 | r = stat(folder->mb_filename, &buf); |
185 | if (r < 0) | 185 | if (r < 0) |
186 | folder->mb_mtime = (time_t) -1; | 186 | folder->mb_mtime = (time_t) -1; |
187 | else | 187 | else |
188 | folder->mb_mtime = buf.st_mtime; | 188 | folder->mb_mtime = buf.st_mtime; |
189 | } | 189 | } |
190 | 190 | ||
191 | /* | 191 | /* |
192 | open the file | 192 | open the file |
193 | */ | 193 | */ |
194 | 194 | ||
195 | int mailmbox_open(struct mailmbox_folder * folder) | 195 | int mailmbox_open(struct mailmbox_folder * folder) |
196 | { | 196 | { |
197 | int fd; | 197 | int fd; |
198 | int read_only; | 198 | int read_only; |
199 | 199 | ||
200 | fd = -1; | ||
201 | read_only = TRUE; | ||
202 | |||
200 | if (!folder->mb_read_only) { | 203 | if (!folder->mb_read_only) { |
201 | read_only = FALSE; | 204 | read_only = FALSE; |
202 | fd = open(folder->mb_filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); | 205 | fd = open(folder->mb_filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); |
203 | } | 206 | } |
204 | 207 | ||
205 | if (folder->mb_read_only || (fd < 0)) { | 208 | if (folder->mb_read_only || (fd < 0)) { |
206 | read_only = TRUE; | 209 | read_only = TRUE; |
207 | fd = open(folder->mb_filename, O_RDONLY); | 210 | fd = open(folder->mb_filename, O_RDONLY); |
208 | if (fd < 0) | 211 | if (fd < 0) |
209 | return MAILMBOX_ERROR_FILE_NOT_FOUND; | 212 | return MAILMBOX_ERROR_FILE_NOT_FOUND; |
210 | } | 213 | } |
211 | 214 | ||
212 | folder->mb_fd = fd; | 215 | folder->mb_fd = fd; |
213 | folder->mb_read_only = read_only; | 216 | folder->mb_read_only = read_only; |
214 | 217 | ||
215 | return MAILMBOX_NO_ERROR; | 218 | return MAILMBOX_NO_ERROR; |
216 | } | 219 | } |
217 | 220 | ||
218 | /* | 221 | /* |
219 | close the file | 222 | close the file |
220 | */ | 223 | */ |
221 | 224 | ||
222 | void mailmbox_close(struct mailmbox_folder * folder) | 225 | void mailmbox_close(struct mailmbox_folder * folder) |
223 | { | 226 | { |
224 | close(folder->mb_fd); | 227 | close(folder->mb_fd); |
225 | folder->mb_fd = -1; | 228 | folder->mb_fd = -1; |
226 | } | 229 | } |
227 | 230 | ||
228 | 231 | ||
229 | static int mailmbox_validate_lock(struct mailmbox_folder * folder, | 232 | static int mailmbox_validate_lock(struct mailmbox_folder * folder, |
230 | int (* custom_lock)(struct mailmbox_folder *), | 233 | int (* custom_lock)(struct mailmbox_folder *), |
231 | int (* custom_unlock)(struct mailmbox_folder *)) | 234 | int (* custom_unlock)(struct mailmbox_folder *)) |
@@ -588,64 +591,66 @@ mailmbox_append_message_list_no_lock(struct mailmbox_folder * folder, | |||
588 | time_t date; | 591 | time_t date; |
589 | int res; | 592 | int res; |
590 | size_t old_size; | 593 | size_t old_size; |
591 | char * str; | 594 | char * str; |
592 | unsigned int i; | 595 | unsigned int i; |
593 | size_t from_size; | 596 | size_t from_size; |
594 | size_t maxuid; | 597 | size_t maxuid; |
595 | size_t left; | 598 | size_t left; |
596 | size_t crlf_count; | 599 | size_t crlf_count; |
597 | 600 | ||
598 | if (folder->mb_read_only) { | 601 | if (folder->mb_read_only) { |
599 | res = MAILMBOX_ERROR_READONLY; | 602 | res = MAILMBOX_ERROR_READONLY; |
600 | goto err; | 603 | goto err; |
601 | } | 604 | } |
602 | 605 | ||
603 | date = time(NULL); | 606 | date = time(NULL); |
604 | from_size = strlen(DEFAULT_FROM_LINE); | 607 | from_size = strlen(DEFAULT_FROM_LINE); |
605 | if (localtime_r(&date, &time_info) != NULL) | 608 | if (localtime_r(&date, &time_info) != NULL) |
606 | from_size = strftime(from_line, MAX_FROM_LINE_SIZE, "From - %c\n", &time_info); | 609 | from_size = strftime(from_line, MAX_FROM_LINE_SIZE, "From - %c\n", &time_info); |
607 | 610 | ||
608 | maxuid = /* */ folder->mb_max_uid; | 611 | maxuid = /* */ folder->mb_max_uid; |
609 | 612 | ||
610 | extra_size = 0; | 613 | extra_size = 0; |
611 | for(i = 0 ; i < carray_count(append_tab) ; i ++) { | 614 | for(i = 0 ; i < carray_count(append_tab) ; i ++) { |
612 | struct mailmbox_append_info * info; | 615 | struct mailmbox_append_info * info; |
613 | 616 | ||
614 | info = carray_get(append_tab, i); | 617 | info = carray_get(append_tab, i); |
615 | extra_size += from_size; | 618 | extra_size += from_size; |
616 | extra_size += get_fixed_message_size(info->ai_message, info->ai_size, | 619 | extra_size += get_fixed_message_size(info->ai_message, info->ai_size, |
617 | folder->mb_max_uid + i + 1, | 620 | folder->mb_max_uid + i + 1, |
618 | folder->mb_no_uid); | 621 | folder->mb_no_uid); |
619 | extra_size += 2; /* CR LF */ | 622 | extra_size += 2; /* CR LF */ |
623 | |||
624 | info->ai_uid = folder->mb_max_uid + i + 1; | ||
620 | } | 625 | } |
621 | 626 | ||
622 | left = folder->mb_mapping_size; | 627 | left = folder->mb_mapping_size; |
623 | crlf_count = 0; | 628 | crlf_count = 0; |
624 | while (left >= 1) { | 629 | while (left >= 1) { |
625 | if (folder->mb_mapping[left - 1] == '\n') { | 630 | if (folder->mb_mapping[left - 1] == '\n') { |
626 | crlf_count ++; | 631 | crlf_count ++; |
627 | left --; | 632 | left --; |
628 | } | 633 | } |
629 | else if (folder->mb_mapping[left - 1] == '\r') { | 634 | else if (folder->mb_mapping[left - 1] == '\r') { |
630 | left --; | 635 | left --; |
631 | } | 636 | } |
632 | else | 637 | else |
633 | break; | 638 | break; |
634 | 639 | ||
635 | if (crlf_count == 2) | 640 | if (crlf_count == 2) |
636 | break; | 641 | break; |
637 | } | 642 | } |
638 | 643 | ||
639 | old_size = folder->mb_mapping_size; | 644 | old_size = folder->mb_mapping_size; |
640 | mailmbox_unmap(folder); | 645 | mailmbox_unmap(folder); |
641 | 646 | ||
642 | if (old_size != 0) { | 647 | if (old_size != 0) { |
643 | if (crlf_count != 2) | 648 | if (crlf_count != 2) |
644 | extra_size += (2 - crlf_count) * 2; | 649 | extra_size += (2 - crlf_count) * 2; |
645 | } | 650 | } |
646 | 651 | ||
647 | r = ftruncate(folder->mb_fd, extra_size + old_size); | 652 | r = ftruncate(folder->mb_fd, extra_size + old_size); |
648 | if (r < 0) { | 653 | if (r < 0) { |
649 | mailmbox_map(folder); | 654 | mailmbox_map(folder); |
650 | res = MAILMBOX_ERROR_FILE; | 655 | res = MAILMBOX_ERROR_FILE; |
651 | goto err; | 656 | goto err; |
@@ -715,105 +720,115 @@ mailmbox_append_message_list(struct mailmbox_folder * folder, | |||
715 | goto unlock; | 720 | goto unlock; |
716 | } | 721 | } |
717 | 722 | ||
718 | cur_token = folder->mb_mapping_size; | 723 | cur_token = folder->mb_mapping_size; |
719 | 724 | ||
720 | r = mailmbox_append_message_list_no_lock(folder, append_tab); | 725 | r = mailmbox_append_message_list_no_lock(folder, append_tab); |
721 | if (r != MAILMBOX_NO_ERROR) { | 726 | if (r != MAILMBOX_NO_ERROR) { |
722 | res = r; | 727 | res = r; |
723 | goto unlock; | 728 | goto unlock; |
724 | } | 729 | } |
725 | 730 | ||
726 | mailmbox_sync(folder); | 731 | mailmbox_sync(folder); |
727 | 732 | ||
728 | r = mailmbox_parse_additionnal(folder, &cur_token); | 733 | r = mailmbox_parse_additionnal(folder, &cur_token); |
729 | if (r != MAILMBOX_NO_ERROR) { | 734 | if (r != MAILMBOX_NO_ERROR) { |
730 | res = r; | 735 | res = r; |
731 | goto unlock; | 736 | goto unlock; |
732 | } | 737 | } |
733 | 738 | ||
734 | mailmbox_timestamp(folder); | 739 | mailmbox_timestamp(folder); |
735 | 740 | ||
736 | mailmbox_write_unlock(folder); | 741 | mailmbox_write_unlock(folder); |
737 | 742 | ||
738 | return MAILMBOX_NO_ERROR; | 743 | return MAILMBOX_NO_ERROR; |
739 | 744 | ||
740 | unlock: | 745 | unlock: |
741 | mailmbox_write_unlock(folder); | 746 | mailmbox_write_unlock(folder); |
742 | err: | 747 | err: |
743 | return res; | 748 | return res; |
744 | } | 749 | } |
745 | 750 | ||
746 | int | 751 | int |
747 | mailmbox_append_message(struct mailmbox_folder * folder, | 752 | mailmbox_append_message_uid(struct mailmbox_folder * folder, |
748 | const char * data, size_t len) | 753 | const char * data, size_t len, unsigned int * puid) |
749 | { | 754 | { |
750 | carray * tab; | 755 | carray * tab; |
751 | struct mailmbox_append_info * append_info; | 756 | struct mailmbox_append_info * append_info; |
752 | int res; | 757 | int res; |
753 | int r; | 758 | int r; |
754 | 759 | ||
755 | tab = carray_new(1); | 760 | tab = carray_new(1); |
756 | if (tab == NULL) { | 761 | if (tab == NULL) { |
757 | res = MAILMBOX_ERROR_MEMORY; | 762 | res = MAILMBOX_ERROR_MEMORY; |
758 | goto err; | 763 | goto err; |
759 | } | 764 | } |
760 | 765 | ||
761 | append_info = mailmbox_append_info_new(data, len); | 766 | append_info = mailmbox_append_info_new(data, len); |
762 | if (append_info == NULL) { | 767 | if (append_info == NULL) { |
763 | res = MAILMBOX_ERROR_MEMORY; | 768 | res = MAILMBOX_ERROR_MEMORY; |
764 | goto free_list; | 769 | goto free_list; |
765 | } | 770 | } |
766 | 771 | ||
767 | r = carray_add(tab, append_info, NULL); | 772 | r = carray_add(tab, append_info, NULL); |
768 | if (r < 0) { | 773 | if (r < 0) { |
769 | res = MAILMBOX_ERROR_MEMORY; | 774 | res = MAILMBOX_ERROR_MEMORY; |
770 | goto free_append_info; | 775 | goto free_append_info; |
771 | } | 776 | } |
772 | 777 | ||
773 | r = mailmbox_append_message_list(folder, tab); | 778 | r = mailmbox_append_message_list(folder, tab); |
774 | 779 | ||
780 | if (puid != NULL) | ||
781 | * puid = append_info->ai_uid; | ||
782 | |||
775 | mailmbox_append_info_free(append_info); | 783 | mailmbox_append_info_free(append_info); |
776 | carray_free(tab); | 784 | carray_free(tab); |
777 | 785 | ||
778 | return r; | 786 | return r; |
779 | 787 | ||
780 | free_append_info: | 788 | free_append_info: |
781 | mailmbox_append_info_free(append_info); | 789 | mailmbox_append_info_free(append_info); |
782 | free_list: | 790 | free_list: |
783 | carray_free(tab); | 791 | carray_free(tab); |
784 | err: | 792 | err: |
785 | return res; | 793 | return res; |
786 | } | 794 | } |
787 | 795 | ||
796 | int | ||
797 | mailmbox_append_message(struct mailmbox_folder * folder, | ||
798 | const char * data, size_t len) | ||
799 | { | ||
800 | return mailmbox_append_message_uid(folder, data, len, NULL); | ||
801 | } | ||
802 | |||
788 | /* ********************************************************************** */ | 803 | /* ********************************************************************** */ |
789 | 804 | ||
790 | int mailmbox_fetch_msg_no_lock(struct mailmbox_folder * folder, | 805 | int mailmbox_fetch_msg_no_lock(struct mailmbox_folder * folder, |
791 | uint32_t num, char ** result, | 806 | uint32_t num, char ** result, |
792 | size_t * result_len) | 807 | size_t * result_len) |
793 | { | 808 | { |
794 | struct mailmbox_msg_info * info; | 809 | struct mailmbox_msg_info * info; |
795 | int res; | 810 | int res; |
796 | chashdatum key; | 811 | chashdatum key; |
797 | chashdatum data; | 812 | chashdatum data; |
798 | int r; | 813 | int r; |
799 | 814 | ||
800 | key.data = # | 815 | key.data = # |
801 | key.len = sizeof(num); | 816 | key.len = sizeof(num); |
802 | 817 | ||
803 | r = chash_get(folder->mb_hash, &key, &data); | 818 | r = chash_get(folder->mb_hash, &key, &data); |
804 | if (r < 0) { | 819 | if (r < 0) { |
805 | res = MAILMBOX_ERROR_MSG_NOT_FOUND; | 820 | res = MAILMBOX_ERROR_MSG_NOT_FOUND; |
806 | goto err; | 821 | goto err; |
807 | } | 822 | } |
808 | 823 | ||
809 | info = data.data; | 824 | info = data.data; |
810 | 825 | ||
811 | if (info->msg_deleted) { | 826 | if (info->msg_deleted) { |
812 | res = MAILMBOX_ERROR_MSG_NOT_FOUND; | 827 | res = MAILMBOX_ERROR_MSG_NOT_FOUND; |
813 | goto err; | 828 | goto err; |
814 | } | 829 | } |
815 | 830 | ||
816 | * result = folder->mb_mapping + info->msg_headers; | 831 | * result = folder->mb_mapping + info->msg_headers; |
817 | * result_len = info->msg_size - info->msg_start_len; | 832 | * result_len = info->msg_size - info->msg_start_len; |
818 | 833 | ||
819 | return MAILMBOX_NO_ERROR; | 834 | return MAILMBOX_NO_ERROR; |
diff --git a/kmicromail/libetpan/mbox/mailmbox.h b/kmicromail/libetpan/mbox/mailmbox.h index 8be086c..0427f1f 100644 --- a/kmicromail/libetpan/mbox/mailmbox.h +++ b/kmicromail/libetpan/mbox/mailmbox.h | |||
@@ -22,64 +22,68 @@ | |||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #ifndef MAILMBOX_H | 36 | #ifndef MAILMBOX_H |
37 | 37 | ||
38 | #define MAILMBOX_H | 38 | #define MAILMBOX_H |
39 | 39 | ||
40 | #ifdef __cplusplus | 40 | #ifdef __cplusplus |
41 | extern "C" { | 41 | extern "C" { |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | #include <libetpan/mailmbox_types.h> | 44 | #include <libetpan/mailmbox_types.h> |
45 | 45 | ||
46 | int | 46 | int |
47 | mailmbox_append_message_list(struct mailmbox_folder * folder, | 47 | mailmbox_append_message_list(struct mailmbox_folder * folder, |
48 | carray * append_tab); | 48 | carray * append_tab); |
49 | 49 | ||
50 | int | 50 | int |
51 | mailmbox_append_message(struct mailmbox_folder * folder, | 51 | mailmbox_append_message(struct mailmbox_folder * folder, |
52 | const char * data, size_t len); | 52 | const char * data, size_t len); |
53 | 53 | ||
54 | int | ||
55 | mailmbox_append_message_uid(struct mailmbox_folder * folder, | ||
56 | const char * data, size_t len, unsigned int * puid); | ||
57 | |||
54 | int mailmbox_fetch_msg(struct mailmbox_folder * folder, | 58 | int mailmbox_fetch_msg(struct mailmbox_folder * folder, |
55 | uint32_t num, char ** result, | 59 | uint32_t num, char ** result, |
56 | size_t * result_len); | 60 | size_t * result_len); |
57 | 61 | ||
58 | int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder, | 62 | int mailmbox_fetch_msg_headers(struct mailmbox_folder * folder, |
59 | uint32_t num, char ** result, | 63 | uint32_t num, char ** result, |
60 | size_t * result_len); | 64 | size_t * result_len); |
61 | 65 | ||
62 | void mailmbox_fetch_result_free(char * msg); | 66 | void mailmbox_fetch_result_free(char * msg); |
63 | 67 | ||
64 | int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder, | 68 | int mailmbox_copy_msg_list(struct mailmbox_folder * dest_folder, |
65 | struct mailmbox_folder * src_folder, | 69 | struct mailmbox_folder * src_folder, |
66 | carray * tab); | 70 | carray * tab); |
67 | 71 | ||
68 | int mailmbox_copy_msg(struct mailmbox_folder * dest_folder, | 72 | int mailmbox_copy_msg(struct mailmbox_folder * dest_folder, |
69 | struct mailmbox_folder * src_folder, | 73 | struct mailmbox_folder * src_folder, |
70 | uint32_t uid); | 74 | uint32_t uid); |
71 | 75 | ||
72 | int mailmbox_expunge(struct mailmbox_folder * folder); | 76 | int mailmbox_expunge(struct mailmbox_folder * folder); |
73 | 77 | ||
74 | int mailmbox_delete_msg(struct mailmbox_folder * folder, uint32_t uid); | 78 | int mailmbox_delete_msg(struct mailmbox_folder * folder, uint32_t uid); |
75 | 79 | ||
76 | int mailmbox_init(const char * filename, | 80 | int mailmbox_init(const char * filename, |
77 | int force_readonly, | 81 | int force_readonly, |
78 | int force_no_uid, | 82 | int force_no_uid, |
79 | uint32_t default_written_uid, | 83 | uint32_t default_written_uid, |
80 | struct mailmbox_folder ** result_folder); | 84 | struct mailmbox_folder ** result_folder); |
81 | 85 | ||
82 | void mailmbox_done(struct mailmbox_folder * folder); | 86 | void mailmbox_done(struct mailmbox_folder * folder); |
83 | 87 | ||
84 | /* low-level access primitives */ | 88 | /* low-level access primitives */ |
85 | 89 | ||
diff --git a/kmicromail/libetpan/mbox/mailmbox_types.c b/kmicromail/libetpan/mbox/mailmbox_types.c index 1986182..4e3e521 100644 --- a/kmicromail/libetpan/mbox/mailmbox_types.c +++ b/kmicromail/libetpan/mbox/mailmbox_types.c | |||
@@ -149,65 +149,66 @@ mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len, | |||
149 | info->msg_headers = msg_headers; | 149 | info->msg_headers = msg_headers; |
150 | info->msg_headers_len = msg_headers_len; | 150 | info->msg_headers_len = msg_headers_len; |
151 | 151 | ||
152 | info->msg_body = msg_body; | 152 | info->msg_body = msg_body; |
153 | info->msg_body_len = msg_body_len; | 153 | info->msg_body_len = msg_body_len; |
154 | 154 | ||
155 | info->msg_size = msg_size; | 155 | info->msg_size = msg_size; |
156 | 156 | ||
157 | info->msg_padding = msg_padding; | 157 | info->msg_padding = msg_padding; |
158 | 158 | ||
159 | return info; | 159 | return info; |
160 | } | 160 | } |
161 | 161 | ||
162 | void mailmbox_msg_info_free(struct mailmbox_msg_info * info) | 162 | void mailmbox_msg_info_free(struct mailmbox_msg_info * info) |
163 | { | 163 | { |
164 | free(info); | 164 | free(info); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
168 | /* append info */ | 168 | /* append info */ |
169 | 169 | ||
170 | struct mailmbox_append_info * | 170 | struct mailmbox_append_info * |
171 | mailmbox_append_info_new(const char * ai_message, size_t ai_size) | 171 | mailmbox_append_info_new(const char * ai_message, size_t ai_size) |
172 | { | 172 | { |
173 | struct mailmbox_append_info * info; | 173 | struct mailmbox_append_info * info; |
174 | 174 | ||
175 | info = malloc(sizeof(* info)); | 175 | info = malloc(sizeof(* info)); |
176 | if (info == NULL) | 176 | if (info == NULL) |
177 | return NULL; | 177 | return NULL; |
178 | 178 | ||
179 | info->ai_message = ai_message; | 179 | info->ai_message = ai_message; |
180 | info->ai_size = ai_size; | 180 | info->ai_size = ai_size; |
181 | 181 | info->ai_uid = 0; | |
182 | |||
182 | return info; | 183 | return info; |
183 | } | 184 | } |
184 | 185 | ||
185 | void mailmbox_append_info_free(struct mailmbox_append_info * info) | 186 | void mailmbox_append_info_free(struct mailmbox_append_info * info) |
186 | { | 187 | { |
187 | free(info); | 188 | free(info); |
188 | } | 189 | } |
189 | 190 | ||
190 | struct mailmbox_folder * mailmbox_folder_new(const char * mb_filename) | 191 | struct mailmbox_folder * mailmbox_folder_new(const char * mb_filename) |
191 | { | 192 | { |
192 | struct mailmbox_folder * folder; | 193 | struct mailmbox_folder * folder; |
193 | 194 | ||
194 | folder = malloc(sizeof(* folder)); | 195 | folder = malloc(sizeof(* folder)); |
195 | if (folder == NULL) | 196 | if (folder == NULL) |
196 | goto err; | 197 | goto err; |
197 | 198 | ||
198 | strncpy(folder->mb_filename, mb_filename, PATH_MAX); | 199 | strncpy(folder->mb_filename, mb_filename, PATH_MAX); |
199 | 200 | ||
200 | folder->mb_mtime = (time_t) -1; | 201 | folder->mb_mtime = (time_t) -1; |
201 | 202 | ||
202 | folder->mb_fd = -1; | 203 | folder->mb_fd = -1; |
203 | folder->mb_read_only = TRUE; | 204 | folder->mb_read_only = TRUE; |
204 | folder->mb_no_uid = TRUE; | 205 | folder->mb_no_uid = TRUE; |
205 | 206 | ||
206 | folder->mb_changed = FALSE; | 207 | folder->mb_changed = FALSE; |
207 | folder->mb_deleted_count = 0; | 208 | folder->mb_deleted_count = 0; |
208 | 209 | ||
209 | folder->mb_mapping = NULL; | 210 | folder->mb_mapping = NULL; |
210 | folder->mb_mapping_size = 0; | 211 | folder->mb_mapping_size = 0; |
211 | 212 | ||
212 | folder->mb_written_uid = 0; | 213 | folder->mb_written_uid = 0; |
213 | folder->mb_max_uid = 0; | 214 | folder->mb_max_uid = 0; |
diff --git a/kmicromail/libetpan/mbox/mailmbox_types.h b/kmicromail/libetpan/mbox/mailmbox_types.h index dd6758c..bd6ee30 100644 --- a/kmicromail/libetpan/mbox/mailmbox_types.h +++ b/kmicromail/libetpan/mbox/mailmbox_types.h | |||
@@ -99,44 +99,45 @@ struct mailmbox_msg_info { | |||
99 | 99 | ||
100 | size_t msg_headers; | 100 | size_t msg_headers; |
101 | size_t msg_headers_len; | 101 | size_t msg_headers_len; |
102 | 102 | ||
103 | size_t msg_body; | 103 | size_t msg_body; |
104 | size_t msg_body_len; | 104 | size_t msg_body_len; |
105 | 105 | ||
106 | size_t msg_size; | 106 | size_t msg_size; |
107 | 107 | ||
108 | size_t msg_padding; | 108 | size_t msg_padding; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
112 | int mailmbox_msg_info_update(struct mailmbox_folder * folder, | 112 | int mailmbox_msg_info_update(struct mailmbox_folder * folder, |
113 | size_t msg_start, size_t msg_start_len, | 113 | size_t msg_start, size_t msg_start_len, |
114 | size_t msg_headers, size_t msg_headers_len, | 114 | size_t msg_headers, size_t msg_headers_len, |
115 | size_t msg_body, size_t msg_body_len, | 115 | size_t msg_body, size_t msg_body_len, |
116 | size_t msg_size, size_t msg_padding, | 116 | size_t msg_size, size_t msg_padding, |
117 | uint32_t msg_uid); | 117 | uint32_t msg_uid); |
118 | 118 | ||
119 | struct mailmbox_msg_info * | 119 | struct mailmbox_msg_info * |
120 | mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len, | 120 | mailmbox_msg_info_new(size_t msg_start, size_t msg_start_len, |
121 | size_t msg_headers, size_t msg_headers_len, | 121 | size_t msg_headers, size_t msg_headers_len, |
122 | size_t msg_body, size_t msg_body_len, | 122 | size_t msg_body, size_t msg_body_len, |
123 | size_t msg_size, size_t msg_padding, | 123 | size_t msg_size, size_t msg_padding, |
124 | uint32_t msg_uid); | 124 | uint32_t msg_uid); |
125 | 125 | ||
126 | void mailmbox_msg_info_free(struct mailmbox_msg_info * info); | 126 | void mailmbox_msg_info_free(struct mailmbox_msg_info * info); |
127 | 127 | ||
128 | struct mailmbox_append_info { | 128 | struct mailmbox_append_info { |
129 | const char * ai_message; | 129 | const char * ai_message; |
130 | size_t ai_size; | 130 | size_t ai_size; |
131 | unsigned int ai_uid; | ||
131 | }; | 132 | }; |
132 | 133 | ||
133 | struct mailmbox_append_info * | 134 | struct mailmbox_append_info * |
134 | mailmbox_append_info_new(const char * ai_message, size_t ai_size); | 135 | mailmbox_append_info_new(const char * ai_message, size_t ai_size); |
135 | 136 | ||
136 | void mailmbox_append_info_free(struct mailmbox_append_info * info); | 137 | void mailmbox_append_info_free(struct mailmbox_append_info * info); |
137 | 138 | ||
138 | #ifdef __cplusplus | 139 | #ifdef __cplusplus |
139 | } | 140 | } |
140 | #endif | 141 | #endif |
141 | 142 | ||
142 | #endif | 143 | #endif |
diff --git a/kmicromail/libetpan/mh/mailmh.c b/kmicromail/libetpan/mh/mailmh.c index d6ff950..119f217 100644 --- a/kmicromail/libetpan/mh/mailmh.c +++ b/kmicromail/libetpan/mh/mailmh.c | |||
@@ -694,66 +694,67 @@ int mailmh_folder_get_message_fd(struct mailmh_folder * folder, | |||
694 | 694 | ||
695 | fd = open(filename, flags); | 695 | fd = open(filename, flags); |
696 | free(filename); | 696 | free(filename); |
697 | if (fd == -1) | 697 | if (fd == -1) |
698 | return MAILMH_ERROR_MSG_NOT_FOUND; | 698 | return MAILMH_ERROR_MSG_NOT_FOUND; |
699 | 699 | ||
700 | * result = fd; | 700 | * result = fd; |
701 | 701 | ||
702 | return MAILMH_NO_ERROR; | 702 | return MAILMH_NO_ERROR; |
703 | } | 703 | } |
704 | 704 | ||
705 | int mailmh_folder_get_message_size(struct mailmh_folder * folder, | 705 | int mailmh_folder_get_message_size(struct mailmh_folder * folder, |
706 | uint32_t index, size_t * result) | 706 | uint32_t index, size_t * result) |
707 | { | 707 | { |
708 | int r; | 708 | int r; |
709 | char * filename; | 709 | char * filename; |
710 | struct stat buf; | 710 | struct stat buf; |
711 | 711 | ||
712 | r = mailmh_folder_get_message_filename(folder, index, &filename); | 712 | r = mailmh_folder_get_message_filename(folder, index, &filename); |
713 | if (r != MAILMH_NO_ERROR) | 713 | if (r != MAILMH_NO_ERROR) |
714 | return r; | 714 | return r; |
715 | 715 | ||
716 | r = stat(filename, &buf); | 716 | r = stat(filename, &buf); |
717 | free(filename); | 717 | free(filename); |
718 | if (r < 0) | 718 | if (r < 0) |
719 | return MAILMH_ERROR_FILE; | 719 | return MAILMH_ERROR_FILE; |
720 | 720 | ||
721 | * result = buf.st_size; | 721 | * result = buf.st_size; |
722 | 722 | ||
723 | return MAILMH_NO_ERROR; | 723 | return MAILMH_NO_ERROR; |
724 | } | 724 | } |
725 | 725 | ||
726 | int mailmh_folder_add_message(struct mailmh_folder * folder, | 726 | int mailmh_folder_add_message_uid(struct mailmh_folder * folder, |
727 | const char * message, size_t size) | 727 | const char * message, size_t size, |
728 | uint32_t * pindex) | ||
728 | { | 729 | { |
729 | char * tmpname; | 730 | char * tmpname; |
730 | int fd; | 731 | int fd; |
731 | size_t namesize; | 732 | size_t namesize; |
732 | size_t left; | 733 | size_t left; |
733 | ssize_t res; | 734 | ssize_t res; |
734 | struct mailmh_msg_info * msg_info; | 735 | struct mailmh_msg_info * msg_info; |
735 | uint32_t index; | 736 | uint32_t index; |
736 | int error; | 737 | int error; |
737 | int r; | 738 | int r; |
738 | unsigned int array_index; | 739 | unsigned int array_index; |
739 | struct stat buf; | 740 | struct stat buf; |
740 | chashdatum key; | 741 | chashdatum key; |
741 | chashdatum data; | 742 | chashdatum data; |
742 | 743 | ||
743 | #if 0 | 744 | #if 0 |
744 | r = mailmh_folder_update(folder); | 745 | r = mailmh_folder_update(folder); |
745 | if (r != MAILMH_NO_ERROR) { | 746 | if (r != MAILMH_NO_ERROR) { |
746 | error = r; | 747 | error = r; |
747 | goto err; | 748 | goto err; |
748 | } | 749 | } |
749 | #endif | 750 | #endif |
750 | 751 | ||
751 | namesize = strlen(folder->fl_filename) + 20; | 752 | namesize = strlen(folder->fl_filename) + 20; |
752 | tmpname = malloc(namesize); | 753 | tmpname = malloc(namesize); |
753 | snprintf(tmpname, namesize, "%s%ctmpXXXXXX", | 754 | snprintf(tmpname, namesize, "%s%ctmpXXXXXX", |
754 | folder->fl_filename, MAIL_DIR_SEPARATOR); | 755 | folder->fl_filename, MAIL_DIR_SEPARATOR); |
755 | fd = mkstemp(tmpname); | 756 | fd = mkstemp(tmpname); |
756 | if (fd < 0) { | 757 | if (fd < 0) { |
757 | error = MAILMH_ERROR_FILE; | 758 | error = MAILMH_ERROR_FILE; |
758 | goto free; | 759 | goto free; |
759 | } | 760 | } |
@@ -780,107 +781,122 @@ int mailmh_folder_add_message(struct mailmh_folder * folder, | |||
780 | r = mailmh_folder_alloc_msg(folder, tmpname, &index); | 781 | r = mailmh_folder_alloc_msg(folder, tmpname, &index); |
781 | if (r != MAILMH_NO_ERROR) { | 782 | if (r != MAILMH_NO_ERROR) { |
782 | unlink(tmpname); | 783 | unlink(tmpname); |
783 | error = MAILMH_ERROR_COULD_NOT_ALLOC_MSG; | 784 | error = MAILMH_ERROR_COULD_NOT_ALLOC_MSG; |
784 | goto free; | 785 | goto free; |
785 | } | 786 | } |
786 | free(tmpname); | 787 | free(tmpname); |
787 | 788 | ||
788 | msg_info = mailmh_msg_info_new(index, size, buf.st_mtime); | 789 | msg_info = mailmh_msg_info_new(index, size, buf.st_mtime); |
789 | if (msg_info == NULL) { | 790 | if (msg_info == NULL) { |
790 | mailmh_folder_remove_message(folder, index); | 791 | mailmh_folder_remove_message(folder, index); |
791 | error = MAILMH_ERROR_MEMORY; | 792 | error = MAILMH_ERROR_MEMORY; |
792 | goto err; | 793 | goto err; |
793 | } | 794 | } |
794 | 795 | ||
795 | r = carray_add(folder->fl_msgs_tab, msg_info, &array_index); | 796 | r = carray_add(folder->fl_msgs_tab, msg_info, &array_index); |
796 | if (r < 0) { | 797 | if (r < 0) { |
797 | mailmh_folder_remove_message(folder, index); | 798 | mailmh_folder_remove_message(folder, index); |
798 | mailmh_msg_info_free(msg_info); | 799 | mailmh_msg_info_free(msg_info); |
799 | error = MAILMH_ERROR_MEMORY; | 800 | error = MAILMH_ERROR_MEMORY; |
800 | goto err; | 801 | goto err; |
801 | } | 802 | } |
802 | msg_info->msg_array_index = array_index; | 803 | msg_info->msg_array_index = array_index; |
803 | 804 | ||
804 | #if 0 | 805 | #if 0 |
805 | r = cinthash_add(folder->fl_msgs_hash, index, msg_info); | 806 | r = cinthash_add(folder->fl_msgs_hash, index, msg_info); |
806 | #endif | 807 | #endif |
807 | key.data = &index; | 808 | key.data = &index; |
808 | key.len = sizeof(index); | 809 | key.len = sizeof(index); |
809 | data.data = msg_info; | 810 | data.data = msg_info; |
810 | data.len = 0; | 811 | data.len = 0; |
811 | 812 | ||
813 | if (pindex != NULL) | ||
814 | * pindex = index; | ||
815 | |||
812 | r = chash_set(folder->fl_msgs_hash, &key, &data, NULL); | 816 | r = chash_set(folder->fl_msgs_hash, &key, &data, NULL); |
813 | if (r < 0) { | 817 | if (r < 0) { |
814 | carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); | 818 | carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); |
815 | mailmh_msg_info_free(msg_info); | 819 | mailmh_msg_info_free(msg_info); |
816 | error = MAILMH_ERROR_MEMORY; | 820 | error = MAILMH_ERROR_MEMORY; |
817 | goto err; | 821 | goto err; |
818 | } | 822 | } |
819 | 823 | ||
820 | return MAILMH_NO_ERROR; | 824 | return MAILMH_NO_ERROR; |
821 | 825 | ||
822 | free: | 826 | free: |
823 | free(tmpname); | 827 | free(tmpname); |
824 | err: | 828 | err: |
825 | return error; | 829 | return error; |
826 | } | 830 | } |
827 | 831 | ||
828 | int mailmh_folder_add_message_file(struct mailmh_folder * folder, | 832 | int mailmh_folder_add_message(struct mailmh_folder * folder, |
829 | int fd) | 833 | const char * message, size_t size) |
834 | { | ||
835 | return mailmh_folder_add_message_uid(folder, message, size, NULL); | ||
836 | } | ||
837 | |||
838 | int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder, | ||
839 | int fd, uint32_t * pindex) | ||
830 | { | 840 | { |
831 | char * message; | 841 | char * message; |
832 | struct stat buf; | 842 | struct stat buf; |
833 | int r; | 843 | int r; |
834 | 844 | ||
835 | #if 0 | 845 | #if 0 |
836 | r = mailmh_folder_update(folder); | 846 | r = mailmh_folder_update(folder); |
837 | if (r != MAILMH_NO_ERROR) | 847 | if (r != MAILMH_NO_ERROR) |
838 | return r; | 848 | return r; |
839 | #endif | 849 | #endif |
840 | 850 | ||
841 | if (fstat(fd, &buf) == -1) | 851 | if (fstat(fd, &buf) == -1) |
842 | return MAILMH_ERROR_FILE; | 852 | return MAILMH_ERROR_FILE; |
843 | 853 | ||
844 | message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | 854 | message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
845 | if (message == MAP_FAILED) | 855 | if (message == MAP_FAILED) |
846 | return MAILMH_ERROR_FILE; | 856 | return MAILMH_ERROR_FILE; |
847 | 857 | ||
848 | r = mailmh_folder_add_message(folder, message, buf.st_size); | 858 | r = mailmh_folder_add_message_uid(folder, message, buf.st_size, pindex); |
849 | 859 | ||
850 | munmap(message, buf.st_size); | 860 | munmap(message, buf.st_size); |
851 | 861 | ||
852 | return r; | 862 | return r; |
853 | } | 863 | } |
854 | 864 | ||
865 | int mailmh_folder_add_message_file(struct mailmh_folder * folder, | ||
866 | int fd) | ||
867 | { | ||
868 | return mailmh_folder_add_message_file_uid(folder, fd, NULL); | ||
869 | } | ||
870 | |||
855 | int mailmh_folder_remove_message(struct mailmh_folder * folder, | 871 | int mailmh_folder_remove_message(struct mailmh_folder * folder, |
856 | uint32_t index) | 872 | uint32_t index) |
857 | { | 873 | { |
858 | char * filename; | 874 | char * filename; |
859 | struct mailmh_msg_info * msg_info; | 875 | struct mailmh_msg_info * msg_info; |
860 | int res; | 876 | int res; |
861 | int r; | 877 | int r; |
862 | chashdatum key; | 878 | chashdatum key; |
863 | chashdatum data; | 879 | chashdatum data; |
864 | 880 | ||
865 | #if 0 | 881 | #if 0 |
866 | r = mailmh_folder_update(folder); | 882 | r = mailmh_folder_update(folder); |
867 | if (r != MAILMH_NO_ERROR) { | 883 | if (r != MAILMH_NO_ERROR) { |
868 | res = r; | 884 | res = r; |
869 | goto err; | 885 | goto err; |
870 | } | 886 | } |
871 | #endif | 887 | #endif |
872 | 888 | ||
873 | r = mailmh_folder_get_message_filename(folder, index, &filename); | 889 | r = mailmh_folder_get_message_filename(folder, index, &filename); |
874 | if (filename == NULL) { | 890 | if (filename == NULL) { |
875 | res = r; | 891 | res = r; |
876 | goto err; | 892 | goto err; |
877 | } | 893 | } |
878 | 894 | ||
879 | if (unlink(filename) == -1) { | 895 | if (unlink(filename) == -1) { |
880 | res = MAILMH_ERROR_FILE; | 896 | res = MAILMH_ERROR_FILE; |
881 | goto free; | 897 | goto free; |
882 | } | 898 | } |
883 | 899 | ||
884 | key.data = &index; | 900 | key.data = &index; |
885 | key.len = sizeof(index); | 901 | key.len = sizeof(index); |
886 | r = chash_get(folder->fl_msgs_hash, &key, &data); | 902 | r = chash_get(folder->fl_msgs_hash, &key, &data); |
diff --git a/kmicromail/libetpan/mh/mailmh.h b/kmicromail/libetpan/mh/mailmh.h index 40432cb..00199b8 100644 --- a/kmicromail/libetpan/mh/mailmh.h +++ b/kmicromail/libetpan/mh/mailmh.h | |||
@@ -90,54 +90,61 @@ struct mailmh_folder { | |||
90 | struct mailmh * mailmh_new(const char * foldername); | 90 | struct mailmh * mailmh_new(const char * foldername); |
91 | void mailmh_free(struct mailmh * f); | 91 | void mailmh_free(struct mailmh * f); |
92 | 92 | ||
93 | struct mailmh_msg_info * | 93 | struct mailmh_msg_info * |
94 | mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime); | 94 | mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime); |
95 | void mailmh_msg_info_free(struct mailmh_msg_info * msg_info); | 95 | void mailmh_msg_info_free(struct mailmh_msg_info * msg_info); |
96 | 96 | ||
97 | struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent, | 97 | struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent, |
98 | const char * name); | 98 | const char * name); |
99 | void mailmh_folder_free(struct mailmh_folder * folder); | 99 | void mailmh_folder_free(struct mailmh_folder * folder); |
100 | 100 | ||
101 | int mailmh_folder_add_subfolder(struct mailmh_folder * parent, | 101 | int mailmh_folder_add_subfolder(struct mailmh_folder * parent, |
102 | const char * name); | 102 | const char * name); |
103 | 103 | ||
104 | struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root, | 104 | struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root, |
105 | const char * filename); | 105 | const char * filename); |
106 | 106 | ||
107 | int mailmh_folder_remove_subfolder(struct mailmh_folder * folder); | 107 | int mailmh_folder_remove_subfolder(struct mailmh_folder * folder); |
108 | 108 | ||
109 | int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder, | 109 | int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder, |
110 | struct mailmh_folder * dst_folder, | 110 | struct mailmh_folder * dst_folder, |
111 | const char * new_name); | 111 | const char * new_name); |
112 | 112 | ||
113 | int mailmh_folder_get_message_filename(struct mailmh_folder * folder, | 113 | int mailmh_folder_get_message_filename(struct mailmh_folder * folder, |
114 | uint32_t index, char ** result); | 114 | uint32_t index, char ** result); |
115 | 115 | ||
116 | int mailmh_folder_get_message_fd(struct mailmh_folder * folder, | 116 | int mailmh_folder_get_message_fd(struct mailmh_folder * folder, |
117 | uint32_t index, int flags, int * result); | 117 | uint32_t index, int flags, int * result); |
118 | 118 | ||
119 | int mailmh_folder_get_message_size(struct mailmh_folder * folder, | 119 | int mailmh_folder_get_message_size(struct mailmh_folder * folder, |
120 | uint32_t index, size_t * result); | 120 | uint32_t index, size_t * result); |
121 | 121 | ||
122 | int mailmh_folder_add_message_uid(struct mailmh_folder * folder, | ||
123 | const char * message, size_t size, | ||
124 | uint32_t * pindex); | ||
125 | |||
122 | int mailmh_folder_add_message(struct mailmh_folder * folder, | 126 | int mailmh_folder_add_message(struct mailmh_folder * folder, |
123 | const char * message, size_t size); | 127 | const char * message, size_t size); |
124 | 128 | ||
129 | int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder, | ||
130 | int fd, uint32_t * pindex); | ||
131 | |||
125 | int mailmh_folder_add_message_file(struct mailmh_folder * folder, | 132 | int mailmh_folder_add_message_file(struct mailmh_folder * folder, |
126 | int fd); | 133 | int fd); |
127 | 134 | ||
128 | int mailmh_folder_remove_message(struct mailmh_folder * folder, | 135 | int mailmh_folder_remove_message(struct mailmh_folder * folder, |
129 | uint32_t index); | 136 | uint32_t index); |
130 | 137 | ||
131 | int mailmh_folder_move_message(struct mailmh_folder * dest_folder, | 138 | int mailmh_folder_move_message(struct mailmh_folder * dest_folder, |
132 | struct mailmh_folder * src_folder, | 139 | struct mailmh_folder * src_folder, |
133 | uint32_t index); | 140 | uint32_t index); |
134 | 141 | ||
135 | int mailmh_folder_update(struct mailmh_folder * folder); | 142 | int mailmh_folder_update(struct mailmh_folder * folder); |
136 | 143 | ||
137 | unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder); | 144 | unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder); |
138 | 145 | ||
139 | #ifdef __cplusplus | 146 | #ifdef __cplusplus |
140 | } | 147 | } |
141 | #endif | 148 | #endif |
142 | 149 | ||
143 | #endif | 150 | #endif |
diff --git a/kmicromail/libetpan/mime/mailmime_decode.c b/kmicromail/libetpan/mime/mailmime_decode.c index 3025dcb..e48ec19 100644 --- a/kmicromail/libetpan/mime/mailmime_decode.c +++ b/kmicromail/libetpan/mime/mailmime_decode.c | |||
@@ -158,74 +158,84 @@ int mailmime_encoded_phrase_parse(const char * default_fromcode, | |||
158 | free(wordutf8); | 158 | free(wordutf8); |
159 | } | 159 | } |
160 | mailmime_encoded_word_free(word); | 160 | mailmime_encoded_word_free(word); |
161 | first = FALSE; | 161 | first = FALSE; |
162 | } | 162 | } |
163 | else if (r == MAILIMF_ERROR_PARSE) { | 163 | else if (r == MAILIMF_ERROR_PARSE) { |
164 | /* do nothing */ | 164 | /* do nothing */ |
165 | } | 165 | } |
166 | else { | 166 | else { |
167 | res = r; | 167 | res = r; |
168 | goto free; | 168 | goto free; |
169 | } | 169 | } |
170 | 170 | ||
171 | if (r == MAILIMF_ERROR_PARSE) { | 171 | if (r == MAILIMF_ERROR_PARSE) { |
172 | char * raw_word; | 172 | char * raw_word; |
173 | 173 | ||
174 | r = mailmime_non_encoded_word_parse(message, length, | 174 | r = mailmime_non_encoded_word_parse(message, length, |
175 | &cur_token, &raw_word); | 175 | &cur_token, &raw_word); |
176 | if (r == MAILIMF_NO_ERROR) { | 176 | if (r == MAILIMF_NO_ERROR) { |
177 | if (!first) { | 177 | if (!first) { |
178 | if (mmap_string_append_c(gphrase, ' ') == NULL) { | 178 | if (mmap_string_append_c(gphrase, ' ') == NULL) { |
179 | free(raw_word); | 179 | free(raw_word); |
180 | res = MAILIMF_ERROR_MEMORY; | 180 | res = MAILIMF_ERROR_MEMORY; |
181 | goto free; | 181 | goto free; |
182 | } | 182 | } |
183 | } | 183 | } |
184 | type = TYPE_WORD; | 184 | type = TYPE_WORD; |
185 | 185 | ||
186 | wordutf8 = NULL; | 186 | wordutf8 = NULL; |
187 | r = charconv(tocode, default_fromcode, raw_word, | 187 | r = charconv(tocode, default_fromcode, raw_word, |
188 | strlen(raw_word), &wordutf8); | 188 | strlen(raw_word), &wordutf8); |
189 | 189 | ||
190 | if (wordutf8 != NULL) { | 190 | switch (r) { |
191 | if (mmap_string_append(gphrase, wordutf8) == NULL) { | 191 | case MAIL_CHARCONV_ERROR_MEMORY: |
192 | free(wordutf8); | 192 | free(raw_word); |
193 | free(raw_word); | 193 | res = MAILIMF_ERROR_MEMORY; |
194 | res = MAILIMF_ERROR_MEMORY; | 194 | goto free; |
195 | goto free; | ||
196 | } | ||
197 | 195 | ||
196 | case MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET: | ||
197 | case MAIL_CHARCONV_ERROR_CONV: | ||
198 | free(raw_word); | ||
199 | res = MAILIMF_ERROR_PARSE; | ||
200 | goto free; | ||
201 | } | ||
202 | |||
203 | if (mmap_string_append(gphrase, wordutf8) == NULL) { | ||
198 | free(wordutf8); | 204 | free(wordutf8); |
205 | free(raw_word); | ||
206 | res = MAILIMF_ERROR_MEMORY; | ||
207 | goto free; | ||
199 | } | 208 | } |
209 | |||
200 | free(raw_word); | 210 | free(raw_word); |
201 | first = FALSE; | 211 | first = FALSE; |
202 | } | 212 | } |
203 | else if (r == MAILIMF_ERROR_PARSE) { | 213 | else if (r == MAILIMF_ERROR_PARSE) { |
204 | break; | 214 | break; |
205 | } | 215 | } |
206 | else { | 216 | else { |
207 | res = r; | 217 | res = r; |
208 | goto free; | 218 | goto free; |
209 | } | 219 | } |
210 | } | 220 | } |
211 | } | 221 | } |
212 | 222 | ||
213 | if (first) { | 223 | if (first) { |
214 | res = MAILIMF_ERROR_PARSE; | 224 | res = MAILIMF_ERROR_PARSE; |
215 | goto free; | 225 | goto free; |
216 | } | 226 | } |
217 | 227 | ||
218 | str = strdup(gphrase->str); | 228 | str = strdup(gphrase->str); |
219 | if (str == NULL) { | 229 | if (str == NULL) { |
220 | res = MAILIMF_ERROR_MEMORY; | 230 | res = MAILIMF_ERROR_MEMORY; |
221 | goto free; | 231 | goto free; |
222 | } | 232 | } |
223 | mmap_string_free(gphrase); | 233 | mmap_string_free(gphrase); |
224 | 234 | ||
225 | * result = str; | 235 | * result = str; |
226 | * index = cur_token; | 236 | * index = cur_token; |
227 | 237 | ||
228 | return MAILIMF_NO_ERROR; | 238 | return MAILIMF_NO_ERROR; |
229 | 239 | ||
230 | free: | 240 | free: |
231 | mmap_string_free(gphrase); | 241 | mmap_string_free(gphrase); |
diff --git a/kmicromail/libetpan/mime/mailmime_write.c b/kmicromail/libetpan/mime/mailmime_write.c index 5c3b1f7..208e3ba 100644 --- a/kmicromail/libetpan/mime/mailmime_write.c +++ b/kmicromail/libetpan/mime/mailmime_write.c | |||
@@ -412,65 +412,65 @@ static int mailmime_disposition_write(FILE * f, int * col, | |||
412 | return r; | 412 | return r; |
413 | 413 | ||
414 | return MAILIMF_NO_ERROR; | 414 | return MAILIMF_NO_ERROR; |
415 | } | 415 | } |
416 | 416 | ||
417 | static int | 417 | static int |
418 | mailmime_disposition_param_write(FILE * f, int * col, | 418 | mailmime_disposition_param_write(FILE * f, int * col, |
419 | struct mailmime_disposition_parm * param) | 419 | struct mailmime_disposition_parm * param) |
420 | { | 420 | { |
421 | size_t len; | 421 | size_t len; |
422 | char sizestr[20]; | 422 | char sizestr[20]; |
423 | int r; | 423 | int r; |
424 | 424 | ||
425 | switch (param->pa_type) { | 425 | switch (param->pa_type) { |
426 | case MAILMIME_DISPOSITION_PARM_FILENAME: | 426 | case MAILMIME_DISPOSITION_PARM_FILENAME: |
427 | len = strlen("filename=") + strlen(param->pa_data.pa_filename); | 427 | len = strlen("filename=") + strlen(param->pa_data.pa_filename); |
428 | break; | 428 | break; |
429 | 429 | ||
430 | case MAILMIME_DISPOSITION_PARM_CREATION_DATE: | 430 | case MAILMIME_DISPOSITION_PARM_CREATION_DATE: |
431 | len = strlen("creation-date=") + strlen(param->pa_data.pa_creation_date); | 431 | len = strlen("creation-date=") + strlen(param->pa_data.pa_creation_date); |
432 | break; | 432 | break; |
433 | 433 | ||
434 | case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE: | 434 | case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE: |
435 | len = strlen("modification-date=") + | 435 | len = strlen("modification-date=") + |
436 | strlen(param->pa_data.pa_modification_date); | 436 | strlen(param->pa_data.pa_modification_date); |
437 | break; | 437 | break; |
438 | 438 | ||
439 | case MAILMIME_DISPOSITION_PARM_READ_DATE: | 439 | case MAILMIME_DISPOSITION_PARM_READ_DATE: |
440 | len = strlen("read-date=") + strlen(param->pa_data.pa_read_date); | 440 | len = strlen("read-date=") + strlen(param->pa_data.pa_read_date); |
441 | break; | 441 | break; |
442 | 442 | ||
443 | case MAILMIME_DISPOSITION_PARM_SIZE: | 443 | case MAILMIME_DISPOSITION_PARM_SIZE: |
444 | snprintf(sizestr, 20, "%u", param->pa_data.pa_size); | 444 | snprintf(sizestr, 20, "%lu", (unsigned long) param->pa_data.pa_size); |
445 | len = strlen("size=") + strlen(sizestr); | 445 | len = strlen("size=") + strlen(sizestr); |
446 | break; | 446 | break; |
447 | 447 | ||
448 | case MAILMIME_DISPOSITION_PARM_PARAMETER: | 448 | case MAILMIME_DISPOSITION_PARM_PARAMETER: |
449 | len = strlen(param->pa_data.pa_parameter->pa_name) + 1 + | 449 | len = strlen(param->pa_data.pa_parameter->pa_name) + 1 + |
450 | strlen(param->pa_data.pa_parameter->pa_value); | 450 | strlen(param->pa_data.pa_parameter->pa_value); |
451 | break; | 451 | break; |
452 | 452 | ||
453 | default: | 453 | default: |
454 | return MAILIMF_ERROR_INVAL; | 454 | return MAILIMF_ERROR_INVAL; |
455 | } | 455 | } |
456 | 456 | ||
457 | if (* col > 1) { | 457 | if (* col > 1) { |
458 | 458 | ||
459 | if (* col + len > MAX_MAIL_COL) { | 459 | if (* col + len > MAX_MAIL_COL) { |
460 | r = mailimf_string_write(f, col, "\r\n ", 3); | 460 | r = mailimf_string_write(f, col, "\r\n ", 3); |
461 | if (r != MAILIMF_NO_ERROR) | 461 | if (r != MAILIMF_NO_ERROR) |
462 | return r; | 462 | return r; |
463 | #if 0 | 463 | #if 0 |
464 | * col = 1; | 464 | * col = 1; |
465 | #endif | 465 | #endif |
466 | } | 466 | } |
467 | } | 467 | } |
468 | 468 | ||
469 | switch (param->pa_type) { | 469 | switch (param->pa_type) { |
470 | case MAILMIME_DISPOSITION_PARM_FILENAME: | 470 | case MAILMIME_DISPOSITION_PARM_FILENAME: |
471 | r = mailimf_string_write(f, col, "filename=", 9); | 471 | r = mailimf_string_write(f, col, "filename=", 9); |
472 | if (r != MAILIMF_NO_ERROR) | 472 | if (r != MAILIMF_NO_ERROR) |
473 | return r; | 473 | return r; |
474 | 474 | ||
475 | r = mailimf_quoted_string_write(f, col, | 475 | r = mailimf_quoted_string_write(f, col, |
476 | param->pa_data.pa_filename, strlen(param->pa_data.pa_filename)); | 476 | param->pa_data.pa_filename, strlen(param->pa_data.pa_filename)); |
diff --git a/kmicromail/libetpan/smtp/mailsmtp.c b/kmicromail/libetpan/smtp/mailsmtp.c index b3be432..3ab1d11 100644 --- a/kmicromail/libetpan/smtp/mailsmtp.c +++ b/kmicromail/libetpan/smtp/mailsmtp.c | |||
@@ -163,64 +163,66 @@ int mailsmtp_quit(mailsmtp * session) | |||
163 | return MAILSMTP_ERROR_STREAM; | 163 | return MAILSMTP_ERROR_STREAM; |
164 | r = read_response(session); | 164 | r = read_response(session); |
165 | if (r == 0) | 165 | if (r == 0) |
166 | return MAILSMTP_ERROR_STREAM; | 166 | return MAILSMTP_ERROR_STREAM; |
167 | mailstream_close(session->stream); | 167 | mailstream_close(session->stream); |
168 | session->stream = NULL; | 168 | session->stream = NULL; |
169 | 169 | ||
170 | return MAILSMTP_NO_ERROR; | 170 | return MAILSMTP_NO_ERROR; |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | 174 | ||
175 | #define HOSTNAME_SIZE 256 | 175 | #define HOSTNAME_SIZE 256 |
176 | 176 | ||
177 | int mailsmtp_helo(mailsmtp * session) | 177 | int mailsmtp_helo(mailsmtp * session) |
178 | { | 178 | { |
179 | int r; | 179 | int r; |
180 | char hostname[HOSTNAME_SIZE]; | 180 | char hostname[HOSTNAME_SIZE]; |
181 | char command[SMTP_STRING_SIZE]; | 181 | char command[SMTP_STRING_SIZE]; |
182 | 182 | ||
183 | r = gethostname(hostname, HOSTNAME_SIZE); | 183 | r = gethostname(hostname, HOSTNAME_SIZE); |
184 | if (r < 0) | 184 | if (r < 0) |
185 | return MAILSMTP_ERROR_HOSTNAME; | 185 | return MAILSMTP_ERROR_HOSTNAME; |
186 | 186 | ||
187 | snprintf(command, SMTP_STRING_SIZE, "HELO %s\r\n", hostname); | 187 | snprintf(command, SMTP_STRING_SIZE, "HELO %s\r\n", hostname); |
188 | r = send_command(session, command); | 188 | r = send_command(session, command); |
189 | if (r == -1) | 189 | if (r == -1) |
190 | return MAILSMTP_ERROR_STREAM; | 190 | return MAILSMTP_ERROR_STREAM; |
191 | r = read_response(session); | 191 | r = read_response(session); |
192 | 192 | ||
193 | switch (r) { | 193 | switch (r) { |
194 | case 250: | 194 | case 250: |
195 | session->esmtp = 0; | ||
196 | session->auth = MAILSMTP_AUTH_NOT_CHECKED; | ||
195 | return MAILSMTP_NO_ERROR; | 197 | return MAILSMTP_NO_ERROR; |
196 | 198 | ||
197 | case 504: | 199 | case 504: |
198 | return MAILSMTP_ERROR_NOT_IMPLEMENTED; | 200 | return MAILSMTP_ERROR_NOT_IMPLEMENTED; |
199 | 201 | ||
200 | case 550: | 202 | case 550: |
201 | return MAILSMTP_ERROR_ACTION_NOT_TAKEN; | 203 | return MAILSMTP_ERROR_ACTION_NOT_TAKEN; |
202 | 204 | ||
203 | case 0: | 205 | case 0: |
204 | return MAILSMTP_ERROR_STREAM; | 206 | return MAILSMTP_ERROR_STREAM; |
205 | 207 | ||
206 | default: | 208 | default: |
207 | return MAILSMTP_ERROR_UNEXPECTED_CODE; | 209 | return MAILSMTP_ERROR_UNEXPECTED_CODE; |
208 | } | 210 | } |
209 | } | 211 | } |
210 | 212 | ||
211 | int mailsmtp_mail(mailsmtp * session, const char * from) | 213 | int mailsmtp_mail(mailsmtp * session, const char * from) |
212 | { | 214 | { |
213 | int r; | 215 | int r; |
214 | char command[SMTP_STRING_SIZE]; | 216 | char command[SMTP_STRING_SIZE]; |
215 | 217 | ||
216 | snprintf(command, SMTP_STRING_SIZE, "MAIL FROM:<%s>\r\n", from); | 218 | snprintf(command, SMTP_STRING_SIZE, "MAIL FROM:<%s>\r\n", from); |
217 | r = send_command(session, command); | 219 | r = send_command(session, command); |
218 | if (r == -1) | 220 | if (r == -1) |
219 | return MAILSMTP_ERROR_STREAM; | 221 | return MAILSMTP_ERROR_STREAM; |
220 | r = read_response(session); | 222 | r = read_response(session); |
221 | 223 | ||
222 | switch (r) { | 224 | switch (r) { |
223 | case 250: | 225 | case 250: |
224 | return MAILSMTP_NO_ERROR; | 226 | return MAILSMTP_NO_ERROR; |
225 | 227 | ||
226 | case 552: | 228 | case 552: |
diff --git a/kmicromail/libetpan/smtp/mailsmtp_helper.c b/kmicromail/libetpan/smtp/mailsmtp_helper.c index 32d6564..7995377 100644 --- a/kmicromail/libetpan/smtp/mailsmtp_helper.c +++ b/kmicromail/libetpan/smtp/mailsmtp_helper.c | |||
@@ -12,77 +12,73 @@ | |||
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the libEtPan! project nor the names of its | 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 | 16 | * contributors may be used to endorse or promote products derived |
17 | * from this software without specific prior written permission. | 17 | * from this software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 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 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 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 | 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 | 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 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | 29 | * SUCH DAMAGE. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * $Id$ | 33 | * $Id$ |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "mailsmtp.h" | 36 | #include "mailsmtp.h" |
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
39 | #include "mail.h" | 39 | #include "mail.h" |
40 | 40 | ||
41 | int mailsmtp_init(mailsmtp * session) | 41 | int mailsmtp_init(mailsmtp * session) |
42 | { | 42 | { |
43 | int r; | 43 | int r; |
44 | session->esmtp = 0; | 44 | |
45 | r = mailesmtp_ehlo(session); | 45 | r = mailesmtp_ehlo(session); |
46 | 46 | ||
47 | if (r == MAILSMTP_NO_ERROR) { | 47 | if (r == MAILSMTP_NO_ERROR) |
48 | // session->esmtp = TRUE; | ||
49 | return MAILSMTP_NO_ERROR; | 48 | return MAILSMTP_NO_ERROR; |
50 | } | ||
51 | 49 | ||
52 | r = mailsmtp_helo(session); | 50 | r = mailsmtp_helo(session); |
53 | /* if (r == MAILSMTP_NO_ERROR) { */ | 51 | if (r == MAILSMTP_NO_ERROR) |
54 | /* session->esmtp = FALSE; */ | 52 | return MAILSMTP_NO_ERROR; |
55 | /* return MAILSMTP_NO_ERROR; */ | ||
56 | /* } */ | ||
57 | 53 | ||
58 | return r; | 54 | return r; |
59 | } | 55 | } |
60 | 56 | ||
61 | 57 | ||
62 | 58 | ||
63 | int mailesmtp_send(mailsmtp * session, | 59 | int mailesmtp_send(mailsmtp * session, |
64 | const char * from, | 60 | const char * from, |
65 | int return_full, | 61 | int return_full, |
66 | const char * envid, | 62 | const char * envid, |
67 | clist * addresses, | 63 | clist * addresses, |
68 | const char * message, size_t size) | 64 | const char * message, size_t size) |
69 | { | 65 | { |
70 | int r; | 66 | int r; |
71 | clistiter * l; | 67 | clistiter * l; |
72 | 68 | ||
73 | if (!session->esmtp) | 69 | if (!session->esmtp) |
74 | return mailsmtp_send(session, from, addresses, message, size); | 70 | return mailsmtp_send(session, from, addresses, message, size); |
75 | 71 | ||
76 | r = mailesmtp_mail(session, from, return_full, envid); | 72 | r = mailesmtp_mail(session, from, return_full, envid); |
77 | if (r != MAILSMTP_NO_ERROR) | 73 | if (r != MAILSMTP_NO_ERROR) |
78 | return r; | 74 | return r; |
79 | 75 | ||
80 | for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) { | 76 | for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) { |
81 | struct esmtp_address * addr; | 77 | struct esmtp_address * addr; |
82 | 78 | ||
83 | addr = clist_content(l); | 79 | addr = clist_content(l); |
84 | 80 | ||
85 | r = mailesmtp_rcpt(session, addr->address, addr->notify, addr->orcpt); | 81 | r = mailesmtp_rcpt(session, addr->address, addr->notify, addr->orcpt); |
86 | if (r != MAILSMTP_NO_ERROR) | 82 | if (r != MAILSMTP_NO_ERROR) |
87 | return r; | 83 | return r; |
88 | } | 84 | } |
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp index 3998abd..3b0ca1f 100644 --- a/kmicromail/libmailwrapper/abstractmail.cpp +++ b/kmicromail/libmailwrapper/abstractmail.cpp | |||
@@ -1,41 +1,43 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "abstractmail.h" | 2 | #include "abstractmail.h" |
3 | #include "imapwrapper.h" | 3 | #include "imapwrapper.h" |
4 | #include "pop3wrapper.h" | 4 | #include "pop3wrapper.h" |
5 | #include "nntpwrapper.h" | 5 | #include "nntpwrapper.h" |
6 | #include "mhwrapper.h" | 6 | #include "mhwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | 8 | ||
9 | 9 | ||
10 | #include <qprogressbar.h> | ||
11 | #include <qapplication.h> | ||
10 | 12 | ||
11 | #include <kdecore/kstandarddirs.h> | 13 | #include <kdecore/kstandarddirs.h> |
12 | #include <qfile.h> | 14 | #include <qfile.h> |
13 | #include <qtextstream.h> | 15 | #include <qtextstream.h> |
14 | #include <stdlib.h> | 16 | #include <stdlib.h> |
15 | #include <libetpan/mailmime_content.h> | 17 | #include <libetpan/mailmime_content.h> |
16 | #include <libetpan/mailmime.h> | 18 | #include <libetpan/mailmime.h> |
17 | 19 | ||
18 | using namespace Opie::Core; | 20 | using namespace Opie::Core; |
19 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 21 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
20 | { | 22 | { |
21 | return new IMAPwrapper(a); | 23 | return new IMAPwrapper(a); |
22 | } | 24 | } |
23 | 25 | ||
24 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 26 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
25 | { | 27 | { |
26 | return new POP3wrapper(a); | 28 | return new POP3wrapper(a); |
27 | } | 29 | } |
28 | 30 | ||
29 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) | 31 | AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) |
30 | { | 32 | { |
31 | return new NNTPwrapper(a); | 33 | return new NNTPwrapper(a); |
32 | } | 34 | } |
33 | 35 | ||
34 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) | 36 | AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) |
35 | { | 37 | { |
36 | return new MHwrapper(a,name); | 38 | return new MHwrapper(a,name); |
37 | } | 39 | } |
38 | 40 | ||
39 | AbstractMail* AbstractMail::getWrapper(Account*a) | 41 | AbstractMail* AbstractMail::getWrapper(Account*a) |
40 | { | 42 | { |
41 | if (!a) return 0; | 43 | if (!a) return 0; |
@@ -111,77 +113,125 @@ QString AbstractMail::gen_attachment_id() | |||
111 | if (!file.open(IO_ReadOnly ) ) | 113 | if (!file.open(IO_ReadOnly ) ) |
112 | return QString::null; | 114 | return QString::null; |
113 | 115 | ||
114 | QTextStream stream(&file); | 116 | QTextStream stream(&file); |
115 | 117 | ||
116 | return "{" + stream.read().stripWhiteSpace() + "}"; | 118 | return "{" + stream.read().stripWhiteSpace() + "}"; |
117 | } | 119 | } |
118 | 120 | ||
119 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) | 121 | int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) |
120 | { | 122 | { |
121 | return 0; | 123 | return 0; |
122 | } | 124 | } |
123 | 125 | ||
124 | QString AbstractMail::defaultLocalfolder() | 126 | QString AbstractMail::defaultLocalfolder() |
125 | { | 127 | { |
126 | // QString f = getenv( "HOME" ); | 128 | // QString f = getenv( "HOME" ); |
127 | QString f = locateLocal( "data", "kmicromail/localmail"); | 129 | QString f = locateLocal( "data", "kmicromail/localmail"); |
128 | // f += "/Applications/opiemail/localmail"; | 130 | // f += "/Applications/opiemail/localmail"; |
129 | return f; | 131 | return f; |
130 | } | 132 | } |
131 | 133 | ||
132 | QString AbstractMail::draftFolder() | 134 | QString AbstractMail::draftFolder() |
133 | { | 135 | { |
134 | return QString("Drafts"); | 136 | return QString("Drafts"); |
135 | } | 137 | } |
136 | 138 | ||
137 | /* temporary - will be removed when implemented in all classes */ | 139 | /* temporary - will be removed when implemented in all classes */ |
138 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) | 140 | void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) |
139 | { | 141 | { |
140 | } | 142 | } |
141 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) | 143 | void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) |
142 | { | 144 | { |
143 | qDebug("AbstractMail::deleteMailList:: Please reimplement! "); | 145 | //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); |
144 | 146 | // this is currently re-implemented in pop3wrapper and imapwrapper | |
147 | int iii = 0; | ||
148 | int count = target.count(); | ||
149 | QProgressBar bar( count,0 ); | ||
150 | bar.setCaption (("Removing mails - close to abort!") ); | ||
151 | int w = 300; | ||
152 | if ( QApplication::desktop()->width() < 320 ) | ||
153 | w = 220; | ||
154 | int h = bar.sizeHint().height() ; | ||
155 | int dw = QApplication::desktop()->width(); | ||
156 | int dh = QApplication::desktop()->height(); | ||
157 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
158 | bar.show(); | ||
159 | int modulo = (count/10)+1; | ||
160 | int incCounter = 0; | ||
161 | while (iii < count ) { | ||
162 | if ( ! bar.isVisible() ) | ||
163 | return ; | ||
164 | if ( incCounter % modulo == 0 ) | ||
165 | bar.setProgress( incCounter ); | ||
166 | ++incCounter; | ||
167 | qApp->processEvents(); | ||
168 | RecMailP mail = (*target.at( iii )); | ||
169 | deleteMail(mail); | ||
170 | ++iii; | ||
171 | } | ||
145 | } | 172 | } |
146 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, | 173 | void AbstractMail::mvcpAllMails(const FolderP&fromFolder, |
147 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 174 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
148 | { | 175 | { |
149 | QValueList<RecMailP> t; | 176 | QValueList<RecMailP> t; |
150 | listMessages(fromFolder->getName(),t, maxSizeInKb); | 177 | listMessages(fromFolder->getName(),t, maxSizeInKb); |
151 | mvcpMailList( t,targetFolder,targetWrapper,moveit); | 178 | mvcpMailList( t,targetFolder,targetWrapper,moveit); |
152 | 179 | ||
153 | } | 180 | } |
154 | void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, | 181 | void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, |
155 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 182 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
156 | { | 183 | { |
157 | |||
158 | encodedString*st = 0; | 184 | encodedString*st = 0; |
159 | int iii = 0; | 185 | int iii = 0; |
160 | int count = t.count(); | 186 | int count = t.count(); |
187 | if ( count == 0 ) | ||
188 | return; | ||
189 | |||
190 | QProgressBar bar( count,0 ); | ||
191 | bar.setCaption (("Copying mails - close to abort!") ); | ||
192 | int w = 300; | ||
193 | if ( QApplication::desktop()->width() < 320 ) | ||
194 | w = 220; | ||
195 | int h = bar.sizeHint().height() ; | ||
196 | int dw = QApplication::desktop()->width(); | ||
197 | int dh = QApplication::desktop()->height(); | ||
198 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
199 | bar.show(); | ||
200 | int modulo = (count/10)+1; | ||
201 | int incCounter = 0; | ||
161 | while (iii < count ) { | 202 | while (iii < count ) { |
203 | if ( ! bar.isVisible() ) | ||
204 | return ; | ||
205 | if ( incCounter % modulo == 0 ) | ||
206 | bar.setProgress( incCounter ); | ||
207 | ++incCounter; | ||
208 | bar.raise(); | ||
209 | qApp->processEvents(); | ||
210 | //qDebug("copy "); | ||
162 | RecMailP r = (*t.at( iii )); | 211 | RecMailP r = (*t.at( iii )); |
163 | st = fetchRawBody(r); | 212 | st = fetchRawBody(r); |
164 | if (st) { | 213 | if (st) { |
165 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 214 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
166 | delete st; | 215 | delete st; |
167 | } | 216 | } |
168 | ++iii; | 217 | ++iii; |
169 | } | 218 | } |
219 | bar.hide(); | ||
170 | if (moveit) { | 220 | if (moveit) { |
171 | deleteMailList( t ); | 221 | deleteMailList( t ); |
172 | //deleteAllMail(fromFolder); | 222 | //deleteAllMail(fromFolder); |
173 | } | 223 | } |
174 | } | 224 | } |
175 | 225 | ||
176 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 226 | void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
177 | { | 227 | { |
178 | encodedString*st = 0; | 228 | encodedString*st = 0; |
179 | st = fetchRawBody(mail); | 229 | st = fetchRawBody(mail); |
180 | if (st) { | 230 | if (st) { |
181 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); | 231 | targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); |
182 | delete st; | 232 | delete st; |
183 | } | 233 | } |
184 | if (moveit) { | 234 | if (moveit) { |
185 | deleteMail(mail); | 235 | deleteMail(mail); |
186 | } | 236 | } |
187 | } | 237 | } |
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index bb8bbfc..11d3343 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,40 +1,41 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | #include <qprogressbar.h> | ||
9 | 10 | ||
10 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
11 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
12 | : AbstractMail() | 13 | : AbstractMail() |
13 | { | 14 | { |
14 | account = a; | 15 | account = a; |
15 | m_imap = 0; | 16 | m_imap = 0; |
16 | m_Lastmbox = ""; | 17 | m_Lastmbox = ""; |
17 | } | 18 | } |
18 | 19 | ||
19 | IMAPwrapper::~IMAPwrapper() | 20 | IMAPwrapper::~IMAPwrapper() |
20 | { | 21 | { |
21 | logout(); | 22 | logout(); |
22 | } | 23 | } |
23 | 24 | ||
24 | /* to avoid to often select statements in loops etc. | 25 | /* to avoid to often select statements in loops etc. |
25 | we trust that we are logged in and connection is established!*/ | 26 | we trust that we are logged in and connection is established!*/ |
26 | int IMAPwrapper::selectMbox(const QString&mbox) | 27 | int IMAPwrapper::selectMbox(const QString&mbox) |
27 | { | 28 | { |
28 | if (mbox == m_Lastmbox) { | 29 | if (mbox == m_Lastmbox) { |
29 | return MAILIMAP_NO_ERROR; | 30 | return MAILIMAP_NO_ERROR; |
30 | } | 31 | } |
31 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
32 | if ( err != MAILIMAP_NO_ERROR ) { | 33 | if ( err != MAILIMAP_NO_ERROR ) { |
33 | m_Lastmbox = ""; | 34 | m_Lastmbox = ""; |
34 | return err; | 35 | return err; |
35 | } | 36 | } |
36 | m_Lastmbox = mbox; | 37 | m_Lastmbox = mbox; |
37 | return err; | 38 | return err; |
38 | } | 39 | } |
39 | 40 | ||
40 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 41 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
@@ -842,139 +843,168 @@ void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which | |||
842 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 843 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
843 | encoding = "7bit"; | 844 | encoding = "7bit"; |
844 | break; | 845 | break; |
845 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 846 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
846 | encoding = "8bit"; | 847 | encoding = "8bit"; |
847 | break; | 848 | break; |
848 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 849 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
849 | encoding="binary"; | 850 | encoding="binary"; |
850 | break; | 851 | break; |
851 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 852 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
852 | encoding="base64"; | 853 | encoding="base64"; |
853 | break; | 854 | break; |
854 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 855 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
855 | encoding="quoted-printable"; | 856 | encoding="quoted-printable"; |
856 | break; | 857 | break; |
857 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 858 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
858 | default: | 859 | default: |
859 | if (enc->enc_value) { | 860 | if (enc->enc_value) { |
860 | char*t=enc->enc_value; | 861 | char*t=enc->enc_value; |
861 | encoding=QString(enc->enc_value); | 862 | encoding=QString(enc->enc_value); |
862 | enc->enc_value=0L; | 863 | enc->enc_value=0L; |
863 | free(t); | 864 | free(t); |
864 | } | 865 | } |
865 | } | 866 | } |
866 | if (which->bd_description) { | 867 | if (which->bd_description) { |
867 | target_part->setDescription(QString(which->bd_description)); | 868 | target_part->setDescription(QString(which->bd_description)); |
868 | } | 869 | } |
869 | target_part->setEncoding(encoding); | 870 | target_part->setEncoding(encoding); |
870 | target_part->setSize(which->bd_size); | 871 | target_part->setSize(which->bd_size); |
871 | } | 872 | } |
872 | void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) | 873 | void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) |
873 | { | 874 | { |
875 | //#if 0 | ||
874 | mailimap_flag_list*flist; | 876 | mailimap_flag_list*flist; |
875 | mailimap_set *set; | 877 | mailimap_set *set; |
876 | mailimap_store_att_flags * store_flags; | 878 | mailimap_store_att_flags * store_flags; |
877 | int err; | 879 | int err; |
878 | login(); | 880 | login(); |
881 | //#endif | ||
879 | if (!m_imap) { | 882 | if (!m_imap) { |
880 | return; | 883 | return; |
881 | } | 884 | } |
882 | int iii = 0; | 885 | int iii = 0; |
883 | int count = target.count(); | 886 | int count = target.count(); |
884 | qDebug("imap remove count %d ", count); | 887 | // qDebug("imap remove count %d ", count); |
888 | |||
889 | QProgressBar bar( count,0 ); | ||
890 | bar.setCaption (("Removing mails - close to abort!") ); | ||
891 | int w = 300; | ||
892 | if ( QApplication::desktop()->width() < 320 ) | ||
893 | w = 220; | ||
894 | int h = bar.sizeHint().height() ; | ||
895 | int dw = QApplication::desktop()->width(); | ||
896 | int dh = QApplication::desktop()->height(); | ||
897 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
898 | bar.show(); | ||
899 | int modulo = (count/10)+1; | ||
900 | int incCounter = 0; | ||
901 | |||
885 | while (iii < count ) { | 902 | while (iii < count ) { |
886 | qDebug("IMAP remove %d ", iii); | 903 | if ( ! bar.isVisible() ) |
904 | return ; | ||
905 | if ( incCounter % modulo == 0 ) | ||
906 | bar.setProgress( incCounter ); | ||
907 | ++incCounter; | ||
908 | qApp->processEvents(); | ||
887 | RecMailP mail = (*target.at( iii )); | 909 | RecMailP mail = (*target.at( iii )); |
888 | 910 | //#if 0 | |
911 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); | ||
889 | err = selectMbox(mail->getMbox()); | 912 | err = selectMbox(mail->getMbox()); |
890 | if ( err != MAILIMAP_NO_ERROR ) { | 913 | if ( err != MAILIMAP_NO_ERROR ) { |
891 | return; | 914 | return; |
892 | } | 915 | } |
893 | flist = mailimap_flag_list_new_empty(); | 916 | flist = mailimap_flag_list_new_empty(); |
894 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 917 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
895 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 918 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
896 | set = mailimap_set_new_single(mail->getNumber()); | 919 | set = mailimap_set_new_single(mail->getNumber()); |
897 | err = mailimap_store(m_imap,set,store_flags); | 920 | err = mailimap_store(m_imap,set,store_flags); |
898 | mailimap_set_free( set ); | 921 | mailimap_set_free( set ); |
899 | mailimap_store_att_flags_free(store_flags); | 922 | mailimap_store_att_flags_free(store_flags); |
900 | 923 | ||
901 | if (err != MAILIMAP_NO_ERROR) { | 924 | if (err != MAILIMAP_NO_ERROR) { |
902 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 925 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
903 | return; | 926 | return; |
904 | } | 927 | } |
905 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 928 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
906 | /* should we realy do that at this moment? */ | 929 | /* should we realy do that at this moment? */ |
907 | 930 | ||
931 | // err = mailimap_expunge(m_imap); | ||
932 | //if (err != MAILIMAP_NO_ERROR) { | ||
933 | // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); | ||
934 | // } | ||
935 | //#endif | ||
936 | //deleteMail( mail); | ||
937 | ++iii; | ||
938 | } | ||
939 | //qDebug("Deleting imap mails... "); | ||
908 | err = mailimap_expunge(m_imap); | 940 | err = mailimap_expunge(m_imap); |
909 | if (err != MAILIMAP_NO_ERROR) { | 941 | if (err != MAILIMAP_NO_ERROR) { |
910 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 942 | Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); |
911 | } | 943 | } |
912 | ++iii; | ||
913 | } | ||
914 | } | 944 | } |
915 | void IMAPwrapper::deleteMail(const RecMailP&mail) | 945 | void IMAPwrapper::deleteMail(const RecMailP&mail) |
916 | { | 946 | { |
917 | mailimap_flag_list*flist; | 947 | mailimap_flag_list*flist; |
918 | mailimap_set *set; | 948 | mailimap_set *set; |
919 | mailimap_store_att_flags * store_flags; | 949 | mailimap_store_att_flags * store_flags; |
920 | int err; | 950 | int err; |
921 | login(); | 951 | login(); |
922 | if (!m_imap) { | 952 | if (!m_imap) { |
923 | return; | 953 | return; |
924 | } | 954 | } |
925 | err = selectMbox(mail->getMbox()); | 955 | err = selectMbox(mail->getMbox()); |
926 | if ( err != MAILIMAP_NO_ERROR ) { | 956 | if ( err != MAILIMAP_NO_ERROR ) { |
927 | return; | 957 | return; |
928 | } | 958 | } |
929 | flist = mailimap_flag_list_new_empty(); | 959 | flist = mailimap_flag_list_new_empty(); |
930 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 960 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
931 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 961 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
932 | set = mailimap_set_new_single(mail->getNumber()); | 962 | set = mailimap_set_new_single(mail->getNumber()); |
933 | err = mailimap_store(m_imap,set,store_flags); | 963 | err = mailimap_store(m_imap,set,store_flags); |
934 | mailimap_set_free( set ); | 964 | mailimap_set_free( set ); |
935 | mailimap_store_att_flags_free(store_flags); | 965 | mailimap_store_att_flags_free(store_flags); |
936 | 966 | ||
937 | if (err != MAILIMAP_NO_ERROR) { | 967 | if (err != MAILIMAP_NO_ERROR) { |
938 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 968 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
939 | return; | 969 | return; |
940 | } | 970 | } |
941 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 971 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
942 | /* should we realy do that at this moment? */ | 972 | /* should we realy do that at this moment? */ |
943 | 973 | ||
944 | err = mailimap_expunge(m_imap); | 974 | err = mailimap_expunge(m_imap); |
945 | if (err != MAILIMAP_NO_ERROR) { | 975 | if (err != MAILIMAP_NO_ERROR) { |
946 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 976 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
947 | } | 977 | } |
948 | qDebug("IMAPwrapper::deleteMail "); | 978 | //qDebug("IMAPwrapper::deleteMail 2"); |
949 | 979 | ||
950 | } | 980 | } |
951 | 981 | ||
952 | void IMAPwrapper::answeredMail(const RecMailP&mail) | 982 | void IMAPwrapper::answeredMail(const RecMailP&mail) |
953 | { | 983 | { |
954 | mailimap_flag_list*flist; | 984 | mailimap_flag_list*flist; |
955 | mailimap_set *set; | 985 | mailimap_set *set; |
956 | mailimap_store_att_flags * store_flags; | 986 | mailimap_store_att_flags * store_flags; |
957 | int err; | 987 | int err; |
958 | login(); | 988 | login(); |
959 | if (!m_imap) { | 989 | if (!m_imap) { |
960 | return; | 990 | return; |
961 | } | 991 | } |
962 | err = selectMbox(mail->getMbox()); | 992 | err = selectMbox(mail->getMbox()); |
963 | if ( err != MAILIMAP_NO_ERROR ) { | 993 | if ( err != MAILIMAP_NO_ERROR ) { |
964 | return; | 994 | return; |
965 | } | 995 | } |
966 | flist = mailimap_flag_list_new_empty(); | 996 | flist = mailimap_flag_list_new_empty(); |
967 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 997 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
968 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 998 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
969 | set = mailimap_set_new_single(mail->getNumber()); | 999 | set = mailimap_set_new_single(mail->getNumber()); |
970 | err = mailimap_store(m_imap,set,store_flags); | 1000 | err = mailimap_store(m_imap,set,store_flags); |
971 | mailimap_set_free( set ); | 1001 | mailimap_set_free( set ); |
972 | mailimap_store_att_flags_free(store_flags); | 1002 | mailimap_store_att_flags_free(store_flags); |
973 | 1003 | ||
974 | if (err != MAILIMAP_NO_ERROR) { | 1004 | if (err != MAILIMAP_NO_ERROR) { |
975 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; | 1005 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; |
976 | return; | 1006 | return; |
977 | } | 1007 | } |
978 | } | 1008 | } |
979 | 1009 | ||
980 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 1010 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
@@ -1160,65 +1190,65 @@ const QString&IMAPwrapper::getName()const | |||
1160 | } | 1190 | } |
1161 | 1191 | ||
1162 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1192 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1163 | { | 1193 | { |
1164 | // dummy | 1194 | // dummy |
1165 | QValueList<int> path; | 1195 | QValueList<int> path; |
1166 | return fetchRawPart(mail,path,false); | 1196 | return fetchRawPart(mail,path,false); |
1167 | } | 1197 | } |
1168 | 1198 | ||
1169 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1199 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1170 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 1200 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
1171 | { | 1201 | { |
1172 | if (targetWrapper != this || maxSizeInKb > 0 ) { | 1202 | if (targetWrapper != this || maxSizeInKb > 0 ) { |
1173 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); | 1203 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); |
1174 | qDebug("IMAPwrapper::mvcpAllMails::Using generic"); | 1204 | qDebug("IMAPwrapper::mvcpAllMails::Using generic"); |
1175 | // odebug << "Using generic" << oendl; | 1205 | // odebug << "Using generic" << oendl; |
1176 | return; | 1206 | return; |
1177 | } | 1207 | } |
1178 | mailimap_set *set = 0; | 1208 | mailimap_set *set = 0; |
1179 | login(); | 1209 | login(); |
1180 | if (!m_imap) { | 1210 | if (!m_imap) { |
1181 | return; | 1211 | return; |
1182 | } | 1212 | } |
1183 | int err = selectMbox(fromFolder->getName()); | 1213 | int err = selectMbox(fromFolder->getName()); |
1184 | if ( err != MAILIMAP_NO_ERROR ) { | 1214 | if ( err != MAILIMAP_NO_ERROR ) { |
1185 | return; | 1215 | return; |
1186 | } | 1216 | } |
1187 | int last = m_imap->imap_selection_info->sel_exists; | 1217 | int last = m_imap->imap_selection_info->sel_exists; |
1188 | set = mailimap_set_new_interval( 1, last ); | 1218 | set = mailimap_set_new_interval( 1, last ); |
1189 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1219 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1190 | mailimap_set_free( set ); | 1220 | mailimap_set_free( set ); |
1191 | if ( err != MAILIMAP_NO_ERROR ) { | 1221 | if ( err != MAILIMAP_NO_ERROR ) { |
1192 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); | 1222 | QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); |
1193 | Global::statusMessage(error_msg); | 1223 | Global::statusMessage(error_msg); |
1194 | // odebug << error_msg << oendl; | 1224 | // odebug << error_msg << oendl; |
1195 | return; | 1225 | return; |
1196 | } | 1226 | } |
1197 | if (moveit) { | 1227 | if (moveit) { |
1198 | deleteAllMail(fromFolder); | 1228 | deleteAllMail(fromFolder); |
1199 | } | 1229 | } |
1200 | } | 1230 | } |
1201 | 1231 | ||
1202 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1232 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1203 | { | 1233 | { |
1204 | if (targetWrapper != this) { | 1234 | if (targetWrapper != this) { |
1205 | // odebug << "Using generic" << oendl; | 1235 | // odebug << "Using generic" << oendl; |
1206 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 1236 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
1207 | return; | 1237 | return; |
1208 | } | 1238 | } |
1209 | mailimap_set *set = 0; | 1239 | mailimap_set *set = 0; |
1210 | login(); | 1240 | login(); |
1211 | if (!m_imap) { | 1241 | if (!m_imap) { |
1212 | return; | 1242 | return; |
1213 | } | 1243 | } |
1214 | int err = selectMbox(mail->getMbox()); | 1244 | int err = selectMbox(mail->getMbox()); |
1215 | if ( err != MAILIMAP_NO_ERROR ) { | 1245 | if ( err != MAILIMAP_NO_ERROR ) { |
1216 | return; | 1246 | return; |
1217 | } | 1247 | } |
1218 | set = mailimap_set_new_single(mail->getNumber()); | 1248 | set = mailimap_set_new_single(mail->getNumber()); |
1219 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1249 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1220 | mailimap_set_free( set ); | 1250 | mailimap_set_free( set ); |
1221 | if ( err != MAILIMAP_NO_ERROR ) { | 1251 | if ( err != MAILIMAP_NO_ERROR ) { |
1222 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); | 1252 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); |
1223 | Global::statusMessage(error_msg); | 1253 | Global::statusMessage(error_msg); |
1224 | // odebug << error_msg << oendl; | 1254 | // odebug << error_msg << oendl; |
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp index 7a84b30..0e6612c 100644 --- a/kmicromail/libmailwrapper/pop3wrapper.cpp +++ b/kmicromail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,42 +1,44 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | #include "logindialog.h" | 5 | #include "logindialog.h" |
6 | #include <libetpan/libetpan.h> | 6 | #include <libetpan/libetpan.h> |
7 | 7 | ||
8 | 8 | ||
9 | #include <qpe/global.h> | 9 | #include <qpe/global.h> |
10 | #include <qfile.h> | 10 | #include <qfile.h> |
11 | #include <qprogressbar.h> | ||
12 | #include <qapplication.h> | ||
11 | 13 | ||
12 | /* we don't fetch messages larger than 5 MB */ | 14 | /* we don't fetch messages larger than 5 MB */ |
13 | #define HARD_MSG_SIZE_LIMIT 5242880 | 15 | #define HARD_MSG_SIZE_LIMIT 5242880 |
14 | 16 | ||
15 | using namespace Opie::Core; | 17 | using namespace Opie::Core; |
16 | POP3wrapper::POP3wrapper( POP3account *a ) | 18 | POP3wrapper::POP3wrapper( POP3account *a ) |
17 | : Genericwrapper() { | 19 | : Genericwrapper() { |
18 | account = a; | 20 | account = a; |
19 | m_pop3 = NULL; | 21 | m_pop3 = NULL; |
20 | msgTempName = a->getFileName()+"_msg_cache"; | 22 | msgTempName = a->getFileName()+"_msg_cache"; |
21 | last_msg_id = 0; | 23 | last_msg_id = 0; |
22 | } | 24 | } |
23 | 25 | ||
24 | POP3wrapper::~POP3wrapper() { | 26 | POP3wrapper::~POP3wrapper() { |
25 | logout(); | 27 | logout(); |
26 | QFile msg_cache(msgTempName); | 28 | QFile msg_cache(msgTempName); |
27 | if (msg_cache.exists()) { | 29 | if (msg_cache.exists()) { |
28 | msg_cache.remove(); | 30 | msg_cache.remove(); |
29 | } | 31 | } |
30 | } | 32 | } |
31 | 33 | ||
32 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | 34 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { |
33 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; | 35 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; |
34 | } | 36 | } |
35 | 37 | ||
36 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { | 38 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { |
37 | int err = MAILPOP3_NO_ERROR; | 39 | int err = MAILPOP3_NO_ERROR; |
38 | char *message = 0; | 40 | char *message = 0; |
39 | size_t length = 0; | 41 | size_t length = 0; |
40 | 42 | ||
41 | RecBodyP body = new RecBody(); | 43 | RecBodyP body = new RecBody(); |
42 | 44 | ||
@@ -164,105 +166,142 @@ void POP3wrapper::login() | |||
164 | 166 | ||
165 | err = mailstorage_connect(m_pop3); | 167 | err = mailstorage_connect(m_pop3); |
166 | if (err != MAIL_NO_ERROR) { | 168 | if (err != MAIL_NO_ERROR) { |
167 | ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; | 169 | ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; |
168 | Global::statusMessage(tr("Error initializing folder")); | 170 | Global::statusMessage(tr("Error initializing folder")); |
169 | mailstorage_free(m_pop3); | 171 | mailstorage_free(m_pop3); |
170 | m_pop3 = 0; | 172 | m_pop3 = 0; |
171 | } else { | 173 | } else { |
172 | mailsession * session = m_pop3->sto_session; | 174 | mailsession * session = m_pop3->sto_session; |
173 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; | 175 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; |
174 | if (mail) { | 176 | if (mail) { |
175 | mail->pop3_progr_fun = &pop3_progress; | 177 | mail->pop3_progr_fun = &pop3_progress; |
176 | } | 178 | } |
177 | } | 179 | } |
178 | } | 180 | } |
179 | 181 | ||
180 | void POP3wrapper::logout() | 182 | void POP3wrapper::logout() |
181 | { | 183 | { |
182 | if ( m_pop3 == NULL ) | 184 | if ( m_pop3 == NULL ) |
183 | return; | 185 | return; |
184 | mailstorage_free(m_pop3); | 186 | mailstorage_free(m_pop3); |
185 | m_pop3 = 0; | 187 | m_pop3 = 0; |
186 | } | 188 | } |
187 | 189 | ||
188 | 190 | ||
189 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { | 191 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { |
190 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); | 192 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); |
191 | FolderP inb=new Folder("INBOX","/"); | 193 | FolderP inb=new Folder("INBOX","/"); |
192 | folders->append(inb); | 194 | folders->append(inb); |
193 | return folders; | 195 | return folders; |
194 | } | 196 | } |
195 | 197 | ||
196 | void POP3wrapper::deleteMailList(QValueList<RecMailP>&target) | 198 | void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) |
197 | { | 199 | { |
198 | login(); | 200 | login(); |
199 | if (!m_pop3) | 201 | if (!m_pop3) |
200 | return; | 202 | return; |
201 | int iii = 0; | 203 | int iii = 0; |
202 | int count = target.count(); | 204 | int count = target.count(); |
203 | while (iii < count ) { | 205 | QProgressBar bar( count,0 ); |
206 | bar.setCaption (("Removing mails - close to abort!") ); | ||
207 | int w = 300; | ||
208 | if ( QApplication::desktop()->width() < 320 ) | ||
209 | w = 220; | ||
210 | int h = bar.sizeHint().height() ; | ||
211 | int dw = QApplication::desktop()->width(); | ||
212 | int dh = QApplication::desktop()->height(); | ||
213 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
214 | bar.show(); | ||
215 | int modulo = (count/10)+1; | ||
216 | int incCounter = 0; | ||
217 | while (iii < count ) { | ||
218 | if ( ! bar.isVisible() ) | ||
219 | return ; | ||
220 | if ( incCounter % modulo == 0 ) | ||
221 | bar.setProgress( incCounter ); | ||
222 | ++incCounter; | ||
223 | qApp->processEvents(); | ||
224 | //qDebug("delete "); | ||
204 | RecMailP mail = (*target.at( iii )); | 225 | RecMailP mail = (*target.at( iii )); |
205 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 226 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
206 | if (err != MAIL_NO_ERROR) { | 227 | if (err != MAIL_NO_ERROR) { |
207 | Global::statusMessage(tr("error deleting mail")); | 228 | Global::statusMessage(tr("Error deleting mail")); |
208 | } | 229 | } |
209 | ++iii; | 230 | ++iii; |
210 | } | 231 | } |
211 | } | 232 | } |
212 | void POP3wrapper::deleteMail(const RecMailP&mail) { | 233 | void POP3wrapper::deleteMail(const RecMailP&mail) { |
213 | login(); | 234 | login(); |
214 | if (!m_pop3) | 235 | if (!m_pop3) |
215 | return; | 236 | return; |
216 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 237 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
217 | if (err != MAIL_NO_ERROR) { | 238 | if (err != MAIL_NO_ERROR) { |
218 | Global::statusMessage(tr("error deleting mail")); | 239 | Global::statusMessage(tr("error deleting mail")); |
219 | } | 240 | } |
220 | } | 241 | } |
221 | 242 | ||
222 | void POP3wrapper::answeredMail(const RecMailP&) {} | 243 | void POP3wrapper::answeredMail(const RecMailP&) {} |
223 | 244 | ||
224 | int POP3wrapper::deleteAllMail(const FolderP&) { | 245 | int POP3wrapper::deleteAllMail(const FolderP&) { |
225 | login(); | 246 | login(); |
226 | if (!m_pop3) | 247 | if (!m_pop3) |
227 | return 0; | 248 | return 0; |
228 | int res = 1; | 249 | int res = 1; |
229 | 250 | ||
230 | uint32_t result = 0; | 251 | uint32_t result = 0; |
231 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); | 252 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); |
232 | if (err != MAIL_NO_ERROR) { | 253 | if (err != MAIL_NO_ERROR) { |
233 | Global::statusMessage(tr("Error getting folder info")); | 254 | Global::statusMessage(tr("Error getting folder info")); |
234 | return 0; | 255 | return 0; |
235 | } | 256 | } |
257 | QProgressBar bar( result,0 ); | ||
258 | bar.setCaption (("Deleting mails - close to abort!") ); | ||
259 | int w = 300; | ||
260 | if ( QApplication::desktop()->width() < 320 ) | ||
261 | w = 220; | ||
262 | int h = bar.sizeHint().height() ; | ||
263 | int dw = QApplication::desktop()->width(); | ||
264 | int dh = QApplication::desktop()->height(); | ||
265 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
266 | bar.show(); | ||
267 | int modulo = (result/10)+1; | ||
268 | int incCounter = 0; | ||
236 | for (unsigned int i = 0; i < result; ++i) { | 269 | for (unsigned int i = 0; i < result; ++i) { |
270 | if ( ! bar.isVisible() ) | ||
271 | return 0; | ||
272 | if ( incCounter % modulo == 0 ) | ||
273 | bar.setProgress( incCounter ); | ||
274 | ++incCounter; | ||
275 | qApp->processEvents(); | ||
237 | err = mailsession_remove_message(m_pop3->sto_session,i+1); | 276 | err = mailsession_remove_message(m_pop3->sto_session,i+1); |
238 | if (err != MAIL_NO_ERROR) { | 277 | if (err != MAIL_NO_ERROR) { |
239 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 278 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
240 | res=0; | 279 | res=0; |
241 | } | 280 | } |
242 | break; | 281 | break; |
243 | } | 282 | } |
244 | return res; | 283 | return res; |
245 | } | 284 | } |
246 | 285 | ||
247 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { | 286 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { |
248 | login(); | 287 | login(); |
249 | target_stat.message_count = 0; | 288 | target_stat.message_count = 0; |
250 | target_stat.message_unseen = 0; | 289 | target_stat.message_unseen = 0; |
251 | target_stat.message_recent = 0; | 290 | target_stat.message_recent = 0; |
252 | if (!m_pop3) | 291 | if (!m_pop3) |
253 | return; | 292 | return; |
254 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, | 293 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, |
255 | &target_stat.message_recent,&target_stat.message_unseen); | 294 | &target_stat.message_recent,&target_stat.message_unseen); |
256 | if (r != MAIL_NO_ERROR) { | 295 | if (r != MAIL_NO_ERROR) { |
257 | ; // odebug << "error getting folter status." << oendl; | 296 | ; // odebug << "error getting folter status." << oendl; |
258 | } | 297 | } |
259 | } | 298 | } |
260 | 299 | ||
261 | encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { | 300 | encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { |
262 | char*target=0; | 301 | char*target=0; |
263 | size_t length=0; | 302 | size_t length=0; |
264 | encodedString*res = 0; | 303 | encodedString*res = 0; |
265 | mailmessage * mailmsg = 0; | 304 | mailmessage * mailmsg = 0; |
266 | int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); | 305 | int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); |
267 | err = mailmessage_fetch(mailmsg,&target,&length); | 306 | err = mailmessage_fetch(mailmsg,&target,&length); |
268 | if (mailmsg) | 307 | if (mailmsg) |
diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h index ee754a4..7c70942 100644 --- a/kmicromail/libmailwrapper/pop3wrapper.h +++ b/kmicromail/libmailwrapper/pop3wrapper.h | |||
@@ -1,44 +1,44 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #ifndef __POP3WRAPPER | 2 | #ifndef __POP3WRAPPER |
3 | #define __POP3WRAPPER | 3 | #define __POP3WRAPPER |
4 | 4 | ||
5 | #include "mailwrapper.h" | 5 | #include "mailwrapper.h" |
6 | #include "genericwrapper.h" | 6 | #include "genericwrapper.h" |
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | 8 | ||
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailstorage; | 10 | struct mailstorage; |
11 | struct mailfolder; | 11 | struct mailfolder; |
12 | 12 | ||
13 | class POP3wrapper : public Genericwrapper | 13 | class POP3wrapper : public Genericwrapper |
14 | { | 14 | { |
15 | Q_OBJECT | 15 | Q_OBJECT |
16 | 16 | ||
17 | public: | 17 | public: |
18 | POP3wrapper( POP3account *a ); | 18 | POP3wrapper( POP3account *a ); |
19 | virtual ~POP3wrapper(); | 19 | virtual ~POP3wrapper(); |
20 | /* mailbox will be ignored */ | 20 | /* mailbox will be ignored */ |
21 | virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); | 21 | virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); |
22 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); | 22 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); |
23 | /* mailbox will be ignored */ | 23 | /* mailbox will be ignored */ |
24 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 24 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
25 | 25 | ||
26 | virtual void deleteMail(const RecMailP&mail); | 26 | virtual void deleteMail(const RecMailP&mail); |
27 | virtual void deleteMailList(const QValueList<RecMailP>&target); | ||
27 | virtual void answeredMail(const RecMailP&mail); | 28 | virtual void answeredMail(const RecMailP&mail); |
28 | virtual void deleteMailList(QValueList<RecMailP>&target); | ||
29 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); | 29 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); |
30 | 30 | ||
31 | virtual RecBodyP fetchBody( const RecMailP &mail ); | 31 | virtual RecBodyP fetchBody( const RecMailP &mail ); |
32 | virtual encodedString* fetchRawBody(const RecMailP&mail); | 32 | virtual encodedString* fetchRawBody(const RecMailP&mail); |
33 | virtual void logout(); | 33 | virtual void logout(); |
34 | virtual MAILLIB::ATYPE getType()const; | 34 | virtual MAILLIB::ATYPE getType()const; |
35 | virtual const QString&getName()const; | 35 | virtual const QString&getName()const; |
36 | static void pop3_progress( size_t current, size_t maximum ); | 36 | static void pop3_progress( size_t current, size_t maximum ); |
37 | 37 | ||
38 | protected: | 38 | protected: |
39 | void login(); | 39 | void login(); |
40 | POP3account *account; | 40 | POP3account *account; |
41 | mailstorage*m_pop3; | 41 | mailstorage*m_pop3; |
42 | }; | 42 | }; |
43 | 43 | ||
44 | #endif | 44 | #endif |
diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp index 3fbdcec..251f15a 100644 --- a/kmicromail/opiemail.cpp +++ b/kmicromail/opiemail.cpp | |||
@@ -1,53 +1,53 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | // CHANGED 2004-08-06 Lutz Rogowski | 2 | // CHANGED 2004-08-06 Lutz Rogowski |
3 | 3 | ||
4 | #include "settingsdialog.h" | 4 | #include "settingsdialog.h" |
5 | #include "opiemail.h" | 5 | #include "opiemail.h" |
6 | #include "editaccounts.h" | 6 | #include "editaccounts.h" |
7 | #include "composemail.h" | 7 | #include "composemail.h" |
8 | #include "mailistviewitem.h" | 8 | #include "mailistviewitem.h" |
9 | #include "viewmail.h" | 9 | #include "viewmail.h" |
10 | #include "selectstore.h" | 10 | #include "selectstore.h" |
11 | #include "selectsmtp.h" | 11 | #include "selectsmtp.h" |
12 | 12 | ||
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | 14 | ||
15 | #include <qpe/qpeapplication.h> | 15 | #include <qpe/qpeapplication.h> |
16 | #include <libmailwrapper/smtpwrapper.h> | 16 | #include <libmailwrapper/smtpwrapper.h> |
17 | #include <libmailwrapper/mailtypes.h> | 17 | #include <libmailwrapper/mailtypes.h> |
18 | #include <libmailwrapper/abstractmail.h> | 18 | #include <libmailwrapper/abstractmail.h> |
19 | /* OPIE */ | 19 | /* OPIE */ |
20 | //#include <qpe/resource.h> | 20 | //#include <qpe/resource.h> |
21 | #include <qpe/qpeapplication.h> | 21 | //#include <qpe/qpeapplication.h> |
22 | 22 | ||
23 | /* QT */ | 23 | /* QT */ |
24 | 24 | ||
25 | using namespace Opie::Core; | 25 | using namespace Opie::Core; |
26 | 26 | ||
27 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) | 27 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) |
28 | : MainWindow( parent, name) //, WStyle_ContextHelp ) | 28 | : MainWindow( parent, name) //, WStyle_ContextHelp ) |
29 | { | 29 | { |
30 | settings = new Settings(); | 30 | settings = new Settings(); |
31 | 31 | ||
32 | folderView->populate( settings->getAccounts() ); | 32 | folderView->populate( settings->getAccounts() ); |
33 | 33 | ||
34 | } | 34 | } |
35 | 35 | ||
36 | OpieMail::~OpieMail() | 36 | OpieMail::~OpieMail() |
37 | { | 37 | { |
38 | if (settings) delete settings; | 38 | if (settings) delete settings; |
39 | } | 39 | } |
40 | 40 | ||
41 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) | 41 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) |
42 | { | 42 | { |
43 | 43 | ||
44 | } | 44 | } |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | void OpieMail::message(const QCString &msg, const QByteArray &data) | 46 | void OpieMail::message(const QCString &msg, const QByteArray &data) |
47 | { | 47 | { |
48 | // copied from old mail2 | 48 | // copied from old mail2 |
49 | static int ii = 0; | 49 | static int ii = 0; |
50 | 50 | ||
51 | // block second call | 51 | // block second call |
52 | if ( ii < 2 ) { | 52 | if ( ii < 2 ) { |
53 | ++ii; | 53 | ++ii; |
@@ -208,107 +208,114 @@ void OpieMail::displayMail() | |||
208 | QListViewItem*item = mailView->currentItem(); | 208 | QListViewItem*item = mailView->currentItem(); |
209 | if (!item) return; | 209 | if (!item) return; |
210 | RecMailP mail = ((MailListViewItem*)item)->data(); | 210 | RecMailP mail = ((MailListViewItem*)item)->data(); |
211 | RecBodyP body = folderView->fetchBody(mail); | 211 | RecBodyP body = folderView->fetchBody(mail); |
212 | ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); | 212 | ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); |
213 | readMail.setBody( body ); | 213 | readMail.setBody( body ); |
214 | readMail.setMail( mail ); | 214 | readMail.setMail( mail ); |
215 | readMail.showMaximized(); | 215 | readMail.showMaximized(); |
216 | readMail.exec(); | 216 | readMail.exec(); |
217 | 217 | ||
218 | if ( readMail.deleted ) | 218 | if ( readMail.deleted ) |
219 | { | 219 | { |
220 | folderView->refreshCurrent(); | 220 | folderView->refreshCurrent(); |
221 | } | 221 | } |
222 | else | 222 | else |
223 | { | 223 | { |
224 | ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); | 224 | ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | void OpieMail::slotDeleteMail() | 228 | void OpieMail::slotDeleteMail() |
229 | { | 229 | { |
230 | if (!mailView->currentItem()) return; | 230 | if (!mailView->currentItem()) return; |
231 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 231 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); |
232 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) | 232 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) |
233 | { | 233 | { |
234 | mail->Wrapper()->deleteMail( mail ); | 234 | mail->Wrapper()->deleteMail( mail ); |
235 | folderView->refreshCurrent(); | 235 | folderView->refreshCurrent(); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | void OpieMail::slotDeleteAllMail() | 238 | void OpieMail::slotDeleteAllMail() |
239 | { | 239 | { |
240 | if (!mailView->currentItem()) return; | 240 | |
241 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 241 | QValueList<RecMailP> t; |
242 | if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) | 242 | if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) |
243 | { | 243 | { |
244 | MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); | 244 | MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); |
245 | while ( item ) { | 245 | while ( item ) { |
246 | if ( item->isSelected() ) { | 246 | if ( item->isSelected() ) { |
247 | RecMailP mail = item->data(); | 247 | t.append( item->data() ); |
248 | mail->Wrapper()->deleteMail( mail ); | 248 | } |
249 | item = (MailListViewItem*)item->nextSibling(); | ||
249 | } | 250 | } |
250 | item = (MailListViewItem*)item->nextSibling(); | ||
251 | } | 251 | } |
252 | folderView->refreshCurrent(); | 252 | else |
253 | } | 253 | return; |
254 | if ( t.count() == 0 ) | ||
255 | return; | ||
256 | RecMailP mail = t.first(); | ||
257 | mail->Wrapper()->deleteMailList(t); | ||
258 | folderView->refreshCurrent(); | ||
259 | |||
260 | |||
254 | } | 261 | } |
255 | void OpieMail::clearSelection() | 262 | void OpieMail::clearSelection() |
256 | { | 263 | { |
257 | mailView->clearSelection(); | 264 | mailView->clearSelection(); |
258 | 265 | ||
259 | } | 266 | } |
260 | 267 | ||
261 | void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) | 268 | void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) |
262 | { | 269 | { |
263 | if (!mailView->currentItem()) return; | 270 | if (!mailView->currentItem()) return; |
264 | MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); | 271 | MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); |
265 | /* just the RIGHT button - or hold on pda */ | 272 | /* just the RIGHT button - or hold on pda */ |
266 | if (button!=2) {return;} | 273 | if (button!=2) {return;} |
267 | if (!item) return; | 274 | if (!item) return; |
268 | QPopupMenu *m = new QPopupMenu(0); | 275 | QPopupMenu *m = new QPopupMenu(0); |
269 | if (m) | 276 | if (m) |
270 | { | 277 | { |
271 | if (mailtype==MAILLIB::A_NNTP) { | 278 | if (mailtype==MAILLIB::A_NNTP) { |
272 | m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); | 279 | m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); |
273 | // m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); | 280 | // m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); |
274 | } else { | 281 | } else { |
275 | if (folderView->currentisDraft()) { | 282 | if (folderView->currentisDraft()) { |
276 | m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); | 283 | m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); |
277 | } | 284 | } |
278 | m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); | 285 | m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); |
279 | m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); | 286 | m->insertItem(tr("Move/Copy this mail"),this,SLOT(slotMoveCopyMail())); |
280 | m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); | 287 | m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); |
281 | m->insertSeparator(); | 288 | m->insertSeparator(); |
282 | m->insertItem(tr("Copy/Move all selected mail"),this,SLOT(slotMoveCopyAllMail())); | 289 | m->insertItem(tr("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail())); |
283 | m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); | 290 | m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); |
284 | m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); | 291 | m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); |
285 | } | 292 | } |
286 | m->setFocus(); | 293 | m->setFocus(); |
287 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | 294 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); |
288 | delete m; | 295 | delete m; |
289 | } | 296 | } |
290 | } | 297 | } |
291 | 298 | ||
292 | void OpieMail::slotShowFolders( bool show ) | 299 | void OpieMail::slotShowFolders( bool show ) |
293 | { | 300 | { |
294 | if ( show && folderView->isHidden() ) | 301 | if ( show && folderView->isHidden() ) |
295 | { | 302 | { |
296 | folderView->show(); | 303 | folderView->show(); |
297 | } | 304 | } |
298 | else if ( !show && !folderView->isHidden() ) | 305 | else if ( !show && !folderView->isHidden() ) |
299 | { | 306 | { |
300 | folderView->hide(); | 307 | folderView->hide(); |
301 | } | 308 | } |
302 | } | 309 | } |
303 | 310 | ||
304 | void OpieMail::refreshMailView(const QValueList<RecMailP>&list) | 311 | void OpieMail::refreshMailView(const QValueList<RecMailP>&list) |
305 | { | 312 | { |
306 | MailListViewItem*item = 0; | 313 | MailListViewItem*item = 0; |
307 | mailView->clear(); | 314 | mailView->clear(); |
308 | 315 | ||
309 | QValueList<RecMailP>::ConstIterator it; | 316 | QValueList<RecMailP>::ConstIterator it; |
310 | for (it = list.begin(); it != list.end();++it) | 317 | for (it = list.begin(); it != list.end();++it) |
311 | { | 318 | { |
312 | item = new MailListViewItem(mailView,item); | 319 | item = new MailListViewItem(mailView,item); |
313 | item->storeData((*it)); | 320 | item->storeData((*it)); |
314 | item->showEntry(); | 321 | item->showEntry(); |
@@ -321,88 +328,94 @@ void OpieMail::mailLeftClicked( QListViewItem *item ) | |||
321 | /* just LEFT button - or tap with stylus on pda */ | 328 | /* just LEFT button - or tap with stylus on pda */ |
322 | //if (button!=1) return; | 329 | //if (button!=1) return; |
323 | if (!item) return; | 330 | if (!item) return; |
324 | if (folderView->currentisDraft()) { | 331 | if (folderView->currentisDraft()) { |
325 | reEditMail(); | 332 | reEditMail(); |
326 | } else { | 333 | } else { |
327 | displayMail(); | 334 | displayMail(); |
328 | } | 335 | } |
329 | } | 336 | } |
330 | 337 | ||
331 | void OpieMail::slotMoveCopyMail() | 338 | void OpieMail::slotMoveCopyMail() |
332 | { | 339 | { |
333 | if (!mailView->currentItem()) return; | 340 | if (!mailView->currentItem()) return; |
334 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 341 | RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); |
335 | AbstractMail*targetMail = 0; | 342 | AbstractMail*targetMail = 0; |
336 | QString targetFolder = ""; | 343 | QString targetFolder = ""; |
337 | Selectstore sels; | 344 | Selectstore sels; |
338 | folderView->setupFolderselect(&sels); | 345 | folderView->setupFolderselect(&sels); |
339 | if (!sels.exec()) return; | 346 | if (!sels.exec()) return; |
340 | targetMail = sels.currentMail(); | 347 | targetMail = sels.currentMail(); |
341 | targetFolder = sels.currentFolder(); | 348 | targetFolder = sels.currentFolder(); |
342 | if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || | 349 | if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || |
343 | targetFolder.isEmpty()) | 350 | targetFolder.isEmpty()) |
344 | { | 351 | { |
345 | return; | 352 | return; |
346 | } | 353 | } |
347 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) | 354 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) |
348 | { | 355 | { |
349 | QMessageBox::critical(0,tr("Error creating new Folder"), | 356 | QMessageBox::critical(0,tr("Error creating new Folder"), |
350 | tr("<center>Error while creating<br>new folder - breaking.</center>")); | 357 | tr("<center>Error while creating<br>new folder - breaking.</center>")); |
351 | return; | 358 | return; |
352 | } | 359 | } |
360 | sels.hide(); | ||
361 | qApp->processEvents(); | ||
362 | // qDebug("hiding sels "); | ||
353 | mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); | 363 | mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); |
354 | folderView->refreshCurrent(); | 364 | folderView->refreshCurrent(); |
355 | } | 365 | } |
356 | 366 | ||
357 | void OpieMail::slotMoveCopyAllMail() | 367 | void OpieMail::slotMoveCopyAllMail() |
358 | { | 368 | { |
359 | 369 | ||
360 | if (!mailView->currentItem()) return; | 370 | if (!mailView->currentItem()) return; |
361 | QValueList<RecMailP> t; | 371 | QValueList<RecMailP> t; |
362 | if ( QMessageBox::warning(this, tr("Copy/Move all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) | 372 | // if ( QMessageBox::warning(this, tr("Move/Copy all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) |
363 | { | 373 | { |
364 | MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); | 374 | MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); |
365 | while ( item ) { | 375 | while ( item ) { |
366 | if ( item->isSelected() ) { | 376 | if ( item->isSelected() ) { |
367 | t.append( item->data() ); | 377 | t.append( item->data() ); |
368 | } | 378 | } |
369 | item = (MailListViewItem*)item->nextSibling(); | 379 | item = (MailListViewItem*)item->nextSibling(); |
370 | } | 380 | } |
371 | } | 381 | } |
372 | else | 382 | // else |
373 | return; | 383 | // return; |
374 | if ( t.count() == 0 ) | 384 | if ( t.count() == 0 ) |
375 | return; | 385 | return; |
376 | RecMailP mail = t.first(); | 386 | RecMailP mail = t.first(); |
377 | AbstractMail*targetMail = 0; | 387 | AbstractMail*targetMail = 0; |
378 | QString targetFolder = ""; | 388 | QString targetFolder = ""; |
379 | Selectstore sels; | 389 | Selectstore sels; |
380 | folderView->setupFolderselect(&sels); | 390 | folderView->setupFolderselect(&sels); |
381 | if (!sels.exec()) return; | 391 | if (!sels.exec()) return; |
382 | targetMail = sels.currentMail(); | 392 | targetMail = sels.currentMail(); |
383 | targetFolder = sels.currentFolder(); | 393 | targetFolder = sels.currentFolder(); |
384 | if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || | 394 | if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || |
385 | targetFolder.isEmpty()) | 395 | targetFolder.isEmpty()) |
386 | { | 396 | { |
387 | return; | 397 | return; |
388 | } | 398 | } |
389 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) | 399 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) |
390 | { | 400 | { |
391 | QMessageBox::critical(0,tr("Error creating new Folder"), | 401 | QMessageBox::critical(0,tr("Error creating new Folder"), |
392 | tr("<center>Error while creating<br>new folder - breaking.</center>")); | 402 | tr("<center>Error while creating<br>new folder - breaking.</center>")); |
393 | return; | 403 | return; |
394 | } | 404 | } |
405 | sels.hide(); | ||
406 | qApp->processEvents(); | ||
407 | //qDebug("hiding sels "); | ||
395 | mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails()); | 408 | mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails()); |
396 | folderView->refreshCurrent(); | 409 | folderView->refreshCurrent(); |
397 | } | 410 | } |
398 | 411 | ||
399 | void OpieMail::reEditMail() | 412 | void OpieMail::reEditMail() |
400 | { | 413 | { |
401 | if (!mailView->currentItem()) return; | 414 | if (!mailView->currentItem()) return; |
402 | 415 | ||
403 | ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); | 416 | ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); |
404 | compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); | 417 | compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); |
405 | compose.slotAdjustColumns(); | 418 | compose.slotAdjustColumns(); |
406 | compose.showMaximized(); | 419 | compose.showMaximized(); |
407 | compose.exec(); | 420 | compose.exec(); |
408 | } | 421 | } |