Logo Search packages:      
Sourcecode: kcheckgmail version File versions

uint GMailParser::parseThread ( const QString &  _data,
const QMap< QString, bool > *  oldMap 
) [protected]

Threads/emails parser.

This parser takes care of extracting the available data from the emails block.

Parameters:
_data The messages data block
oldMap The old messages map, used to detect whether a message was already reported as new or not
Returns:
The number of unread messages that were found in _data

Definition at line 200 of file gmailparser.cpp.

References cleanUpData().

Referenced by parse().

{
      //Matches messages when snippets are on
      static QRegExp rx(
                  "\\[\"([a-fA-F0-9]+)\"\\s*,"  // replyID
                  "\\s*([0-9]+)\\s*,"           // isNew
                  "\\s*([0-9]+)\\s*,"           // unknown1
                  "\\s*\"([^\"]*)\"\\s*,"       // date_short
                  "\\s*\"([^\"]*)\"\\s*,"       // senders
                  "\\s*\"([^\"]*)\"\\s*,"       // chevron
                  "\\s*\"([^\"]*)\"\\s*,"       // subject
                  "\\s*\"([^\"]*)\"\\s*,"       // snippet
                  "\\s*\\[([^\\]]*)\\]\\s*,"    // labels
                  "\\s*\"([^\"]*)\"\\s*,"       // attachments
                  "\\s*\"([a-fA-F0-9]+)\"\\s*," // msgID
                  "\\s*([0-9]+)\\s*,"           // unknown2
                  "\\s*\"([^\"]*)\"\\s*"        // date_long
                  "(,\\s*([0-9]+)\\s*,)?"       // unknown3
                  "(\\s*\"([^\"]*)\"\\s*,)?"    // unknown4
                  "(\\s*([0-9]+)\\s*\\])?"      // unknown5
                   );

      //Matches messages when snippets are off
      static QRegExp rx2(
                  "\\[\"([a-fA-F0-9]+)\"\\s*,"  // replyID
                  "\\s*([0-9]+)\\s*,"           // isNew
                  "\\s*([0-9]+)\\s*,"           // unknown1
                  "\\s*\"([^\"]*)\"\\s*,"       // date_short
                  "\\s*\"([^\"]*)\"\\s*,"       // senders
                  "\\s*\"([^\"]*)\"\\s*,"       // chevron
                  "\\s*\"([^\"]*)\"\\s*,"       // subject
                  "(\\s*),"               // snippet
                  "\\s*\\[([^\\]]*)\\]\\s*,"    // labels
                  "\\s*\"([^\"]*)\"\\s*,"       // attachments
                  "\\s*\"([a-fA-F0-9]+)\"\\s*," // msgID
                  "\\s*([0-9]+)\\s*,"           // unknown2
                  "\\s*\"([^\"]*)\"\\s*"        // date_long
                  "(,\\s*([0-9]+)\\s*,)?"       // unknown3
                  "(\\s*\"([^\"]*)\"\\s*,)?"    // unknown4
                  "(\\s*([0-9]+)\\s*\\])?"      // unknown5
                    );

      QString data = _data;
      data.replace("\\\"","&quot;");

      int pos = 0;

      rx.setMinimal(true);
      rx2.setMinimal(true);

      if(!rx.isValid()) {
            kdWarning() << k_funcinfo << "Invalid RX!\n"
                        << rx.errorString() << endl;
      }

      if(!rx2.isValid()) {
            kdWarning() << k_funcinfo << "Invalid RX2!\n"
                        << rx2.errorString() << endl;
      }
      
      /*
      replyId == msgId if latest message on this 
      thread is not from you
      */

      unsigned int newMsgCount = 0;

      if(oldMap)
            kdDebug() << k_funcinfo << "oldmap.size=" << oldMap->size() << endl;
      else
            kdDebug() << k_funcinfo << "no oldmap" << endl;

      while((pos = rx.search(data, pos)) != -1) {
            Thread *t = new Thread;
            t->id = mCurMsgId ++;
            t->replyId = rx.cap(1);
            t->isNew = rx.cap(2).toInt();
            t->unknown1 = rx.cap(3).toUInt();
            t->date_short = rx.cap(4);
            t->senders = cleanUpData(rx.cap(5));
            t->chevron = rx.cap(6);
            t->subject = cleanUpData(rx.cap(7));
            t->snippet = cleanUpData(rx.cap(8));
            t->labels = rx.cap(9);
            t->attachments = rx.cap(10);
            t->msgId = rx.cap(11);
            t->unknown2 = rx.cap(12).toUInt();
            t->date_long = rx.cap(13);
            t->unknown3 = rx.cap(14).toUInt();
            t->isNull = false;

            if(t->isNew && (!oldMap || 
                         (oldMap->find(t->msgId) == oldMap->end()))) {
                  kdDebug() << "Message [" << t->msgId << "] is new." << endl;
                  newMsgCount ++;
            } else
                  kdDebug() << "Message [" << t->msgId << "] is NOT new." << endl;
            
            // (re-)insert
            mThreads.insert(t->msgId, t);

            pos += rx.matchedLength();
      }

      pos = 0;
      
      while((pos = rx2.search(data, pos)) != -1) {
            Thread *t = new Thread;
            t->id = mCurMsgId ++;
            t->replyId = rx2.cap(1);
            t->isNew = rx2.cap(2).toInt();
            t->unknown1 = rx2.cap(3).toUInt();
            t->date_short = rx2.cap(4);
            t->senders = cleanUpData(rx2.cap(5));
            t->chevron = rx2.cap(6);
            t->subject = cleanUpData(rx2.cap(7));
            t->snippet = cleanUpData(rx2.cap(8));
            t->labels = rx2.cap(9);
            t->attachments = rx2.cap(10);
            t->msgId = rx2.cap(11);
            t->unknown2 = rx2.cap(12).toUInt();
            t->date_long = rx2.cap(13);
            t->unknown3 = rx2.cap(14).toUInt();
            t->isNull = false;

            if(t->isNew && (!oldMap || 
                         (oldMap->find(t->msgId) == oldMap->end()))) {
                  kdDebug() << "Message [" << t->msgId << "] is new." << endl;
                  newMsgCount ++;
            } else
                  kdDebug() << "Message [" << t->msgId << "] is NOT new." << endl;
            
            // (re-)insert
            mThreads.insert(t->msgId, t);

            pos += rx2.matchedLength();
      }

      kdDebug() << k_funcinfo << "Finished searching for threads in: " << endl;
      kdDebug() << data << endl;
      kdDebug() << k_funcinfo << "newMsgCount: " << newMsgCount << endl;

      return newMsgCount;
}


Generated by  Doxygen 1.6.0   Back to index