Results 1 to 8 of 8

Thread: Pop3

  1. #1
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Question Pop3

    Hello!

    I have a small problem related to "How does Gpop works?". So the problem is, that STAT-command shows incorrect information about messages amount in my mailbox(I have about 756 messages, STAT-command shows 356). I've read there: http://groups.google.com/group/Gmail...57310cd5b11fc9 , that gmail saves messages in batches and I need to reconnect for getting a new one. And here is the problem:
    - Program connects the first time;
    - It retrieves all messages;
    - Connection is closed by QUIT-command;
    - I tried to reconnect by sending once again the empty message. But server, simply, doesn't response me at all.
    Message sequence, what I used:
    Qt Code:
    1. <connection to the server> //Empty string
    2. USER username
    3. PASS pass
    4. STAT
    5. LIST
    6. RETR
    7. QUIT
    8. <connection to the server> //Here server doesn't response.
    To copy to clipboard, switch view to plain text mode 



    In program I use a loop for getting it work.

    Where can be a problem?

    Thank you for answers beforehand.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Pop3

    I bet that when you QUIT Google's server closes the connection. Anything you send after that is likely being silently ignored (at your end).

    BTW: What does this have to do with Qt? Why don't you ask Google how their system works?

  3. The following user says thank you to ChrisW67 for this useful post:

    DmitryNik (16th September 2011)

  4. #3
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Pop3

    Thank you!

    It could relate to QSslSocket too. And in this case it's more QT than google. For instance, sometimes, after the project rebuilding, program will not start send messages at all. Even the first line "Welcome" will not appear on the screen (qDebug()<<"Welcome". Sockets are not that new subject for me, but in QT, sometimes, I have some problems=)

  5. #4
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Exclamation Re: Pop3

    I have to admit, that I don't understand something in "How does qDebug() << message work?". Apparently, at any one time, when we call qDebug() << something; something suppose to appear in the console, isn't it? But in this piece of code it will not work in a right way:
    Qt Code:
    1. socket->write("LIST\r\n");
    2. QString str;
    3. while(socket->waitForReadyRead())
    4. {
    5. str = socket->readAll().data();
    6. qDebug() << str;
    7. qDebug() << str.length();
    8. }
    To copy to clipboard, switch view to plain text mode 

    I will not get the length of the string in the console. I tried to put a break-point. Yes, program will stop on that point, but once again there is no result on the screen for some reason. May be I need to include something in .pro file, besides QT += network. I don't know. Could you please explain me, what's going on behind the scene in qDebug() and why it will not show any results?

    Thank you beforehand.

    p.s. I consider the worst scenario, when message will be received by chunks. In this case either once the length will be shown or nothing at all.
    p.p.s. I solved problem in this way:

    Qt Code:
    1. socket->write("LIST\r\n");
    2. while(socket->waitForReadyRead())
    3. {
    4. arr.insert(arr.length(), socket->readAll());
    5. qDebug() << arr.data();
    6. qDebug() << "Length: " << arr.length();
    7. if(arr.endsWith(".\r\n"))
    8. break;
    9. }
    To copy to clipboard, switch view to plain text mode 

    I got the right result. But why for the QString it doesn't work? I'm a bit confused. In the world of C++
    Qt Code:
    1. std::cout
    To copy to clipboard, switch view to plain text mode 
    works perfectly. And we always can grab the right result for the string length... Honestly, I don't get it, how does qt interpret length-function for the QString...
    Last edited by DmitryNik; 17th September 2011 at 11:57.

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Pop3

    Qt Code:
    1. socket->write("LIST\r\n");
    2. QString str;
    3. while(socket->waitForReadyRead())
    4. {
    5. str = socket->readAll().data();
    6. qDebug() << str;
    7. qDebug() << str.length();
    8. }
    To copy to clipboard, switch view to plain text mode 
    You are retrieving a bunch of bytes into a QByteArray using QTcpSocket::readAll(). This may not be any sort of character data (although it should be for POP3) or a complete message. You then assume the content of the array is a C-style string (QByteArray::data()) and assign it to a QString. QString:perator=() runs it through fromAscii() which, depending what is actually in the data and the current codec settings, may do odd things to it. After that QString will report the number of characters in the QString.

    On Windows you may need "CONFIG += console" to get console output when a debugger is not present.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  7. The following user says thank you to ChrisW67 for this useful post:

    DmitryNik (18th September 2011)

  8. #6
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Question Re: Pop3

    Thank you. Now I understand that. I presume, I can use only QByteArray, without QString.

    BTW, I have one question: does qt have the class, which is related to readers-writers problem? Or we still need to write something like that:

    Qt Code:
    1. while(true)
    2. {
    3. mutex.acqure();
    4. readcount++;
    5. if(readcount == 1) mutex.acqure();
    6. mutex.release();
    7.  
    8. //critical section
    9.  
    10. mutex.acqure();
    11. readcount--;
    12. if(readcount == 0) mutex.release();
    13. mutex.release();
    14. }
    To copy to clipboard, switch view to plain text mode 

    In C#, for instance, we have ReaderWriterLockSlim class, which reduce amount of code.
    Last edited by DmitryNik; 18th September 2011 at 10:17.

  9. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Talking Re: Pop3

    Have a look at QMutex and the See Also list on that page.

  10. The following user says thank you to ChrisW67 for this useful post:

    DmitryNik (19th September 2011)

  11. #8
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Pop3

    Thank you once again for clarifying.

    p.s. yeah, that thread is not only about pop3 now =D

Similar Threads

  1. Stopping the download process during pop3 session.
    By kremuwa in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2010, 23:41
  2. Replies: 3
    Last Post: 9th July 2010, 20:55
  3. Replies: 2
    Last Post: 4th July 2010, 22:49
  4. Downloading specific mails using POP3 protocol.
    By kremuwa in forum General Programming
    Replies: 1
    Last Post: 22nd May 2010, 10:06
  5. Simply Client E-mail (POP3)
    By Altertwin in forum Qt Programming
    Replies: 5
    Last Post: 25th February 2010, 17:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.