Skip to content

Can't remove, add or set \Seen #232

@tarach

Description

@tarach

I'm trying to change \Seen flag in an email message but I'm unable to no matter how hard I try ...
I'm using gmail account for testing.

require('dotenv').config();
const config = require('./config');

const ImapClient = require('emailjs-imap-client').default;
const client = new ImapClient(
    config.host,
    config.port,
    config.options
);

const getMessages = async (id) => {
    return await client.listMessages('INBOX', id, ['uid', 'flags', 'body[]']);
};

const printMessages = (messages) => {
    console.log(`Num of messages: ${messages.length}`);
    messages.forEach((message) => {
        if(message.uid === undefined) {
            console.trace(message);
            return null;
        }
        console.log('Flags for ' + message.uid + ': ' + message.flags.join(', '))
    });
};

const main = async () => {
    await client.connect();

    printMessages(await getMessages(7));

    printMessages(await client.setFlags('INBOX', 7, { remove: ['\\Seen']}));

    printMessages(await client.setFlags('INBOX', 7, { remove: ['\Seen'] }));

    printMessages(await getMessages(7));

    await client.close();
};

main().catch(err => console.error(err));

Output:

Num of messages: 1
Flags for 7: \Seen
Num of messages: 1
Trace: { '#': 7, flags: [] }
    at messages.forEach (/f/projects/sms-to-email/index.js:19:21)
    at Array.forEach (<anonymous>)
    at printMessages (/f/projects/sms-to-email/index.js:17:14)
    at main (/f/projects/sms-to-email/index.js:31:5)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Num of messages: 0
Num of messages: 1
Flags for 7: \Seen

I was expecting mail that I'm trying to change to toggle being read/unread in the UI by font from bold normal and vice-versa but nothing happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions