Skip to content

Conversation

Copy link

Copilot AI commented Oct 26, 2025

Adds IMAP client module to check email inbox every minute via wp-cron and send emails via SMTP. Follows the External_Service_Module pattern established by Evernote sync.

Core Implementation

  • IMAP inbox checking: Connects to IMAP server, fetches emails, parses subject/sender/body
  • wp-cron integration: Custom "minutely" interval, tracks last processed email ID to avoid reprocessing
  • Action hook: Triggers pos_imap_new_email for each email with sanitized data
  • SMTP sending: Wraps wp_mail() with custom PHPMailer configuration

Settings

All credentials stored via settings module:

  • IMAP: host, port, username, password, SSL toggle
  • SMTP: host, port, username, password
  • Active toggle for sync enable/disable

Usage

Hook into new emails:

add_action( 'pos_imap_new_email', function( $email_data ) {
    // $email_data: ['id', 'subject', 'from', 'body', 'date']
    // Process email here
}, 10, 1 );

Send email:

$imap_module = POS::get_module_by_id( 'imap' );
$imap_module->send_email( '[email protected]', 'Subject', 'Body' );

Security

  • Email headers sanitized with WordPress functions
  • Base64 decoding uses strict mode
  • Body content excluded from default logging
  • Documentation recommends app-specific passwords and SSL/TLS

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:

  • wordpress.org
    • Triggering command: node /home/REDACTED/work/PersonalOS/PersonalOS/node_modules/.bin/wp-env run tests-cli --env-cwd=wp-content/plugins/personalos ./vendor/bin/phpunit --testsuite=unit (dns block)

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

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement the IMAP module</issue_title>
<issue_description>We need a new module for imap client:

  • We want credentials in settings
  • We want to check that inbox every minute via wp-cron. A pattern for these periodic checks in in evernote sync module
  • Lets get all emails in that email inbox. For each email, lets trigger a new action
  • Lets hook into that hook and log the email to error_log

In the future we will want to process these emails and react to them.

We also want a method to send email from this email inbox using phpmailer

We will also want to have access to attachments attached to emails in this inbox, but for now lets only log subject, sender and body.

The settings should be using the settings module </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Implement IMAP module for email handling Implement IMAP module for email checking and sending Oct 26, 2025
Copilot AI requested a review from artpi October 26, 2025 17:49
Copilot finished work on behalf of artpi October 26, 2025 17:49
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.

Implement the IMAP module

2 participants