[Evolution-users] Mails :: Automatic expunge of local Trash folder

Milan Crha mcrha at redhat.com
Thu Jul 31 16:15:10 UTC 2025


On Thu, 2025-07-31 at 14:52 +0200, Matthias Kuntze wrote:
> Does this module exist somewhere or do I have to code it?

	Hi,
there is an example module, which covers several parts of the
Evolution, but it's only an example, it does not do anything specific
apart of showing how to get to the UI elements and some bottom parts:
https://gitlab.gnome.org/GNOME/evolution/-/wikis/Extensions#example-module

You'd need only the `m-shell-view-extension` part, the others can be
skipped.

What I had on my mind was roughly this:
a) open the "On This Computer/.../Archive" folder shortly after start,
   like instead of calling `m_mail_ui_init()` you'd do:
      CamelSession *session = NULL;
      CamelService *service;
      g_object_get (e_shell_view_get_shell_backend (shell_view), "session", &session);
      service = camel_session_ref_service (session, E_MAIL_SESSION_LOCAL_UID); /* aka "local" */
      if (service) {
          CamelFolder *archive_folder;
          GError *local_error = NULL;
          /* this will block the GUI thread, possibly freezing the app, maybe use camel_store_get_folder() instead */
          archive_folder = camel_store_get_folder_sync (CAMEL_STORE (service), "Archive", 0, NULL, &local_error);
          if (archive_folder) {
              /* following step */
              /* remember the 'folder', and unref it on quit/dispose of the extension */
          } else {
              g_warning ("Failed to open 'Archive' folder: %s", local_error ? local_error->message : "Unknown error");
          }
          g_clear_error (&local_error);
      } else {
          g_warning ("cannot find 'On This Computer' service);
      }
      g_clear_object (&service);
      g_clear_object (&session);
b) connect to `notify::deleted-count` signal on the folder's
   camel_folder_get_folder_summary (archive_folder);
c) when the callback is called and
      camel_folder_summary_get_deleted_count() > 0
   then schedule some timeout callback (to fire the expunge), say
   after 10 seconds (g_timeout_add_seconds (10, ....));
   the timeout is needed in case of consecutive deleted, to not expunge
   after every single message deletion
d) when the timeout is called, schedule a session job, which will
   run in a dedicated thread and not block the UI:
   camel_session_submit_job (session, "Expunging local Archive folder",....)
   though getting to the `session` is a bit fun thing:
      session = camel_service_ref_session (CAMEL_SERVICE (
         camel_folder_get_parent_store (archive_folder)));
   and as it's a "ref" function, then also g_object_unref(session) when
   done with it (which is after the camel_session_submit_job() call);
   The submitted job will also indicate it's doing that in
   the status bar and will let you cancel it - not that I expect
   to take the expunge long, when it's all local
e) finally, in the job/thread function you call:
   camel_folder_expunge_sync (archive_folder,...) or rather
   camel_folder_synchronize_sync (archive_folder, TRUE, ...)
   to also save the changes.

It may look scary, but it's not a long code, it's only tricky when one
is not familiar with the libcamel API and does not know how to get to
it in the Evolution.

As the example module adds actions on various places, an action to
schedule the listener for any local folder (only manually, which is not
that great when one looks for the automation) could be done too. With a
combination with saving into the GSettings... nah, it would be too much.

	Bye,
	Milan

P.S.: I only outlined what I think can work. I may come into other ways
when implementing it and testing it in action. Maybe if I'll find some
time tomorrow, I can provide you the code, which you'll just tweak to
your liking.



More information about the evolution-users mailing list