Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Adds a new EmailParserOpenAi module that uses OpenAI to parse raw EML content as an alternative to the laminas-mail library.

Changes

  • New EmailParserOpenAi class (/organizer/src/class/Ai/)

    • Accepts raw EML content, returns structured ParsedEmail data class
    • Uses OpenAI structured JSON output for reliable parsing
    • Handles headers (from, to, subject, date, cc, reply_to) and body (plain text, HTML→text)
    • Smart truncation at newlines for large emails (100KB limit)
    • Filters MIME-style base64 blocks to avoid content filter issues
    • Uses gpt-4o-mini by default for cost efficiency
  • Unit tests - 9 tests covering plain text, HTML, multipart, Norwegian characters, edge cases

Usage

use Offpost\Ai\EmailParserOpenAi;

$parser = new EmailParserOpenAi($openaiApiKey);
$parsed = $parser->parseEmail($rawEmlContent);

$parsed->subject;
$parsed->from;
$parsed->getBody();        // plain text preferred
$parsed->getCombinedBody(); // both if different

Existing laminas-mail parsing unchanged for backward compatibility.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/PHPMailer/PHPMailer/zipball/bf74d75a1fde6beaa34a0ddae2ec5fce0f72a144
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/laminas/laminas-loader/zipball/c507d5eccb969f7208434e3980680a1f6c0b1d8d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/laminas/laminas-mail/zipball/110e04497395123998220e244cceecb167cc6dda
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/laminas/laminas-mime/zipball/08cc544778829b7d68d27a097885bd6e7130135e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/laminas/laminas-servicemanager/zipball/a8640182b892b99767d54404d19c5c3b3699f79b
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Mdbipj /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/laminas/laminas-stdlib/zipball/8974a1213be42c3e2f70b2c27b17f910291ab2f4
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Mdbipj /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/laminas/laminas-validator/zipball/b3ec5865e7aa60a0fbce211500f4a5c6a6e11a30
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/myclabs/DeepCopy/zipball/1720ddd719e16cf0db4eb1c6eca108031636d46c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/nikic/PHP-Parser/zipball/ae59794362fe85e051a58ad36b289443f57be7a9
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Mdbipj /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Mdbipj /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/c34583b87e7b7a8055bf6c450c2c77ce32a24084
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/comparator/zipball/a18251eb0b7a2dcd2f7aa3d6078b18545ef0558e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/complexity/zipball/68ff824baeae169ec9f2137158ee529584553799
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/diff/zipball/c41e007b4b62af48218231d6c2275e4c9b975b2e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/955288482d97c19a372d3f31006ab3f37da47adf
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/856e7f6a75a84e339195d48c556f23be2ebf75d0
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7e308268858ed6baedc8704a304727d20bc07c77
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8080be387a5be380dda48c6f41cee4a13aadab3d
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/9614ac4d8061dc257ecc64cba1b140873dce8ad3
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Mdbipj /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Mdbipj /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Mdbipj /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Mdbipj /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/YfsbwB /usr/bin/composer install --no-interaction --prefer-dist (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Replace php lib for reading emails with calls to openai. Make a separe module for it.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 28, 2026 22:41
Co-authored-by: HNygard <168380+HNygard@users.noreply.github.com>
Co-authored-by: HNygard <168380+HNygard@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace PHP library for reading emails with OpenAI calls Add OpenAI-based email parser module Jan 28, 2026
Copilot AI requested a review from HNygard January 28, 2026 22:45
…hema

- Add EmailParserOpenAiRealApiTest.php with 9 tests against real OpenAI API
- Fix structured output schema format (name at top level, not nested in json_schema)
- Tests cover: plain text, Norwegian chars, multipart, CC/Reply-To, quoted-printable, kommune-style emails
- Uses OpenAiIntegrationNoLogging to avoid database dependency in tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants