-rw-r--r-- | noncore/net/mailit/smtpclient.cpp | 10 | ||||
-rw-r--r-- | noncore/unsupported/mailit/smtpclient.cpp | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/noncore/net/mailit/smtpclient.cpp b/noncore/net/mailit/smtpclient.cpp index 3bdc072..6699a90 100644 --- a/noncore/net/mailit/smtpclient.cpp +++ b/noncore/net/mailit/smtpclient.cpp | |||
@@ -1,163 +1,171 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "smtpclient.h" | 20 | #include "smtpclient.h" |
21 | #include "emailhandler.h" | 21 | #include "emailhandler.h" |
22 | 22 | ||
23 | SmtpClient::SmtpClient() | 23 | SmtpClient::SmtpClient() |
24 | { | 24 | { |
25 | socket = new QSocket(this, "smtpClient"); | 25 | socket = new QSocket(this, "smtpClient"); |
26 | stream = new QTextStream(socket); | 26 | stream = new QTextStream(socket); |
27 | mailList.setAutoDelete(TRUE); | 27 | mailList.setAutoDelete(TRUE); |
28 | 28 | ||
29 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 29 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
30 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 30 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
31 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 31 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
32 | 32 | ||
33 | sending = FALSE; | 33 | sending = FALSE; |
34 | } | 34 | } |
35 | 35 | ||
36 | SmtpClient::~SmtpClient() | 36 | SmtpClient::~SmtpClient() |
37 | { | 37 | { |
38 | delete socket; | 38 | delete socket; |
39 | delete stream; | 39 | delete stream; |
40 | } | 40 | } |
41 | 41 | ||
42 | void SmtpClient::newConnection(QString target, int port) | 42 | void SmtpClient::newConnection(QString target, int port) |
43 | { | 43 | { |
44 | if (sending) { | 44 | if (sending) { |
45 | qWarning("socket in use, connection refused"); | 45 | qWarning("socket in use, connection refused"); |
46 | return; | 46 | return; |
47 | } | 47 | } |
48 | 48 | ||
49 | status = Init; | 49 | status = Init; |
50 | sending = TRUE; | 50 | sending = TRUE; |
51 | socket->connectToHost(target, port); | 51 | socket->connectToHost(target, port); |
52 | 52 | ||
53 | emit updateStatus(tr("DNS lookup")); | 53 | emit updateStatus(tr("DNS lookup")); |
54 | } | 54 | } |
55 | 55 | ||
56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) | 56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) |
57 | { | 57 | { |
58 | RawEmail *mail = new RawEmail; | 58 | RawEmail *mail = new RawEmail; |
59 | 59 | ||
60 | mail->from = from; | 60 | mail->from = from; |
61 | mail->subject = subject; | 61 | mail->subject = subject; |
62 | mail->to = to; | 62 | mail->to = to; |
63 | mail->body = body; | 63 | mail->body = body; |
64 | 64 | ||
65 | mailList.append(mail); | 65 | mailList.append(mail); |
66 | } | 66 | } |
67 | 67 | ||
68 | void SmtpClient::connectionEstablished() | 68 | void SmtpClient::connectionEstablished() |
69 | { | 69 | { |
70 | emit updateStatus(tr("Connection established")); | 70 | emit updateStatus(tr("Connection established")); |
71 | 71 | ||
72 | } | 72 | } |
73 | 73 | ||
74 | void SmtpClient::errorHandling(int status) | 74 | void SmtpClient::errorHandling(int status) |
75 | { | 75 | { |
76 | emit errorOccurred(status); | 76 | emit errorOccurred(status); |
77 | socket->close(); | 77 | socket->close(); |
78 | mailList.clear(); | 78 | mailList.clear(); |
79 | sending = FALSE; | 79 | sending = FALSE; |
80 | } | 80 | } |
81 | 81 | ||
82 | void SmtpClient::incomingData() | 82 | void SmtpClient::incomingData() |
83 | { | 83 | { |
84 | QString response; | 84 | QString response; |
85 | 85 | ||
86 | if (!socket->canReadLine()) | 86 | if (!socket->canReadLine()) |
87 | return; | 87 | return; |
88 | 88 | ||
89 | response = socket->readLine(); | 89 | response = socket->readLine(); |
90 | 90 | qDebug(response); | |
91 | |||
91 | switch(status) { | 92 | switch(status) { |
92 | case Init: { | 93 | case Init: { |
93 | if (response[0] == '2') { | 94 | if (response[0] == '2') { |
94 | status = From; | 95 | status = From; |
95 | mailPtr = mailList.first(); | 96 | mailPtr = mailList.first(); |
96 | *stream << "HELO there\r\n"; | 97 | *stream << "HELO there\r\n"; |
98 | qDebug("HELO"); | ||
97 | } else errorHandling(ErrUnknownResponse); | 99 | } else errorHandling(ErrUnknownResponse); |
98 | break; | 100 | break; |
99 | } | 101 | } |
100 | case From: { | 102 | case From: { |
101 | if (response[0] == '2') { | 103 | if (response[0] == '2') { |
102 | *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; | 104 | *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; |
103 | status = Recv; | 105 | status = Recv; |
106 | qDebug("MAIL FROM: "+mailPtr->from); | ||
104 | } else errorHandling(ErrUnknownResponse); | 107 | } else errorHandling(ErrUnknownResponse); |
105 | break; | 108 | break; |
106 | } | 109 | } |
107 | case Recv: { | 110 | case Recv: { |
108 | if (response[0] == '2') { | 111 | if (response[0] == '2') { |
109 | it = mailPtr->to.begin(); | 112 | it = mailPtr->to.begin(); |
110 | if (it == NULL) | 113 | if (it == NULL) |
111 | errorHandling(ErrUnknownResponse); | 114 | errorHandling(ErrUnknownResponse); |
112 | *stream << "RCPT TO: <" << *it << ">\r\n"; | 115 | *stream << "RCPT TO: <" << *it << ">\r\n"; |
116 | qDebug("RCPT TO: "+ *it); | ||
113 | status = MRcv; | 117 | status = MRcv; |
114 | } else errorHandling(ErrUnknownResponse); | 118 | } else errorHandling(ErrUnknownResponse); |
115 | break; | 119 | break; |
116 | } | 120 | } |
117 | case MRcv: { | 121 | case MRcv: { |
118 | if (response[0] == '2') { | 122 | if (response[0] == '2') { |
119 | it++; | 123 | it++; |
120 | if ( it != mailPtr->to.end() ) { | 124 | if ( it != mailPtr->to.end() ) { |
121 | *stream << "RCPT TO: <" << *it << ">\r\n"; | 125 | *stream << "RCPT TO: <" << *it << ">\r\n"; |
126 | qDebug("RCPT TO: "+ *it); | ||
122 | break; | 127 | break; |
123 | } else { | 128 | } else { |
124 | status = Data; | 129 | status = Data; |
125 | } | 130 | } |
126 | } else errorHandling(ErrUnknownResponse); | 131 | } else errorHandling(ErrUnknownResponse); |
127 | } | 132 | } |
128 | case Data: { | 133 | case Data: { |
129 | if (response[0] == '2') { | 134 | if (response[0] == '2') { |
130 | *stream << "DATA\r\n"; | 135 | *stream << "DATA\r\n"; |
131 | status = Body; | 136 | status = Body; |
137 | qDebug("DATA"); | ||
132 | emit updateStatus(tr("Sending: ") + mailPtr->subject); | 138 | emit updateStatus(tr("Sending: ") + mailPtr->subject); |
133 | } else errorHandling(ErrUnknownResponse); | 139 | } else errorHandling(ErrUnknownResponse); |
134 | break; | 140 | break; |
135 | } | 141 | } |
136 | case Body: { | 142 | case Body: { |
137 | if (response[0] == '3') { | 143 | if (response[0] == '3') { |
138 | *stream << mailPtr->body << "\r\n.\r\n"; | 144 | *stream << mailPtr->body << "\r\n.\r\n"; |
139 | mailPtr = mailList.next(); | 145 | mailPtr = mailList.next(); |
140 | if (mailPtr != NULL) { | 146 | if (mailPtr != NULL) { |
141 | status = From; | 147 | status = From; |
142 | } else { | 148 | } else { |
143 | status = Quit; | 149 | status = Quit; |
144 | } | 150 | } |
151 | qDebug("BODY"); | ||
145 | } else errorHandling(ErrUnknownResponse); | 152 | } else errorHandling(ErrUnknownResponse); |
146 | break; | 153 | break; |
147 | } | 154 | } |
148 | case Quit: { | 155 | case Quit: { |
149 | if (response[0] == '2') { | 156 | if (response[0] == '2') { |
150 | *stream << "QUIT\r\n"; | 157 | *stream << "QUIT\r\n"; |
151 | status = Done; | 158 | status = Done; |
152 | QString temp; | 159 | QString temp; |
153 | temp.setNum(mailList.count()); | 160 | temp.setNum(mailList.count()); |
154 | emit updateStatus(tr("Sent ") + temp + tr(" messages")); | 161 | emit updateStatus(tr("Sent ") + temp + tr(" messages")); |
155 | emit mailSent(); | 162 | emit mailSent(); |
156 | mailList.clear(); | 163 | mailList.clear(); |
157 | sending = FALSE; | 164 | sending = FALSE; |
158 | socket->close(); | 165 | socket->close(); |
166 | qDebug("QUIT"); | ||
159 | } else errorHandling(ErrUnknownResponse); | 167 | } else errorHandling(ErrUnknownResponse); |
160 | break; | 168 | break; |
161 | } | 169 | } |
162 | } | 170 | } |
163 | } | 171 | } |
diff --git a/noncore/unsupported/mailit/smtpclient.cpp b/noncore/unsupported/mailit/smtpclient.cpp index 3bdc072..6699a90 100644 --- a/noncore/unsupported/mailit/smtpclient.cpp +++ b/noncore/unsupported/mailit/smtpclient.cpp | |||
@@ -1,163 +1,171 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "smtpclient.h" | 20 | #include "smtpclient.h" |
21 | #include "emailhandler.h" | 21 | #include "emailhandler.h" |
22 | 22 | ||
23 | SmtpClient::SmtpClient() | 23 | SmtpClient::SmtpClient() |
24 | { | 24 | { |
25 | socket = new QSocket(this, "smtpClient"); | 25 | socket = new QSocket(this, "smtpClient"); |
26 | stream = new QTextStream(socket); | 26 | stream = new QTextStream(socket); |
27 | mailList.setAutoDelete(TRUE); | 27 | mailList.setAutoDelete(TRUE); |
28 | 28 | ||
29 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 29 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
30 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 30 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
31 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 31 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
32 | 32 | ||
33 | sending = FALSE; | 33 | sending = FALSE; |
34 | } | 34 | } |
35 | 35 | ||
36 | SmtpClient::~SmtpClient() | 36 | SmtpClient::~SmtpClient() |
37 | { | 37 | { |
38 | delete socket; | 38 | delete socket; |
39 | delete stream; | 39 | delete stream; |
40 | } | 40 | } |
41 | 41 | ||
42 | void SmtpClient::newConnection(QString target, int port) | 42 | void SmtpClient::newConnection(QString target, int port) |
43 | { | 43 | { |
44 | if (sending) { | 44 | if (sending) { |
45 | qWarning("socket in use, connection refused"); | 45 | qWarning("socket in use, connection refused"); |
46 | return; | 46 | return; |
47 | } | 47 | } |
48 | 48 | ||
49 | status = Init; | 49 | status = Init; |
50 | sending = TRUE; | 50 | sending = TRUE; |
51 | socket->connectToHost(target, port); | 51 | socket->connectToHost(target, port); |
52 | 52 | ||
53 | emit updateStatus(tr("DNS lookup")); | 53 | emit updateStatus(tr("DNS lookup")); |
54 | } | 54 | } |
55 | 55 | ||
56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) | 56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) |
57 | { | 57 | { |
58 | RawEmail *mail = new RawEmail; | 58 | RawEmail *mail = new RawEmail; |
59 | 59 | ||
60 | mail->from = from; | 60 | mail->from = from; |
61 | mail->subject = subject; | 61 | mail->subject = subject; |
62 | mail->to = to; | 62 | mail->to = to; |
63 | mail->body = body; | 63 | mail->body = body; |
64 | 64 | ||
65 | mailList.append(mail); | 65 | mailList.append(mail); |
66 | } | 66 | } |
67 | 67 | ||
68 | void SmtpClient::connectionEstablished() | 68 | void SmtpClient::connectionEstablished() |
69 | { | 69 | { |
70 | emit updateStatus(tr("Connection established")); | 70 | emit updateStatus(tr("Connection established")); |
71 | 71 | ||
72 | } | 72 | } |
73 | 73 | ||
74 | void SmtpClient::errorHandling(int status) | 74 | void SmtpClient::errorHandling(int status) |
75 | { | 75 | { |
76 | emit errorOccurred(status); | 76 | emit errorOccurred(status); |
77 | socket->close(); | 77 | socket->close(); |
78 | mailList.clear(); | 78 | mailList.clear(); |
79 | sending = FALSE; | 79 | sending = FALSE; |
80 | } | 80 | } |
81 | 81 | ||
82 | void SmtpClient::incomingData() | 82 | void SmtpClient::incomingData() |
83 | { | 83 | { |
84 | QString response; | 84 | QString response; |
85 | 85 | ||
86 | if (!socket->canReadLine()) | 86 | if (!socket->canReadLine()) |
87 | return; | 87 | return; |
88 | 88 | ||
89 | response = socket->readLine(); | 89 | response = socket->readLine(); |
90 | 90 | qDebug(response); | |
91 | |||
91 | switch(status) { | 92 | switch(status) { |
92 | case Init: { | 93 | case Init: { |
93 | if (response[0] == '2') { | 94 | if (response[0] == '2') { |
94 | status = From; | 95 | status = From; |
95 | mailPtr = mailList.first(); | 96 | mailPtr = mailList.first(); |
96 | *stream << "HELO there\r\n"; | 97 | *stream << "HELO there\r\n"; |
98 | qDebug("HELO"); | ||
97 | } else errorHandling(ErrUnknownResponse); | 99 | } else errorHandling(ErrUnknownResponse); |
98 | break; | 100 | break; |
99 | } | 101 | } |
100 | case From: { | 102 | case From: { |
101 | if (response[0] == '2') { | 103 | if (response[0] == '2') { |
102 | *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; | 104 | *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; |
103 | status = Recv; | 105 | status = Recv; |
106 | qDebug("MAIL FROM: "+mailPtr->from); | ||
104 | } else errorHandling(ErrUnknownResponse); | 107 | } else errorHandling(ErrUnknownResponse); |
105 | break; | 108 | break; |
106 | } | 109 | } |
107 | case Recv: { | 110 | case Recv: { |
108 | if (response[0] == '2') { | 111 | if (response[0] == '2') { |
109 | it = mailPtr->to.begin(); | 112 | it = mailPtr->to.begin(); |
110 | if (it == NULL) | 113 | if (it == NULL) |
111 | errorHandling(ErrUnknownResponse); | 114 | errorHandling(ErrUnknownResponse); |
112 | *stream << "RCPT TO: <" << *it << ">\r\n"; | 115 | *stream << "RCPT TO: <" << *it << ">\r\n"; |
116 | qDebug("RCPT TO: "+ *it); | ||
113 | status = MRcv; | 117 | status = MRcv; |
114 | } else errorHandling(ErrUnknownResponse); | 118 | } else errorHandling(ErrUnknownResponse); |
115 | break; | 119 | break; |
116 | } | 120 | } |
117 | case MRcv: { | 121 | case MRcv: { |
118 | if (response[0] == '2') { | 122 | if (response[0] == '2') { |
119 | it++; | 123 | it++; |
120 | if ( it != mailPtr->to.end() ) { | 124 | if ( it != mailPtr->to.end() ) { |
121 | *stream << "RCPT TO: <" << *it << ">\r\n"; | 125 | *stream << "RCPT TO: <" << *it << ">\r\n"; |
126 | qDebug("RCPT TO: "+ *it); | ||
122 | break; | 127 | break; |
123 | } else { | 128 | } else { |
124 | status = Data; | 129 | status = Data; |
125 | } | 130 | } |
126 | } else errorHandling(ErrUnknownResponse); | 131 | } else errorHandling(ErrUnknownResponse); |
127 | } | 132 | } |
128 | case Data: { | 133 | case Data: { |
129 | if (response[0] == '2') { | 134 | if (response[0] == '2') { |
130 | *stream << "DATA\r\n"; | 135 | *stream << "DATA\r\n"; |
131 | status = Body; | 136 | status = Body; |
137 | qDebug("DATA"); | ||
132 | emit updateStatus(tr("Sending: ") + mailPtr->subject); | 138 | emit updateStatus(tr("Sending: ") + mailPtr->subject); |
133 | } else errorHandling(ErrUnknownResponse); | 139 | } else errorHandling(ErrUnknownResponse); |
134 | break; | 140 | break; |
135 | } | 141 | } |
136 | case Body: { | 142 | case Body: { |
137 | if (response[0] == '3') { | 143 | if (response[0] == '3') { |
138 | *stream << mailPtr->body << "\r\n.\r\n"; | 144 | *stream << mailPtr->body << "\r\n.\r\n"; |
139 | mailPtr = mailList.next(); | 145 | mailPtr = mailList.next(); |
140 | if (mailPtr != NULL) { | 146 | if (mailPtr != NULL) { |
141 | status = From; | 147 | status = From; |
142 | } else { | 148 | } else { |
143 | status = Quit; | 149 | status = Quit; |
144 | } | 150 | } |
151 | qDebug("BODY"); | ||
145 | } else errorHandling(ErrUnknownResponse); | 152 | } else errorHandling(ErrUnknownResponse); |
146 | break; | 153 | break; |
147 | } | 154 | } |
148 | case Quit: { | 155 | case Quit: { |
149 | if (response[0] == '2') { | 156 | if (response[0] == '2') { |
150 | *stream << "QUIT\r\n"; | 157 | *stream << "QUIT\r\n"; |
151 | status = Done; | 158 | status = Done; |
152 | QString temp; | 159 | QString temp; |
153 | temp.setNum(mailList.count()); | 160 | temp.setNum(mailList.count()); |
154 | emit updateStatus(tr("Sent ") + temp + tr(" messages")); | 161 | emit updateStatus(tr("Sent ") + temp + tr(" messages")); |
155 | emit mailSent(); | 162 | emit mailSent(); |
156 | mailList.clear(); | 163 | mailList.clear(); |
157 | sending = FALSE; | 164 | sending = FALSE; |
158 | socket->close(); | 165 | socket->close(); |
166 | qDebug("QUIT"); | ||
159 | } else errorHandling(ErrUnknownResponse); | 167 | } else errorHandling(ErrUnknownResponse); |
160 | break; | 168 | break; |
161 | } | 169 | } |
162 | } | 170 | } |
163 | } | 171 | } |