Digital Sovereignty for everyone

Inbound mail ingestion

Ingestion copies each site’s IMAP mailboxes into LH Messaging (LH_Email_Ingest, includes/class-lh-email-ingest.php). It runs only in the background, on the lh_email_ingest Action Scheduler action, or through the run-ingest ability, never inside a page request. A run works for about 20 seconds (lh_email_return_ingest_time_budget): new mail since the folder’s cursor first, then any failed messages due for a retry, then the newest-first backfill. While work remains it queues the next run a minute later; otherwise the hourly wakeup starts the next one.

A database lock (GET_LOCK, released when the run ends or its connection closes) keeps two runs from overlapping. A run that finds the lock held logs “Another ingest run is in progress” and tries again a minute later.

Runs the host ends

The host can end a request without PHP running any shutdown code. Action Scheduler then leaves the action in progress for an hour before marking it failed. Since 3.20.3 the hourly wakeup counts only a waiting run as a duplicate, not one still shown as in progress, so a killed run costs at most an hour of ingest instead of two. Each run also records the step it is on (connecting, the new-mail, retry or backfill UIDs, or the bodies being fetched and their size) in the lh_email_ingest_progress option, deleted when the run ends. A record still there when the next run takes the lock belongs to a run that never finished, and that run logs a warning: “Ingest: the previous run on site N never finished: started …, last step at …: …”.

Messages that fail

A batch that fails as a whole is retried one message at a time, so a single unreadable message never stalls the cursor. A message that still cannot be read, or is fetched but not stored, is logged (“UID … skipped” or “UID … not stored”, with LH Messaging’s database reason since its 0.4.2), counted as failed, and, since 3.21.0, recorded in the lh_email_ingest_failures table (schema 2.11.0) with its connection, folder, UIDVALIDITY, error, attempt count and times. The cursor moves on, but the message is not lost: later runs retry it.

  • Each run retries up to 5 due messages per folder (lh_email_return_ingest_retry_batch_size), after new mail and before the backfill, within the time budget.
  • The wait before the next attempt is 15 minutes, doubling each time, at most a day (lh_email_return_ingest_retry_delay). Runs are hourly when there is nothing else to do, so short waits round up to the next run.
  • A message that stores, turns out to be stored already, or is no longer in the folder is dropped from the list. Since 3.21.1 that includes a message whose retry fails with an IMAP error (such as “Empty response”): the run checks with a UID SEARCH whether it is still in the folder and drops it if the server says it is gone, as happens to a deleted message or a Gmail draft re-saved under a new UID. If that check itself fails, the message keeps its retry schedule. A UIDVALIDITY change drops the whole folder’s list, since the folder is read again from the start.
  • After 8 attempts (lh_email_return_ingest_max_store_attempts, about 32 hours) the message is given up on: it is logged as a warning and stays listed, with its last error, for a person to look at.

run-ingest shows all of this. A run reports failed, retried and recovered counts per folder, and every folder report carries failures (how many are retrying and how many were given up). status also lists the failures themselves, given-up ones first. action: retry with no UIDs gives every given-up message a fresh set of attempts (optionally for one slug or folder). With slug, folder and uids it adds those UIDs to the list, for mail lost before 3.21.0. Either way the next run is queued a minute later.

If you like this plugin please consider making a donation to further development

Install LHero.org

lhero.org

Open it straight from your home screen, full screen and quicker to load.

  1. Tap the Share button . If you cannot see it, tap ••• first.
  2. Scroll down and tap Add to Home Screen.
  3. Tap Add.
  1. Tap the browser menu â‹®.
  2. Tap Install app or Add to Home screen.
  1. In the menu bar, choose File, then Add to Dock.

Use your browser's menu to install this site or add it to your home screen.