static CamelFolder * diary_decode_folder (CamelDiscoDiary *diary) { CamelFolder *folder; char *name; if (camel_file_util_decode_string (diary->file, &name) == -1) return NULL; folder = g_hash_table_lookup (diary->folders, name); if (!folder) { CamelException ex; char *msg; camel_exception_init (&ex); folder = camel_store_get_folder (CAMEL_STORE (diary->store), name, 0, &ex); if (folder) g_hash_table_insert (diary->folders, name, folder); else { msg = g_strdup_printf (_("Could not open `%s':\n%s\nChanges made to this folder will not be resynchronized."), name, camel_exception_get_description (&ex)); camel_exception_clear (&ex); camel_session_alert_user (camel_service_get_session (CAMEL_SERVICE (diary->store)), CAMEL_SESSION_ALERT_WARNING, msg, FALSE); g_free (msg); g_free (name); } } else g_free (name); return folder; }
/** * camel_session_alert_user_with_id: * * Like camel_session_alert_user() but constructs and uses a CamelException * with the error ID and the specified message. */ gboolean camel_session_alert_user_with_id (CamelSession *session, CamelSessionAlertType type, ExceptionId id, const gchar* message, gboolean cancel, CamelService *service) { CamelException ex = CAMEL_EXCEPTION_INITIALISER; gboolean result; g_return_val_if_fail (message, FALSE); camel_exception_set (&ex, id, message); result = camel_session_alert_user (session, type, &ex, cancel, service); camel_exception_clear (&ex); return result; }
void camel_disco_diary_log (CamelDiscoDiary *diary, CamelDiscoDiaryAction action, ...) { va_list ap; int status; d(printf("diary log: %s\n", diary->file?"ok":"no file!")); /* You may already be a loser. */ if (!diary && !diary->file) return; status = camel_file_util_encode_uint32 (diary->file, action); if (status == -1) goto lose; va_start (ap, action); switch (action) { case CAMEL_DISCO_DIARY_FOLDER_EXPUNGE: { CamelFolder *folder = va_arg (ap, CamelFolder *); GPtrArray *uids = va_arg (ap, GPtrArray *); d(printf(" folder expunge '%s'\n", folder->full_name)); status = camel_file_util_encode_string (diary->file, folder->full_name); if (status != -1) status = diary_encode_uids (diary, uids); break; } case CAMEL_DISCO_DIARY_FOLDER_APPEND: { CamelFolder *folder = va_arg (ap, CamelFolder *); char *uid = va_arg (ap, char *); d(printf(" folder append '%s'\n", folder->full_name)); status = camel_file_util_encode_string (diary->file, folder->full_name); if (status != -1) status = camel_file_util_encode_string (diary->file, uid); break; } case CAMEL_DISCO_DIARY_FOLDER_TRANSFER: { CamelFolder *source = va_arg (ap, CamelFolder *); CamelFolder *destination = va_arg (ap, CamelFolder *); GPtrArray *uids = va_arg (ap, GPtrArray *); gboolean delete_originals = va_arg (ap, gboolean); d(printf(" folder transfer '%s' to '%s'\n", source->full_name, destination->full_name)); status = camel_file_util_encode_string (diary->file, source->full_name); if (status == -1) break; status = camel_file_util_encode_string (diary->file, destination->full_name); if (status == -1) break; status = diary_encode_uids (diary, uids); if (status == -1) break; status = camel_file_util_encode_uint32 (diary->file, delete_originals); break; } default: g_assert_not_reached (); break; } va_end (ap); lose: if (status == -1) { char *msg; msg = g_strdup_printf (_("Could not write log entry: %s\n" "Further operations on this server " "will not be replayed when you\n" "reconnect to the network."), g_strerror (errno)); camel_session_alert_user (camel_service_get_session (CAMEL_SERVICE (diary->store)), CAMEL_SESSION_ALERT_ERROR, msg, FALSE); g_free (msg); fclose (diary->file); diary->file = NULL; } }
/** * camel_imap_command_response: * @store: the IMAP store * @response: a pointer to pass back the response data in * @ex: a CamelException * * This reads a single tagged, untagged, or continuation response from * @store into *@response. The caller must free the string when it is * done with it. * * Return value: One of %CAMEL_IMAP_RESPONSE_CONTINUATION, * %CAMEL_IMAP_RESPONSE_UNTAGGED, %CAMEL_IMAP_RESPONSE_TAGGED, or * %CAMEL_IMAP_RESPONSE_ERROR. If either of the last two, @store's * command lock will be unlocked. **/ CamelImapResponseType camel_imap_command_response (CamelImapStore *store, char **response, CamelException *ex) { CamelImapResponseType type; char *respbuf; if (camel_imap_store_readline (store, &respbuf, ex) < 0) { CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); return CAMEL_IMAP_RESPONSE_ERROR; } switch (*respbuf) { case '*': if (!g_ascii_strncasecmp (respbuf, "* BYE", 5)) { /* Connection was lost, no more data to fetch */ camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL); camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, _("Server unexpectedly disconnected: %s"), _("Unknown error")); /* g_strerror (104)); FIXME after 1.0 is released */ store->connected = FALSE; g_free (respbuf); respbuf = NULL; type = CAMEL_IMAP_RESPONSE_ERROR; break; } /* Read the rest of the response. */ type = CAMEL_IMAP_RESPONSE_UNTAGGED; respbuf = imap_read_untagged (store, respbuf, ex); if (!respbuf) type = CAMEL_IMAP_RESPONSE_ERROR; else if (!g_ascii_strncasecmp (respbuf, "* OK [ALERT]", 12) || !g_ascii_strncasecmp (respbuf, "* NO [ALERT]", 12) || !g_ascii_strncasecmp (respbuf, "* BAD [ALERT]", 13)) { char *msg; /* for imap ALERT codes, account user@host */ /* we might get a ']' from a BAD response since we +12, but who cares? */ msg = g_strdup_printf(_("Alert from IMAP server %s@%s:\n%s"), ((CamelService *)store)->url->user, ((CamelService *)store)->url->host, respbuf+12); camel_session_alert_user(((CamelService *)store)->session, CAMEL_SESSION_ALERT_WARNING, msg, FALSE); g_free(msg); } break; case '+': type = CAMEL_IMAP_RESPONSE_CONTINUATION; break; default: type = CAMEL_IMAP_RESPONSE_TAGGED; break; } *response = respbuf; if (type == CAMEL_IMAP_RESPONSE_ERROR || type == CAMEL_IMAP_RESPONSE_TAGGED) CAMEL_SERVICE_REC_UNLOCK (store, connect_lock); return type; }
static gboolean groupwise_connect_sync (CamelService *service, GCancellable *cancellable, GError **error) { CamelGroupwiseStore *store = CAMEL_GROUPWISE_STORE (service); CamelGroupwiseStorePrivate *priv = store->priv; CamelGroupwiseStoreNamespace *ns; CamelSession *session = service->session; d("in groupwise store connect\n"); if (service->status == CAMEL_SERVICE_DISCONNECTED) return FALSE; if (!priv) { store->priv = g_new0 (CamelGroupwiseStorePrivate, 1); priv = store->priv; camel_service_construct (service, service->session, service->provider, service->url, error); } camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); if (priv->cnc) { camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); return TRUE; } if (!check_for_connection (service, cancellable, error) || !groupwise_auth_loop (service, cancellable, error)) { camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); camel_service_disconnect_sync (service, TRUE, NULL); return FALSE; } service->status = CAMEL_SERVICE_CONNECTED; camel_offline_store_set_online_sync ( CAMEL_OFFLINE_STORE (store), TRUE, cancellable, NULL); if (!e_gw_connection_get_version (priv->cnc)) { camel_session_alert_user (session, CAMEL_SESSION_ALERT_WARNING, _("Some features may not work correctly with your current server version"), FALSE); } ns = camel_groupwise_store_summary_namespace_new (store->summary, priv->storage_path, '/'); camel_groupwise_store_summary_namespace_set (store->summary, ns); if (camel_store_summary_count ((CamelStoreSummary *)store->summary) == 0) { /*Settting the refresh stamp to the current time*/ store->refresh_stamp = time (NULL); } camel_store_summary_save ((CamelStoreSummary *) store->summary); camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); if (E_IS_GW_CONNECTION (priv->cnc)) { return TRUE; } return FALSE; }