[Bug]: Email Message.DeleteOrphanedMessages deletes retrieved (Email Inbox) messages
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- database
Direzione di ricerca
Leggi src/System Application/App/Email/src/Message/EmailMessageImpl.Codeunit.al e individua DeleteEmailMessageIfOrphaned; confronta i controlli per Outbox e Sent Email con il modo in cui le righe di Email Inbox fanno riferimento ai messaggi. Controlla la documentazione di DeleteOrphanedMessages nella codeunit 8904 e i test esistenti sui messaggi email. Il lavoro è completato quando i messaggi referenziati dalla posta in arrivo vengono conservati durante la pulizia e la documentazione descrive questo comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the issue
Email Message.DeleteOrphanedMessages (codeunit 8904) calls Email Message Impl..DeleteEmailMessageIfOrphaned (codeunit 8905). That procedure treats a message as orphaned when no Email Outbox row and no Sent Email row reference it:
local procedure DeleteEmailMessageIfOrphaned(var EmailMessage: Record "Email Message")
var
EmailOutbox: Record "Email Outbox";
SentEmail: Record "Sent Email";
begin
EmailOutbox.SetRange("Message Id", EmailMessage.Id);
if not EmailOutbox.IsEmpty() then
exit;
SentEmail.SetRange("Message Id", EmailMessage.Id);
if not SentEmail.IsEmpty() then
exit;
EmailMessage.Delete();
end;
Messages retrieved with Email.RetrieveEmails (Email Connector v3, used for example by the Sales Order Agent) are stored as an Email Message referenced only by an Email Inbox row (table 8886). They have no Outbox or Sent Email row, so DeleteOrphanedMessages deletes them, with their attachments, recipients and related records. The Email Inbox row is left pointing to a message that no longer exists.
The rest of codeunit 8905 already treats Email Inbox as an owner of the message:
- OnAfterDeleteEmailInbox deletes the message when its inbox row is deleted.
- OnBeforeModifyEmailMessage refuses to modify a message that has an Email Inbox row.
- The codeunit already has
tabledata "Email Inbox" = rin its Permissions.
The XML doc comment on DeleteOrphanedMessages ("Deletes messages that does not have a reference from either the email outbox nor sent email") matches the code, but it predates email retrieval, so I believe the inbox check was missed rather than intended.
I found this while building a cleanup for a customer tenant where custom code had left about 163,000 orphaned messages (about 141 GiB of Tenant Media) behind failed sends. DeleteOrphanedMessages is the only supported way to remove them in Business Central online, because the license gives every user, SUPER included, only indirect access to the email tables. As it stands, a company that also retrieves email cannot run it safely, and there is no way online to see which messages it will delete.
Checked against the current main branch of BCApps (src/System Application/App/Email/src/Message/EmailMessageImpl.Codeunit.al).
Expected behavior
A message referenced by an Email Inbox row is not orphaned and DeleteOrphanedMessages keeps it. Suggested fix in DeleteEmailMessageIfOrphaned:
EmailInbox.SetRange("Message Id", EmailMessage.Id);
if not EmailInbox.IsEmpty() then
exit;
and the doc comment in codeunit 8904 updated to mention the inbox.
A message referenced by an Email Inbox row is not orphaned and DeleteOrphanedMessages keeps it. Suggested fix in DeleteEmailMessageIfOrphaned:
EmailInbox.SetRange("Message Id", EmailMessage.Id);
if not EmailInbox.IsEmpty() then
exit;
and the doc comment in codeunit 8904 updated to mention the inbox.
Steps to reproduce
- Set up an email account on a connector that supports retrieval (Microsoft 365 or Current User).
- Call Email.RetrieveEmails for that account, or activate a feature that does (for example the Sales Order Agent). Confirm Email Inbox has rows and their Message Id exists in Email Message.
- Call EmailMessage.DeleteOrphanedMessages(EmptyGuid, 1000) until it returns an empty Guid.
- The retrieved messages are gone from Email Message (EmailMessage.Get(EmailInbox."Message Id") returns false), while the Email Inbox rows remain.
Additional context
BC 27 System Application, same code on current main. Related: Email Inbox has a Retention Policy (my customer's tenant shows it enabled at 2 days), which deletes the inbox row and, through OnAfterDeleteEmailInbox, the message. That is the supported cleanup path for retrieved email, which is another reason DeleteOrphanedMessages should leave those messages alone.
Long term architectural recommendation:
A centralized reference tracking implementation for email message records.
I will provide a fix for a bug
- I will provide a fix for a bug
- Lingua principale
- AL
- Stelle
- 720
- Fork
- 488
- Merge medio
- 2g 17h
- PR unite (30g)
- 568
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/BCApps
-
Team: SCM
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/BCApps#13723 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Team: SCM
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
microsoft/BCApps#13708 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Approved ext-requester-pr request-for-external Team: Finance
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
microsoft/BCApps#13691 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Team: SCM
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
microsoft/BCApps#13635 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Team: Finance
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
microsoft/BCApps#13621 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/BCApps
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
NVIDIA/auto-ontology#463 ·
I maintainer di solito rispondono entro 1 giorno
-
xsd:integer cast from a string rejects negative numbers, a leading + and surrounding whitespaceApertabug 🐛
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
comunica/comunica#1960 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 2 giorni
-
[yugabyted] xcluster set_up and add_to_replication fail for database names containing - . or (Apertakind/bug priority/medium qa_automation
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
yugabyte/yugabyte-db#37324 ·
I maintainer di solito rispondono entro 1 giorno