author | llornkcor <llornkcor> | 2003-04-06 17:45:00 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-04-06 17:45:00 (UTC) |
commit | 70b1ff1a3f134d75d1539f269d52b34e6762684d (patch) (unidiff) | |
tree | 28c1b3d0c03e8c0188f014dfe094645d1ddfef5f /noncore/net/mailit/smtpclient.cpp | |
parent | 75e8f29020e267d1013a79839831035073b4eeae (diff) | |
download | opie-70b1ff1a3f134d75d1539f269d52b34e6762684d.zip opie-70b1ff1a3f134d75d1539f269d52b34e6762684d.tar.gz opie-70b1ff1a3f134d75d1539f269d52b34e6762684d.tar.bz2 |
move malit to head again, since it is working
Diffstat (limited to 'noncore/net/mailit/smtpclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/smtpclient.cpp | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/noncore/net/mailit/smtpclient.cpp b/noncore/net/mailit/smtpclient.cpp new file mode 100644 index 0000000..7bb7933 --- a/dev/null +++ b/noncore/net/mailit/smtpclient.cpp | |||
@@ -0,0 +1,163 @@ | |||
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 | |||
23 | SmtpClient::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 | |||
36 | SmtpClient::~SmtpClient() | ||
37 | { | ||
38 | delete socket; | ||
39 | delete stream; | ||
40 | } | ||
41 | |||
42 | void SmtpClient::newConnection(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("DNS lookup"); | ||
54 | } | ||
55 | |||
56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, 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 | |||
68 | void SmtpClient::connectionEstablished() | ||
69 | { | ||
70 | emit updateStatus("Connection established"); | ||
71 | |||
72 | } | ||
73 | |||
74 | void SmtpClient::errorHandling(int status) | ||
75 | { | ||
76 | emit errorOccurred(status); | ||
77 | socket->close(); | ||
78 | mailList.clear(); | ||
79 | sending = FALSE; | ||
80 | } | ||
81 | |||
82 | void SmtpClient::incomingData() | ||
83 | { | ||
84 | QString response; | ||
85 | |||
86 | if (!socket->canReadLine()) | ||
87 | return; | ||
88 | |||
89 | response = socket->readLine(); | ||
90 | |||
91 | switch(status) { | ||
92 | case Init: { | ||
93 | if (response[0] == '2') { | ||
94 | status = From; | ||
95 | mailPtr = mailList.first(); | ||
96 | *stream << "HELO there\r\n"; | ||
97 | } else errorHandling(ErrUnknownResponse); | ||
98 | break; | ||
99 | } | ||
100 | case From: { | ||
101 | if (response[0] == '2') { | ||
102 | *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; | ||
103 | status = Recv; | ||
104 | } else errorHandling(ErrUnknownResponse); | ||
105 | break; | ||
106 | } | ||
107 | case Recv: { | ||
108 | if (response[0] == '2') { | ||
109 | it = mailPtr->to.begin(); | ||
110 | if (it == NULL) | ||
111 | errorHandling(ErrUnknownResponse); | ||
112 | *stream << "RCPT TO: <" << *it << ">\r\n"; | ||
113 | status = MRcv; | ||
114 | } else errorHandling(ErrUnknownResponse); | ||
115 | break; | ||
116 | } | ||
117 | case MRcv: { | ||
118 | if (response[0] == '2') { | ||
119 | it++; | ||
120 | if ( it != mailPtr->to.end() ) { | ||
121 | *stream << "RCPT TO: <" << *it << ">\r\n"; | ||
122 | break; | ||
123 | } else { | ||
124 | status = Data; | ||
125 | } | ||
126 | } else errorHandling(ErrUnknownResponse); | ||
127 | } | ||
128 | case Data: { | ||
129 | if (response[0] == '2') { | ||
130 | *stream << "DATA\r\n"; | ||
131 | status = Body; | ||
132 | emit updateStatus("Sending: " + mailPtr->subject); | ||
133 | } else errorHandling(ErrUnknownResponse); | ||
134 | break; | ||
135 | } | ||
136 | case Body: { | ||
137 | if (response[0] == '3') { | ||
138 | *stream << mailPtr->body << "\r\n.\r\n"; | ||
139 | mailPtr = mailList.next(); | ||
140 | if (mailPtr != NULL) { | ||
141 | status = From; | ||
142 | } else { | ||
143 | status = Quit; | ||
144 | } | ||
145 | } else errorHandling(ErrUnknownResponse); | ||
146 | break; | ||
147 | } | ||
148 | case Quit: { | ||
149 | if (response[0] == '2') { | ||
150 | *stream << "QUIT\r\n"; | ||
151 | status = Done; | ||
152 | QString temp; | ||
153 | temp.setNum(mailList.count()); | ||
154 | emit updateStatus("Sent " + temp + " messages"); | ||
155 | emit mailSent(); | ||
156 | mailList.clear(); | ||
157 | sending = FALSE; | ||
158 | socket->close(); | ||
159 | } else errorHandling(ErrUnknownResponse); | ||
160 | break; | ||
161 | } | ||
162 | } | ||
163 | } | ||