Ticket #1584 (closed defect: fixed)

Opened 14 years ago

Last modified 14 years ago

Problem loading msg with Communigate IMAP server

Reported by: gracinet Owned by: tziade
Priority: P1 Milestone: CPS 3.4.1
Component: CPSMailAccess Version: 3.4.1
Severity: normal Keywords: Communigate IMAP server
Cc: b.asil@…

Description

Message structure not understood... Quoting b.asil on cps-users-fr, who investigated this:

Aprés quelques investigations (debug), il semble que cela vienne de l'interprétation de la réponse du serveur à la commande UID FETCH (Voir fichier join), notament le UID 2979 à la fin.

La réponse du serveur semble être conforme au RFC 2060.

Dans IMAPConnection_extractResult (pour query='BODY'), self._parseIMAPMessage (result) retourne ['body', 'uid', 2979,...]. Du coup, IMAPConnection.getMessageStructure retourne... 'uid'! C'est cette chaine qui est passée comme paramètre structure_info à la méthode MailMessage?.loadMessage (au lieu d'une liste?). loadMessage utilise structure_info[0] et structure_info[1] pour generer le header content_type (j'ai content_type= u/i; charset="ISO8859-15").

Bon, ok, c'est pas forcément trés clair, mais j'espère que ça pourra aider... Contactez moi si vous voulez plus de détails!

* OK CommuniGate Pro IMAP Server 3.5b7 at xxxx ready
BJEM0 CAPABILITY
* CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA STARTTLS ID MULTIAPPEND AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=NTLM
BJEM0 OK completed
BJEM1 LOGIN "system@xxxx" "xxxx"
BJEM1 OK completed
BJEM2 SELECT Junk
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)] limited
* 143 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 267873078] UIDs valid
* OK [UNSEEN 1] message 1 is first unseen
BJEM2 OK [READ-WRITE] SELECT completed
BJEM3 UID FETCH 2979 (BODY)
* 129 FETCH (BODY ("text" "plain" ("charset" "us-ascii") "1143151408-1-xxxx@xxxx" NIL "7bit" 19901 279) UID 2979)
BJEM3 OK completed_______________________________________________

Change History

comment:1 Changed 14 years ago by gracinet

  • Milestone changed from CPS 3.2.5 to CPS 3.4.1

comment:2 Changed 14 years ago by B.asil

Aprés quelques essais, j'ai constaté que le problème semblait venir de

IMAPConnection._findClosingParenthesis (self, text, start)

Par exemple, pour

_findClosingParenthesis ('129,(BODY ("text" "plain" ("charset" "us-ascii") "1143151408-1-xxxx@xxxx" NIL "7bit" 19901 279) UID 2979)', 5)

la methode retourne l'index de la dernière parenthèse (celle aprés 2979) au lieu de l'avant dernière (celle aprés 279).

Pour tester, j'ai fait deux modifications dans IMAPConnection:

    def _findClosingParenthesis(self, text, start):
        """ closing-finder pattern """
        opened = 0
        i = start + 1
        while i < len(text):
            char = text[i]
            if char == '(':
                opened += 1
            elif char == ')':
                if opened == 0:
                    return i
                else:
                    opened -= 1
            i+=1
        return -1

devient:

    def _findClosingParenthesis(self, text, start):
        """ closing-finder pattern """
        opened = 0
        i = start + 1
        while i < len(text):
            char = text[i]
            if char == '(':
                opened += 1
            elif char == ')':
# ----- begining of modification -----
                opened -= 1
                if opened == 0:
                    return i
# ----- end of modification -----
            i+=1
        return -1

et dans la methode _extractResult, j'ai remplacé

        if query == 'BODY' or query == 'BODYSTRUCTURE':
            # todo
            # parse message
            # XXX should be use by all sub cases
            if isinstance(results, list):
                results = results[0]

            # extract subpart if needed
            cindexstart = results.find('BODYSTRUCTURE (')
            if cindexstart == -1:
                cindexstart = results.find('BODY (')

            if cindexstart != -1:
                cindexstop = self._findClosingParenthesis(results, cindexstart)
                result = results[cindexstart:cindexstop]
            else:
                result = results

            result = self._parseIMAPMessage(result)

par:

        if query == 'BODY' or query == 'BODYSTRUCTURE':
            # todo
            # parse message
            # XXX should be use by all sub cases
            if isinstance(results, list):
                results = results[0]

            # extract subpart if needed
            cindexstart = results.find('BODYSTRUCTURE (')
            if cindexstart == -1:
                cindexstart = results.find('BODY (')

            if cindexstart != -1:
                cindexstop = self._findClosingParenthesis(results, cindexstart)
# ----- begining of modification -----
                result = results[cindexstart:cindexstop + 1]
# ----- end of modification -----
            else:
                result = results

            result = self._parseIMAPMessage(result)

Avec ces modifications, je peux lire le contenu des messages dans le webmail. Cependant, j'ignore si il y a des effets de bord ou si ça fonctionne encore avec d'autres serveurs...

comment:3 Changed 14 years ago by tracguest

Aprés avoir executer les tests, une petite modification s'impose:

    def _findClosingParenthesis(self, text, start):
        """ closing-finder pattern """
        opened = 0
# ----- begining of modification -----
        i = start
# ----- end of modification -----
        while i < len(text):
            char = text[i]
            if char == '(':
                opened += 1
            elif char == ')':
# ----- begining of modification -----
                opened -= 1
# ----- end of modification -----
                if opened == 0:
                    return i
            i+=1
        return -1

comment:4 Changed 14 years ago by fguillaume

Huh, can't all this be done with regexps? Or is the structure too variable?

comment:5 Changed 14 years ago by tziade

  • Priority changed from P2 to P1

comment:6 Changed 14 years ago by tziade

  • Status changed from new to closed
  • Resolution set to fixed

fixed in [35162], thanks for all the feedback

Note: See TracTickets for help on using tickets.