#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-
"""This module take care of the comunication between aplication and the POP3
python api.
"""

from poplib import POP3, error_proto


class PopMessages(object):
    """This class takes care of retrieving messages from a pop3 server."""

    def __init__(self, host, port):
        """__init__() creatas a new instance of PopMessages."""

        self.pop = POP3(host, port)

    def set_login(self, user, passwd):
        """set_logi method takes a username and a password that it sends to
        poplib that in turn sends it to the mailserver.
        """
        self.pop.user(user)
        self.pop.pass_(passwd)
         

    def get_status(self):
        """get_status() checks the status of the mail repository."""
        
        return self.pop.stat()

    def get_message_length(self):
        """get_message_length() check the length of a message."""
        
        return self.pop.list()[1]
        
    def retrieve_message(self, i):
        """retrieve_message() retrieves messages one by one from mailserver."""
        
        return self.pop.retr(i)[1]
