Giter Site home page Giter Site logo

Comments (2)

felixhammerl avatar felixhammerl commented on August 24, 2024

There is a working implementation on top of browserbox that accumulates many of its features in a somewhat opinionated high-level api, so you might want to have a look at that: https://github.com/whiteout-io/imap-client
(We did not really get around to write a proper documentation for the imap-client), but you should be able to figure it out pretty quickly from the inline documentation)

Regarding your code examples: client.connect(); is not synchronous, you need to wait for the onauth callback. Here's an example. Otherwise your queries end up somewhere in oblivion.

Second: useSSL is deprecated, you should use useSecureTransport instead. I'll adapt the README.

Please let me know if that helped.

from emailjs-imap-client.

andris9 avatar andris9 commented on August 24, 2024

The module is not synchronous, just as Felix already stated – you have to wait for the callback before you can make the next command.

What happens with your code is the following:

S: * OK Gimap ready for requests from X.X.X.X j1mb3779317lae ← session idendifier
C: W1 LIST "" "*" ← already calling LIST command even though you're not logged in
S: W1 BAD Unknown command j1mb3779317lae ← error response with session idendifier
                                           the command is 'unknown' because LIST is
                                           available only in the 'authenticated' state

To fix this, your code should be like this:

client.connect();
client.onauth = function() {
    client.listMailboxes(function(err, mailboxes) {
        console.log(err || mailboxes);
        client.selectMailbox(mailbox, function(err, mailbox) {
            console.log(err || 'Mailbox was successfully changed to ' + mailbox);
        });
    });
};

In this case the commands are completely different:

S: * OK Gimap ready for requests from X.X.X.X j1mb3779317lae
C: W1 CAPABILITY
S: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE ...
S: W1 OK Thats all she wrote! j1mb3779317lae
C: W2 ID NIL
S: * ID ("name" "GImap" "vendor" "Google, Inc." ...
S: W2 OK Success j1mb3779317lae
C: W3 login "[email protected]" "some.password"
S: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE ...
S: W3 OK [email protected] Some Email authenticated (Success)
C: W4 LIST "" "*" ← now we send the LIST after successful auth
S: * LIST (\Noselect \HasChildren) "/" "[Gmail]" ← and no error anymore
...

Remember that in addition of onauth you should also set onerror handler, otherwise you might end up with uncaught errors, and the onclose handler to detect if the connection is already closed.

I'll close this issue as it is not a bug but feel free to ask if you have any further questions.

from emailjs-imap-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.