gchar * mail_tool_do_movemail (CamelStore *store, GError **error) { #ifndef G_OS_WIN32 CamelService *service; CamelProvider *provider; CamelSettings *settings; gchar *src_path; gchar *dest_path; struct stat sb; gboolean success; g_return_val_if_fail (CAMEL_IS_STORE (store), NULL); service = CAMEL_SERVICE (store); provider = camel_service_get_provider (service); g_return_val_if_fail (provider != NULL, NULL); if (g_strcmp0 (provider->protocol, "mbox") != 0) { /* This is really only an internal error anyway */ g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_URL_INVALID, _("Trying to movemail a non-mbox source '%s'"), camel_service_get_uid (CAMEL_SERVICE (store))); return NULL; } settings = camel_service_ref_settings (service); src_path = camel_local_settings_dup_path ( CAMEL_LOCAL_SETTINGS (settings)); g_object_unref (settings); /* Set up our destination. */ dest_path = mail_tool_get_local_movemail_path (store, error); if (dest_path == NULL) return NULL; /* Movemail from source to dest_path */ success = camel_movemail (src_path, dest_path, error) != -1; g_free (src_path); if (g_stat (dest_path, &sb) < 0 || sb.st_size == 0) { g_unlink (dest_path); /* Clean up the movemail.foo file. */ g_free (dest_path); return NULL; } if (!success) { g_free (dest_path); return NULL; } return dest_path; #else /* Unclear yet whether camel-movemail etc makes any sense on * Win32, at least it is not ported yet. */ g_warning ("%s: Not implemented", __FUNCTION__); return NULL; #endif }
static gchar * format_service_name (CamelService *service) { CamelProvider *provider; CamelSettings *settings; gchar *service_name = NULL; const gchar *display_name; gchar *pretty_url = NULL; gchar *host = NULL; gchar *path = NULL; gchar *user = NULL; gchar *cp; gboolean have_host = FALSE; gboolean have_path = FALSE; gboolean have_user = FALSE; provider = camel_service_get_provider (service); display_name = camel_service_get_display_name (service); settings = camel_service_ref_settings (service); if (CAMEL_IS_NETWORK_SETTINGS (settings)) { host = camel_network_settings_dup_host ( CAMEL_NETWORK_SETTINGS (settings)); have_host = (host != NULL) && (*host != '\0'); user = camel_network_settings_dup_user ( CAMEL_NETWORK_SETTINGS (settings)); have_user = (user != NULL) && (*user != '\0'); } if (CAMEL_IS_LOCAL_SETTINGS (settings)) { path = camel_local_settings_dup_path ( CAMEL_LOCAL_SETTINGS (settings)); have_path = (path != NULL) && (*path != '\0'); } g_object_unref (settings); /* Shorten user names with '@', since multiple '@' in a * 'user@host' label look weird. This is just supposed * to be a hint anyway so it doesn't matter if it's not * strictly correct. */ if (have_user && (cp = strchr (user, '@')) != NULL) *cp = '\0'; g_return_val_if_fail (provider != NULL, NULL); /* This should never happen, but if the service has no * display name, fall back to the generic service name. */ if (display_name == NULL || *display_name == '\0') { service_name = camel_service_get_name (service, TRUE); display_name = service_name; } if (have_host && have_user) { pretty_url = g_markup_printf_escaped ( "<b>%s</b> <small>(%s@%s)</small>", display_name, user, host); } else if (have_host) { pretty_url = g_markup_printf_escaped ( "<b>%s</b> <small>(%s)</small>", display_name, host); } else if (have_path) { pretty_url = g_markup_printf_escaped ( "<b>%s</b> <small>(%s)</small>", display_name, path); } else { pretty_url = g_markup_printf_escaped ( "<b>%s</b>", display_name); } g_free (service_name); g_free (host); g_free (path); g_free (user); return pretty_url; }