X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=imap%2Fimap.c;h=a9552ceaca683bda6508eb8045c4bcee1547ff2f;hp=d4b622c336065bb134f48e7e998926f35ef7846a;hb=643be053e447a35cccc37550ac0087bb5bb5c5ad;hpb=6833ce8bdca2d64e14485118f2a4417b7e1cb1b1 diff --git a/imap/imap.c b/imap/imap.c index d4b622c..a9552ce 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -20,6 +20,10 @@ /* Support for IMAP4rev1, with the occasional nod to IMAP 4. */ +#if HAVE_CONFIG_H +# include "config.h" +#endif + #include "mutt.h" #include "mutt_curses.h" #include "mx.h" @@ -29,7 +33,7 @@ #include "browser.h" #include "message.h" #include "imap_private.h" -#ifdef USE_SSL +#if defined(USE_SSL) || defined(USE_GNUTLS) # include "mutt_ssl.h" #endif @@ -104,20 +108,37 @@ int imap_create_mailbox (IMAP_DATA* idata, char* mailbox) return 0; } +int imap_rename_mailbox (IMAP_DATA* idata, IMAP_MBOX* mx, const char* newname) +{ + char oldmbox[LONG_STRING]; + char newmbox[LONG_STRING]; + char buf[LONG_STRING]; + + imap_munge_mbox_name (oldmbox, sizeof (oldmbox), mx->mbox); + imap_munge_mbox_name (newmbox, sizeof (newmbox), newname); + + snprintf (buf, sizeof (buf), "RENAME %s %s", oldmbox, newmbox); + + if (imap_exec (idata, buf, 0) != 0) + return -1; + + return 0; +} + int imap_delete_mailbox (CONTEXT* ctx, IMAP_MBOX mx) { char buf[LONG_STRING], mbox[LONG_STRING]; IMAP_DATA *idata; if (!ctx || !ctx->data) { - if (!(idata = imap_conn_find (&mx.account, - option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW : 0))) - { - FREE (&mx.mbox); - return -1; - } + if (!(idata = imap_conn_find (&mx.account, + option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW : 0))) + { + FREE (&mx.mbox); + return -1; + } } else { - idata = ctx->data; + idata = ctx->data; } imap_munge_mbox_name (mbox, sizeof (mbox), mx.mbox); @@ -408,7 +429,7 @@ int imap_open_connection (IMAP_DATA* idata) /* TODO: Parse new tagged CAPABILITY data (* OK [CAPABILITY...]) */ if (imap_check_capabilities (idata)) goto bail; -#if defined(USE_SSL) && !defined(USE_NSS) +#if defined(USE_SSL) || defined(USE_GNUTLS) /* Attempt STARTTLS if available and desired. */ if (mutt_bit_isset (idata->capabilities, STARTTLS) && !idata->conn->ssf) { @@ -422,11 +443,15 @@ int imap_open_connection (IMAP_DATA* idata) goto bail; if (rc != -2) { +#ifdef USE_SSL if (mutt_ssl_starttls (idata->conn)) +#elif USE_GNUTLS + if (mutt_gnutls_starttls (idata->conn)) +#endif { mutt_error (_("Could not negotiate TLS connection")); mutt_sleep (1); - goto bail; + goto err_close_conn; } else { @@ -456,6 +481,7 @@ int imap_open_connection (IMAP_DATA* idata) err_close_conn: mutt_socket_close (idata->conn); + idata->state = IMAP_DISCONNECTED; bail: FREE (&idata->capstr); return -1; @@ -602,6 +628,17 @@ int imap_open_mailbox (CONTEXT* ctx) if ((pc = imap_get_flags (&(idata->flags), pc)) == NULL) goto fail; } +#ifdef USE_HCACHE + /* save UIDVALIDITY for the header cache */ + else if (ascii_strncasecmp("OK [UIDVALIDITY", pc, 14) == 0) + { + dprint(2, (debugfile, "Getting mailbox UIDVALIDITY\n")); + pc += 3; + pc = imap_next_word(pc); + + sscanf(pc, "%u", &(idata->uid_validity)); + } +#endif else { pc = imap_next_word (pc); @@ -778,12 +815,14 @@ void imap_logout (IMAP_DATA* idata) imap_cmd_start (idata, "LOGOUT"); while (imap_cmd_step (idata) == IMAP_CMD_CONTINUE) ; + FREE(& idata->cmd.buf); + FREE(& idata); } +/* int imap_close_connection (CONTEXT *ctx) { dprint (1, (debugfile, "imap_close_connection(): closing connection\n")); - /* if the server didn't shut down on us, close the connection gracefully */ if (CTX_DATA->status != IMAP_BYE) { mutt_message _("Closing connection to IMAP server..."); @@ -795,6 +834,7 @@ int imap_close_connection (CONTEXT *ctx) CTX_DATA->conn->data = NULL; return 0; } +*/ /* imap_set_flag: append str to flags if we currently have permission * according to aclbit */ @@ -803,7 +843,7 @@ static void imap_set_flag (IMAP_DATA* idata, int aclbit, int flag, { if (mutt_bit_isset (idata->rights, aclbit)) if (flag) - strncat (flags, str, flsize); + safe_strcat (flags, flsize, str); } /* imap_make_msg_set: make an IMAP4rev1 UID message set out of a set of @@ -981,9 +1021,11 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint) mutt_buffer_addstr (&cmd, "UID STORE "); mutt_buffer_addstr (&cmd, uid); - /* if attachments have been deleted we delete the message and reupload - * it. This works better if we're expunging, of course. */ - if (ctx->hdrs[n]->attach_del) + /* if the message has been rethreaded or attachments have been deleted + * we delete the message and reupload it. + * This works better if we're expunging, of course. */ + if (ctx->hdrs[n]->refs_changed || ctx->hdrs[n]->irt_changed || + ctx->hdrs[n]->attach_del) { dprint (3, (debugfile, "imap_sync_mailbox: Attachments to be deleted, falling back to _mutt_save_message\n")); if (!appendctx) @@ -1467,3 +1509,20 @@ int imap_complete(char* dest, size_t dlen, char* path) { FREE (&mx.mbox); return -1; } + +/* reconnect if connection was lost */ +int imap_reconnect(CONTEXT* ctx) { + IMAP_DATA* imap_data = (IMAP_DATA *)ctx->data; + + if (imap_data) { + if (imap_data->status == IMAP_CONNECTED) + return -1; + } + + if (query_quadoption(OPT_IMAPRECONNECT,_("Connection lost. Reconnect to IMAP server?")) != M_YES) + return -1; + + mx_open_mailbox(ctx->path,0,ctx); + return 0; +} +