Hello,

on Hotmail/Outlook webmail, when I receive an email message in the spam folder (formally Junk), I can mark the message as Not Junk. The server will then start to deliver the messages from that source, directly into the Inbox, working like a whitelist.

Is it possible to do the same through the IMAP commands? I have been testing for a while, but I haven't find a solution. Moving the messages from Junk to Inbox does not solve, because the following messages will end again in the Junk folder. At this point this seems appropriate. I have tried to display the flags, to see if it were marked as spam, but it does not seem so.

Here's the test script to show the message flags in the Junk folder:

<?php

/**
 * @see http://busylog.net/telnet-imap-commands-note/
 * @see http://stackoverflow.com/a/6994157
 * @see https://github.com/vlucas/phpdotenv
 * @see https://github.com/raveren/kint
 */

require_once './vendor/autoload.php';
use \Dotenv\Dotenv as Dotenv;

$dotenv   = (new Dotenv(__DIR__))->load();
$server   = 'ssl://imap-mail.outlook.com';
$port     = 993;
$login    = $_ENV['IMAP_EMAIL'];
$password = $_ENV['IMAP_PASSW'];
$mailbox  = 'Junk';
$response = [];
$timeout  = 10;
$i = 0;

function fsockread($fp)
{
    $result = [];

    while(substr($str = fgets($fp), 0, 1) == '*')
        $result[] = substr($str, 0, -2);

    $result[] = substr($str, 0, -2);
    return $result;
}

$fp = @fsockopen($server, $port, $errno, $errstr, $timeout);

if(TRUE === is_resource($fp))
{
    # sign in
    fwrite($fp, sprintf(". LOGIN %s %s\r\n", $login, $password));

    $response[] = fsockread($fp);

    # select mailbox
    fwrite($fp, sprintf(". SELECT %s\r\n", $mailbox));

    $select = fsockread($fp);
    $total  = abs(filter_var($select[0], FILTER_SANITIZE_NUMBER_INT));
    $response[] = $select;

    do {

        $i++;

        fwrite($fp, sprintf(". FETCH %s (FLAGS)\r\n", $i));
        $response[] = fsockread($fp);

        if($total <= $i)
            break;

    } while(TRUE);

    fclose($fp);
}

else
    $response[] = 'No connection.';

s($response);

Which returns:

array (6) [
    array (2) [
        string (73) "* OK Outlook.com IMAP4rev1 server version 17.4.0.0 ready (BLU451-IMAP184)"
        string (28) ". OK AUTHENTICATE completed."
    ]
    array (8) [
        string (10) "* 4 EXISTS"
        string (10) "* 1 RECENT"
        string (59) "* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)"
        string (89) "* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags"
        string (43) "* OK [UNSEEN 3] Is the first unseen message"
        string (39) "* OK [UIDVALIDITY 30] UIDVALIDITY value"
        string (50) "* OK [UIDNEXT 35] The next unique identifier value"
        string (35) ". OK [READ-WRITE] SELECT completed."
    ]
    array (2) [
        string (25) "* 1 FETCH (FLAGS (\Seen))"
        string (21) "1 OK FETCH completed."
    ]
    array (2) [
        string (25) "* 2 FETCH (FLAGS (\Seen))"
        string (21) "2 OK FETCH completed."
    ]
    array (2) [
        string (20) "* 3 FETCH (FLAGS ())"
        string (21) "3 OK FETCH completed."
    ]
    array (2) [
        string (27) "* 4 FETCH (FLAGS (\Recent))"
        string (21) "4 OK FETCH completed."
    ]
]

I know some desktop clients use custom flags to mark emails as "junk" or "not junk", but it does not seem to be supported by Hotmail/Outlook. I have also created a rule, in the webmail, to mark mails from a specific address as "junk" but I get only \Recent (because it's the last message).

To simplify I think that the "not junk" flag is defined, in Hotmail/Outlook system, outside of the IMAP protocol, at least I have not found traces in the RFCs. Do you have any suggestions?

Thanks!

Turns out they don't support custom flags, they only support those listed here:

string (59) "* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)"

When custom flags are enabled then there is also this flag \* and it seems they do not support any \Junk flag, otherwise it would be very simple to manage this issue:

. STORE 1 -FLAGS \Junk

I think, however, I can solve it by using their Contacts API: by adding the sender as a contact, then the following messages should arrive in the Inbox, unless I set an override, which is a filter to send messages to specific folders, but this is limited to 1000 contacts:

If it works I will update with a test script.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.