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