Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchLast and fetchMessages never return... #49

Closed
ikemuc opened this issue Feb 12, 2017 · 8 comments
Closed

fetchLast and fetchMessages never return... #49

ikemuc opened this issue Feb 12, 2017 · 8 comments

Comments

@ikemuc
Copy link

ikemuc commented Feb 12, 2017

I try to access my IMAP server with this code, which is based on your demo code:

`

import Foundation
import Postal

class MailManagerPostal {
    var configuration: Configuration!
    
    fileprivate lazy var postal: Postal = Postal(configuration: self.configuration)
    fileprivate var messages: [FetchResult] = []
    
    init(hostname: String, userName: String, password: String) {
        log.debug("init called...")
        
        configuration = Configuration(hostname: hostname, port: 993, login: userName, password: .plain(password), connectionType: .tls, checkCertificateEnabled: false)

        log.debug("configuration created: \(self.configuration.description)")
        
        postal.connect(timeout: Postal.defaultTimeout, completion: { [weak self] result in
            log.debug("postal.connect completed.")
            switch result {
            case .success:
                log.debug("fetching messages now.")
                
                let indexset = IndexSet(0...100000)
                
                self?.postal.fetchMessages("INBOX", uids: indexset, flags: [ .fullHeaders ], onMessage: { message in
                    log.debug("message : \(message.header)")
                    self?.messages.insert(message, at: 0)
                }, onComplete: { error in
                    if let error = error {
                        log.error("fetch failed: \((error as NSError).localizedDescription)")
                    } else {
                        log.debug("connection successful")
                    }
                    log.debug("fetch complete.")
                })
                
            case .failure(let error):
                log.error("connection failed: \((error as NSError).localizedDescription)")
            }
        })
        log.debug("init finished.")
    }
}

`

Problem: The last message I see is "fetching messages now.". Then nothing happens any more. What's happening here? Where is my mistake? The credentials I use work with using mailcode2 without a problem.

Some more questions:

  • How can I debug the IMAP requests?
  • Where can I find a documentation of the API?
  • Can I manipulate message, especially add custom headers to a message (or take a message, add custom headers, write it as a new message to the server and delete the old one...)?
@matadan
Copy link

matadan commented Feb 12, 2017 via email

@ikemuc
Copy link
Author

ikemuc commented Feb 12, 2017

The first try was exactly the demo code with fetchLast() with 50 messages. It didn't work. Then I tried fetchLast() with 3 messages. Then I changed it to fetchMessages... Always the same problem...

@matadan
Copy link

matadan commented Feb 12, 2017 via email

@ikemuc
Copy link
Author

ikemuc commented Feb 12, 2017

Tested it with 0..10 just to make sure. Same problem.

I updated to 0.4.1 today, that didn't solve the problem...

@matadan
Copy link

matadan commented Feb 12, 2017

My issue was fixed with 0.4.1 but it sounds like you have a different issue.

@ikemuc
Copy link
Author

ikemuc commented Feb 12, 2017

I shifted the initialization of postal to the init() method and now it works.

class KanbanManagerPostal {
var configuration: Configuration!

var messages: [FetchResult] = []

init(hostname: String, userName: String, password: String) {
    log.debug("init called...")
    
    configuration = Configuration(hostname: hostname, port: 993, login: userName, password: .plain(password), connectionType: .tls, checkCertificateEnabled: false)
    
    var postal: Postal = Postal(configuration: configuration)
[...]

@ikemuc
Copy link
Author

ikemuc commented Feb 12, 2017

Now there are only the other questions unanswered ;-)

  • How can I debug the IMAP requests?
  • Where can I find a documentation of the API?
  • Can I manipulate a message, especially add custom headers to a message (or take a message, add custom headers, write it as a new message to the server and delete the old one...)?

@klefevre
Copy link
Contributor

klefevre commented Feb 13, 2017

@ikemuc To answer your questions:

- How can I debug the IMAP requests?
You can set a closure on a Postal instance to have IMAP logs:

let postal = Postal(configuration: ...)
postal.logger { log in
    print(log)
}

- Where can I find a documentation of the API?

Unfortunately there isn't yet an official documentation of the API but we documented every public functions that you can access through xcode but I agree it's not enough. Everything should be ok to add jazzy or something like that if you want to do it, PR are welcome ! :)

- Can I manipulate a message, especially add custom headers to a message (or take a message, add custom headers, write it as a new message to the server and delete the old one...)?

No, Postal was first designed in first place only for fetching messages, not manipulating them. But I don't think it would be hard to add such features since libetpan propose an API for that.

Your issue seems fixed so I close it. If you want new features, please submit an issue and we'll figure out how to implement them as quickly as possible 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants