I've amended the script below and it works as expected.

What I would like to do is update it so I can move messages from INBOX to various IMAP folders based on specific criteria:

ie:
Subject contains SPAM move to 'Junk'
TO contains Tom move to 'Inbox.Tom'
FROM contains update@ebay.com move to Inbox.Ebay

think you get the idea 🙂

This my starting code:

<?php

/* connect to imap */
$hostname = '{127.0.0.1:143}INBOX';
$username = 'user';
$password = 'pass';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to $hostname: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'ALL');

/* if emails are returned, cycle through each... */
if($emails) {

/* put the newest emails on top */
rsort($emails);

/* for every email... */
foreach($emails as $email_number) {

/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$msg_id=$overview[0]->msgno;
$subj=$overview[0]->subject;

imap_mail_move($inbox,$msg_id,'INBOX.New');

}

} 

/* close the connection */
imap_close($inbox);
?>

Any Ideas ? Thanks 🙂

    Write a Reply...