Diffstat (limited to 'noncore/unsupported/mail2/libmail/imapbase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/mail2/libmail/imapbase.cpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/noncore/unsupported/mail2/libmail/imapbase.cpp b/noncore/unsupported/mail2/libmail/imapbase.cpp index 9a2ba47..4753f43 100644 --- a/noncore/unsupported/mail2/libmail/imapbase.cpp +++ b/noncore/unsupported/mail2/libmail/imapbase.cpp | |||
@@ -32,79 +32,101 @@ void IMAPBase::disconnect() | |||
32 | _connected = false; | 32 | _connected = false; |
33 | delete _socket; | 33 | delete _socket; |
34 | emit disconnected(); | 34 | emit disconnected(); |
35 | } | 35 | } |
36 | 36 | ||
37 | void IMAPBase::makeConnect() | 37 | void IMAPBase::makeConnect() |
38 | { | 38 | { |
39 | emit lookingUpHost(); | 39 | emit lookingUpHost(); |
40 | if (_socket == NULL) _socket = new QSocket(this); | 40 | if (_socket == NULL) _socket = new QSocket(this); |
41 | 41 | ||
42 | Q_UINT16 port = _account.imapPort().toUInt(); | 42 | Q_UINT16 port = _account.imapPort().toUInt(); |
43 | _socket->connectToHost(_account.imapServer(), port); | 43 | _socket->connectToHost(_account.imapServer(), port); |
44 | } | 44 | } |
45 | 45 | ||
46 | void IMAPBase::writeCommands() | 46 | void IMAPBase::writeCommands() |
47 | { | 47 | { |
48 | if (!_connected) return; | 48 | if (!_connected) return; |
49 | if (_commandQueue.isEmpty()) return; | 49 | if (_commandQueue.isEmpty()) return; |
50 | if (!_writingAllowed) return; | 50 | if (!_writingAllowed) return; |
51 | 51 | ||
52 | QStringList::Iterator it; | 52 | QStringList::Iterator it; |
53 | for (it = _commandQueue.begin(); it != _commandQueue.end(); it++) { | 53 | for (it = _commandQueue.begin(); it != _commandQueue.end(); it++) { |
54 | if (!(*it).isEmpty() && _writingAllowed) { | 54 | if (!(*it).isEmpty() && _writingAllowed) { |
55 | #ifndef QT_NO_DEBUG | 55 | #ifndef QT_NO_DEBUG |
56 | qDebug("IMAP > " + (*it).stripWhiteSpace()); | 56 | qDebug("IMAP > " + (*it).stripWhiteSpace().local8Bit ()); |
57 | #endif | 57 | #endif |
58 | _socket->writeBlock((*it).latin1(), (*it).length()); | 58 | _socket->writeBlock((*it).latin1(), (*it).length()); |
59 | _writingAllowed = false; | 59 | _writingAllowed = false; |
60 | if (( *it ). find ( QRegExp ( "^[a-z][0-9]+ " )) == 0 ) | ||
61 | _lasttag = (*it).left(2); | ||
62 | |||
63 | connect(_socket, SIGNAL(readyRead()), SLOT(slotDataAvailiable())); | ||
60 | _commandQueue.remove(it); | 64 | _commandQueue.remove(it); |
61 | break; | 65 | break; |
62 | } | 66 | } |
63 | } | 67 | } |
64 | } | 68 | } |
65 | 69 | ||
66 | void IMAPBase::slotError(int err) | 70 | void IMAPBase::slotError(int err) |
67 | { | 71 | { |
68 | if (err == QSocket::ErrConnectionRefused) { | 72 | if (err == QSocket::ErrConnectionRefused) { |
69 | emit error(IMAPErrConnectionRefused); | 73 | emit error(IMAPErrConnectionRefused); |
70 | } else if (err == QSocket::ErrHostNotFound) { | 74 | } else if (err == QSocket::ErrHostNotFound) { |
71 | emit error(IMAPErrHostNotFound); | 75 | emit error(IMAPErrHostNotFound); |
72 | } else if (err == QSocket::ErrSocketRead) { | 76 | } else if (err == QSocket::ErrSocketRead) { |
73 | emit error(IMAPErrSocketRead); | 77 | emit error(IMAPErrSocketRead); |
74 | } else { | 78 | } else { |
75 | emit error(IMAPErrUnknownError); | 79 | emit error(IMAPErrUnknownError); |
76 | } | 80 | } |
77 | } | 81 | } |
78 | 82 | ||
79 | void IMAPBase::slotHostFound() | 83 | void IMAPBase::slotHostFound() |
80 | { | 84 | { |
81 | emit hostFound(); | 85 | emit hostFound(); |
82 | } | 86 | } |
83 | 87 | ||
84 | void IMAPBase::slotConnected() | 88 | void IMAPBase::slotConnected() |
85 | { | 89 | { |
86 | _connected = true; | 90 | _connected = true; |
87 | emit connected(); | 91 | emit connected(); |
88 | } | 92 | } |
89 | 93 | ||
90 | void IMAPBase::slotDisconnected() | 94 | void IMAPBase::slotDisconnected() |
91 | { | 95 | { |
92 | _connected = false; | 96 | _connected = false; |
93 | emit disconnected(); | 97 | emit disconnected(); |
94 | } | 98 | } |
95 | 99 | ||
100 | #include <unistd.h> | ||
101 | |||
96 | void IMAPBase::slotDataAvailiable() | 102 | void IMAPBase::slotDataAvailiable() |
97 | { | 103 | { |
104 | static bool firstline = true; | ||
105 | |||
98 | while (_socket->canReadLine()) { | 106 | while (_socket->canReadLine()) { |
99 | _data += _socket->readLine(); | 107 | QString tmp = _socket-> readLine ( ); |
100 | if (_socket->atEnd()) { | 108 | |
101 | #ifndef QT_NO_DEBUG | 109 | _data += tmp; |
102 | qDebug("IMAP < " + _data.stripWhiteSpace()); | 110 | qDebug ( "New Line [%d]: '%s'\n", _connected ? 1 : 0, tmp.latin1( )); |
103 | #endif | 111 | |
112 | if ( firstline || tmp. left(2) == _lasttag ) { | ||
113 | firstline = false; | ||
114 | |||
115 | // if ( _socket-> atEnd ( )) | ||
116 | qDebug ( "at end -> emitting\n" ); | ||
117 | |||
118 | QObject::disconnect(_socket, SIGNAL(readyRead()), this, SLOT(slotDataAvailiable())); | ||
104 | emit dataReceived(_data); | 119 | emit dataReceived(_data); |
120 | _data = QString::null; | ||
105 | _writingAllowed = true; | 121 | _writingAllowed = true; |
106 | _data = QString(0); | ||
107 | } | 122 | } |
108 | } | 123 | } |
109 | } | 124 | } |
110 | 125 | ||
126 | void IMAPBase::tryRead ( QString &data ) | ||
127 | { | ||
128 | qDebug ( "Trying to read...\n" ); | ||
129 | |||
130 | while ( _socket-> canReadLine ( )) | ||
131 | data += _socket-> readLine ( ); | ||
132 | } | ||