*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
#ifdef HAVE_CONFIG_H
return TRUE;
}
+static void imap_logger_noop(int direction, const char * str, size_t size)
+{
+ /* inhibit logging */
+}
+
static void imap_logger_cmd(int direction, const char * str, size_t size)
{
gchar *buf;
gchar **lines;
int i = 0;
- if (size > 8192) {
+ if (size > 128 && !direction) {
log_print(LOG_PROTOCOL, "IMAP4%c [FETCH data - %zd bytes]\n", direction?'>':'<', size);
return;
}
else {
gchar tmp[64];
strncpy2(tmp, lines[i], 63);
- log_print(LOG_PROTOCOL, "IMAP4%c %s[... - %zd bytes more]\n", direction?'>':'<', tmp,
+ log_print(LOG_PROTOCOL, "IMAP4%c %s[... - %d bytes more]\n", direction?'>':'<', tmp,
llen-64);
}
i++;
g_warning("no cert presented.\n");
return 0;
}
- cert = d2i_X509(NULL, &certificate, len);
+ cert = d2i_X509(NULL, (const unsigned char **)&certificate, len);
if (cert == NULL) {
g_warning("can't get cert\n");
return 0;
debug_print("imap noop run - end %i\n", r);
}
-int imap_threaded_noop(Folder * folder, unsigned int * p_exists)
+int imap_threaded_noop(Folder * folder, unsigned int * p_exists,
+ unsigned int *p_recent,
+ unsigned int *p_expunge,
+ unsigned int *p_unseen,
+ unsigned int *p_uidnext,
+ unsigned int *p_uidval)
{
struct noop_param param;
struct noop_result result;
threaded_run(folder, ¶m, &result, noop_run);
- if (imap && imap->imap_selection_info != NULL) {
+ if (result.error == 0 && imap && imap->imap_selection_info != NULL) {
* p_exists = imap->imap_selection_info->sel_exists;
- }
- else {
+ * p_recent = imap->imap_selection_info->sel_recent;
+ * p_unseen = imap->imap_selection_info->sel_unseen;
+ * p_uidnext = imap->imap_selection_info->sel_uidnext;
+ * p_uidval = imap->imap_selection_info->sel_uidvalidity;
+ } else {
* p_exists = 0;
- }
-
- debug_print("imap noop - end\n");
+ * p_recent = 0;
+ * p_unseen = 0;
+ * p_uidnext = 0;
+ * p_uidval = 0;
+ }
+ if (result.error == 0 && imap && imap->imap_response_info != NULL &&
+ imap->imap_response_info->rsp_expunged != NULL) {
+ * p_expunge = clist_count(imap->imap_response_info->rsp_expunged);
+ } else {
+ * p_expunge = 0;
+ }
+ debug_print("imap noop - end [EXISTS %d RECENT %d EXPUNGE %d UNSEEN %d UIDNEXT %d UIDVAL %d]\n",
+ *p_exists, *p_recent, *p_expunge, *p_unseen,
+ *p_uidnext, *p_uidval);
return result.error;
}
return result.error;
}
+static void close_run(struct etpan_thread_op * op)
+{
+ struct select_param * param;
+ struct select_result * result;
+ int r;
+
+ param = op->param;
+ result = op->result;
+
+ CHECK_IMAP();
+ r = mailimap_close(param->imap);
+
+ result->error = r;
+ debug_print("imap close run - end %i\n", r);
+}
+
+int imap_threaded_close(Folder * folder)
+{
+ struct select_param param;
+ struct select_result result;
+ mailimap * imap;
+
+ debug_print("imap close - begin\n");
+
+ imap = get_imap(folder);
+ param.imap = imap;
+
+ threaded_run(folder, ¶m, &result, close_run);
+
+ if (result.error != MAILIMAP_NO_ERROR)
+ return result.error;
+
+ debug_print("imap close - end\n");
+
+ return result.error;
+}
struct examine_param {
mailimap * imap;
goto free_fetch_type;
}
+ mailstream_logger = imap_logger_fetch;
+
r = mailimap_uid_fetch(imap, set,
fetch_type, &fetch_result);
+ mailstream_logger = imap_logger_cmd;
mailimap_fetch_type_free(fetch_type);
mailimap_set_free(set);
CHECK_IMAP();
fetch_result = NULL;
- mailstream_logger = NULL;
+ mailstream_logger = imap_logger_noop;
log_print(LOG_PROTOCOL, "IMAP4- [fetching UIDs...]\n");
r = imap_get_messages_list(param->imap, param->first_index,
goto free_fetch_type;
}
+ mailstream_logger = imap_logger_fetch;
+
r = mailimap_uid_fetch(imap, set,
fetch_type, &fetch_result);
+ mailstream_logger = imap_logger_cmd;
mailimap_fetch_type_free(fetch_type);
mailimap_set_free(set);
param.imap = imap;
param.first_index = first_index;
- mailstream_logger = NULL;
+ mailstream_logger = imap_logger_noop;
log_print(LOG_PROTOCOL, "IMAP4- [fetching flags...]\n");
threaded_run(folder, ¶m, &result, fetch_uid_flags_run);
goto free_fetch_att;
}
+ mailstream_logger = imap_logger_fetch;
+
r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
+ mailstream_logger = imap_logger_cmd;
mailimap_fetch_type_free(fetch_type);
mailimap_set_free(set);
}
r = fwrite(content, 1, content_size, f);
- if (r == 0) {
+ if (r < content_size) {
goto fclose;
}
r = fclose(f);
if (r == EOF) {
- g_unlink(param->filename);
- goto close;
+ goto unlink;
}
goto free;
else
r = imap_add_header_fetch_att(fetch_type);
+ mailstream_logger = imap_logger_fetch;
+
r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
+ mailstream_logger = imap_logger_cmd;
switch (r) {
case MAILIMAP_NO_ERROR:
break;