示例#1
0
// ===========================================================================
//  PRIVATE Functions
// ===========================================================================
static ImapMessage *_imapParseMessage (const QString& responseText) {
    if (!responseText.startsWith('*'))
        return(NULL);

    QString response = responseText;

    QRegExp regexId("\\* (\\d*)");
    QRegExp regexMessageId("\"<([^>]+)>\"\\)\\)");
    QRegExp regexFlags("\\(FLAGS \\(([^\\)]*)\\)");
    QRegExp regexInternalDate("INTERNALDATE \"([^\"]+)\"");
    QRegExp regexSize("RFC822.SIZE (\\d+)");
    QRegExp regexEnvelope("ENVELOPE");

    ImapMessage *message = new ImapMessage;
    if (regexId.indexIn(response) != -1)
        message->setId(regexId.cap(1).toInt());
    if (regexFlags.indexIn(response) != -1)
        message->setFlags(regexFlags.cap(1));
    if (regexInternalDate.indexIn(response) != -1)
        message->setReceived(regexInternalDate.cap(1));
    if (regexSize.indexIn(response) != -1)
        message->setSize(regexSize.cap(1).toInt());

    if (regexEnvelope.indexIn(response) != -1) {
        int rmSize = regexEnvelope.pos() + regexEnvelope.matchedLength();
        response = response.remove(0, rmSize);
    }

    QRegExp regexSent("\(\"(?:\\w{3}\\, )?([^\"]+)\"");
示例#2
0
static ImapMessage *_imapParseMessage (const QString& responseText) {
    if (!responseText.startsWith('*'))
        return(NULL);

    QString response = responseText;

    QRegExp regexId("\\* (\\d*)");    
    QRegExp regexMessageId("\"<([^>]+)>\"\\)\\)");
    QRegExp regexFlags("\\(UID (\\d*) FLAGS \\(([^\\)]*)\\)");
    QRegExp regexInternalDate("INTERNALDATE \"([^\"]+)\"");
    QRegExp regexSentDate("ENVELOPE \(\"([^\"]+)\"");
    QRegExp regexSize("RFC822.SIZE (\\d+)");
    QRegExp regexEnvelope("ENVELOPE");   
    QRegExp regexUid("\\(UID (\\d*)\\");

    ImapMessage *message = new ImapMessage;
    if (regexId.indexIn(response) != -1)
        message->setId(regexId.cap(1).toInt());
    if (regexFlags.indexIn(response) != -1)
    {
        message->setFlags(regexFlags.cap(1));
        message->setUid(regexFlags.cap(1));
        //QString tmp = regexFlags.cap(1);
        //QStringList list = tmp.split(" ");

    }
    if (regexInternalDate.indexIn(response) != -1)
        message->setReceived(regexInternalDate.cap(1));
    if (regexSize.indexIn(response) != -1)
        message->setSize(regexSize.cap(1).toInt());



    if (regexEnvelope.indexIn(response) != -1) {
        int rmSize = regexEnvelope.pos() + regexEnvelope.matchedLength();
        response = response.remove(0, rmSize);
    }

    if (regexUid.indexIn(response) != -1)
    {
        QString tmp = regexUid.cap(1);
        QStringList list = tmp.split(" ");


        message->setUid(list[1]);
    }


    QRegExp regexSent("\"([^\"]+)\"");

   // QRegExp regexSent("\(\"(?:\\w{3}\\, )?([^\"]+)\"");
    if (regexSent.indexIn(response) != -1) {
        QRegExp subRegex("([\\-\\+]\\d{4}.*|NIL.*)");
        subRegex.indexIn(regexSent.cap(1));

        message->setSent(regexSent.cap(1).remove(subRegex.pos()));
        message->setTimeZone(subRegex.cap(1));
        response = response.remove(0, regexSent.pos() + regexSent.matchedLength());
    }
 
    QString token = "((";
    int tokenOffset;        
    if (response.contains(token)) {
        tokenOffset = 0;
    } else {
        token = "\" NIL";
        tokenOffset = 2;
    }
    
    QRegExp regexSubject(" \"(.*)\"");
    QString subject = response.mid(0, response.indexOf(token) + tokenOffset).trimmed();
    if (subject == "NIL")
        subject.clear();
    else if (regexSubject.indexIn(subject) != -1)
        subject = regexSubject.cap(1);
    message->setSubject(Imap::decode(subject.toLatin1()));

    if (response.contains("((")) {
        response = response.remove(0, response.indexOf("(("));
    } else {
        if (message->subject().isEmpty())
            message->setSubject(response);
    }
    
    if (regexMessageId.indexIn(response)) {
        message->setMessageId(regexMessageId.cap(1));
        response = response.remove(regexMessageId.pos()).trimmed();
    }
    
    if (response.endsWith("NIL")) {
        response = response.remove(response.size() - 3);
    } else {
        QRegExp regexReference("\"<([^>]+)>\"");
        if (regexReference.indexIn(response) != -1)
        message->setReference(regexReference.cap(1));
    }
    
    message->setAddresses(response.trimmed());
    return(message);
}