chadxz / imap-simple

Wrapper over node-imap, providing a simpler api for common use cases
MIT License
243 stars 80 forks source link

Implement Delete function, fix #58 #60

Closed synox closed 4 years ago

chadxz commented 5 years ago

Will you also add a section to the README for the method?

synox commented 5 years ago

yes ill do readme

synox commented 5 years ago

Do you also want to uupdate the example "Open messages and delete them"? Done for today, it's late here.

chadxz commented 5 years ago

That'd be great

synox commented 5 years ago

I would also need a search function that does not fetch, often I just need the uids.

E.g. i want delete all mails older than 1 month, I don't want to fetch them first. Would you expose a search-without-fetch method or create a search+delete method?

So far i am doing for deleting:

        let searchCriteria = [
            ['!DELETED'],
            ['BEFORE', moment().subtract(30, 'days').toDate()]
        ];
    const imapUnderlying = this.connection.imap
    const uids = await new Promise((resolve, reject) => {
        imapUnderlying.search(searchCriteria, (err, uids) => {
            if (err) {
                reject(err)
            } else {
                resolve(uids || [])
            }
        })
    })
    if (uids.length === 0) {
        return
    }
    await this.connection.deleteMessage(uids)
chadxz commented 5 years ago

Either one sounds reasonable. If you wanted a search without fetch we could make the search take an optional parameter to skip the fetch. Or we could add a deleteWhere that accepts search criteria.

synox commented 5 years ago

done, you can merge

tennox commented 4 years ago

@chadxz Would be great if you could merge this, so it could be released - and also #49

chadxz commented 4 years ago

Released as v5.0.0

Thanks for the nudge @TeNNoX