---
id: object/codeunit/3322
type: object
title: Codeunit 3322 "PA Email Cleanup"
summary: Codeunit 3322 "PA Email Cleanup" in PayablesAgent (Microsoft.Agent.PayablesAgent). 5 public procedures. Introduced in BC29, still in BC30.
tier: official
language: en
tags:
  - codeunit
  - payablesagent
versions:
  introduced: "29"
  last_changed: null
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: 2696491e00e0613202df711a4c6591eb1b13519cc8e75cadbe72c06784f4fd0a
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Apps/W1/PayablesAgent/app/EmailStorageCleanup/PAEmailCleanup.Codeunit.al
    title: src/Apps/W1/PayablesAgent/app/EmailStorageCleanup/PAEmailCleanup.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcapps/11950
    - change/bcapps/11890
object_type: codeunit
object_id: 3322
name: PA Email Cleanup
namespace: Microsoft.Agent.PayablesAgent
app: PayablesAgent
extends: null
first_version: "29"
last_version: "30"
present_in:
  - "29"
  - "30"
changed_in: []
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 11
  events: 0
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 1
  called_by: 3
  implements: 0
---

# Codeunit 3322 "PA Email Cleanup"

> Codeunit 3322 "PA Email Cleanup" in PayablesAgent (Microsoft.Agent.PayablesAgent). 5 public procedures. Introduced in BC29, still in BC30.

PayablesAgent · Microsoft.Agent.PayablesAgent · BC29-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Apps/W1/PayablesAgent/app/EmailStorageCleanup/PAEmailCleanup.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| Access | Internal |
| Permissions | tabledata "Email Inbox" = rd |

## Procedures

- `BuildDuplicateGroups(var TempDuplicateBuffer: Record "PA Email Duplicate Buffer" temporary): Integer`: Scans the Email Inbox and fills the buffer with one row per duplicate group.
- `GetDuplicateStatistics(var GroupCount: Integer; var RedundantRowCount: Integer; var SkippedRowCount: Integer)`
- `CleanUpDuplicates(): Integer`: Deletes every safe-to-delete redundant Email Inbox row, keeping the oldest copy of each email and leaving skipped copies untouched.
- `DeleteRedundantRowsOfGroup(var TempDuplicateBuffer: Record "PA Email Duplicate Buffer" temporary; CommitBatchSize: Integer; DeleteLimit: Integer; var DeletedCount: Integer; var SkippedCount: Integer; var UncommittedCount: Integer)` (internal)
- `IsSafeToDelete(MessageId: Guid): Boolean` (internal)

Plus 6 local procedures.

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 3328 "PA Email Inbox Row Delete"](../codeunit/3328.md) (1 call: `DeleteRedundantRowsOfGroup → (object)`)

## Called by

- [Codeunit 3323 "PA Email Cleanup Runner"](../codeunit/3323.md) (1 call: `OnRun → CleanUpDuplicates`)
- [Page 3325 "PA Email Storage Cleanup"](../page/3325.md) (1 call: `RefreshStatistics → GetDuplicateStatistics`)
- [Page 3326 "PA Email Duplicates"](../page/3326.md) (1 call: `Reload → BuildDuplicateGroups`)

## Recent changes

- 2026-09-28 [#11950 Adding an in-product email storage cleanup (backport to releases/29.x)](../../changes/bcapps/11950.md) (releases/29.x, BC29, feature, added)
- 2026-09-28 [#11890 Adding an in-product email storage cleanup](../../changes/bcapps/11890.md) (main, BC30, feature, added)

## Across versions

- Present in: BC29-30
- Changed (declaration) in: none

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "PA Email Cleanup")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
