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

LookupError: 'quoted-printable' is not a text encoding; use codecs.decode() to handle arbitrary codecs #17

Open
kostiantynvoiku opened this issue Jun 14, 2018 · 3 comments

Comments

@kostiantynvoiku
Copy link

kostiantynvoiku commented Jun 14, 2018

Hello there,

I'm getting this LookupError when I try to use Get Links From Email keyword:

Open Mailbox  server=imap.googlemail.com  [email protected]  password=pass ${proWelcomeMail} =    Wait for Email  recipient=${USER_EMAIL}  subject=Welcome
Open Link From Email  ${proWelcomeMail}
...
Close Mailbox

Output:
2018-06-14 15-43-29

Is there a workaround for this please?

@Ph38240
Copy link

Ph38240 commented Aug 13, 2018

Hy,

To avoid the error, i've just modify the Library in the src/ImpaLibrary/_init_.py file
In the import section, i've add

import quopri

And I've modify the get_email_body method

    def get_email_body(self, email_index):
        """Returns the decoded email body on multipart email message,
        otherwise returns the body text.

        Arguments:
        - ``email_index``: An email index to identity the email message.

        Examples:
        | Get Email Body | INDEX |
        """
        if self._is_walking_multipart(email_index):
            print('multipart')
            body = self.get_multipart_payload(decode=True)
        else:
            **raw_body = quopri.decodestring(self._imap.uid('fetch',
                                  email_index,'(BODY[TEXT])')[1][0][1]).decode('utf-8')
            body = message_from_string(raw_body)**
        return body

I'm not sure that .decode('utf-8') work in all the case !

For my own test, I've add a new function: get_email_header

    def get_email_header(self, email_index):
        """Returns the decoded email header of the email message in a dictionary

        Arguments:
        - ``email_index``: An email index to identity the email message.

        Examples:
        | Get Email Header | INDEX |
        """
        # decode('quoted-printable')
        raw_header = quopri.decodestring(self._imap.uid('fetch',email_index,
                              '(BODY[HEADER])')[1][0][1]).decode('utf-8')
        header = message_from_string(raw_header)
        result = {}
        result['From'] = header['From']
        result['To'] = header['To']
        result['Date'] = header['Date']
        result['Subject'] = header['Subject']
        result['Content-Type'] = header['Content-Type']
        result['Content-Language'] = header['Content-Language']
        result['Return-Path'] = header['Return-Path']
        return result

Perhaps this solution might be pulled in the git ..

@jasonbarr
Copy link

Getting the same issue, will give this workaround a try. Looks like it's a common problem...

@tigsuway
Copy link

Any working work-around or fix?

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

4 participants