KIO
smtp.h
Go to the documentation of this file.
00001 /* 00002 Copyright (c) 2000 Bernd Johannes Wuebben <wuebben@math.cornell.edu> 00003 Copyright (c) 2000 Stephan Kulow <coolo@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2, or (at your option) 00008 any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 #ifndef SMTP_H 00020 #define SMTP_H 00021 00022 #include <QtCore/QObject> 00023 #include <QtCore/QTimer> 00024 #include <QtNetwork/QTcpSocket> 00025 #include <ksocketfactory.h> 00026 00027 /*int SMTPServerStatus[] = { 00028 220, // greeting from server 00029 221, // server acknolages goodbye 00030 250, // command successful 00031 354, // ready to receive data 00032 501, // error 00033 550, // user unknown 00034 0 // null 00035 }; 00036 00037 int SMTPClientStatus[] = { 00038 50, // not logged in yet. 00039 100, // logged in, got 220 00040 150, // sent helo, got 250 00041 200, // sent mail from, got 250 00042 250, // sent rctp to, got 250 00043 300, // data sent, got 354 00044 350, // sent data/., got 250 00045 400, // send quit, got 221 00046 450, // finished, logged out 00047 0 // null 00048 }; 00049 */ 00050 00051 #define DEFAULT_SMTP_PORT 25 00052 #define DEFAULT_SMTP_SERVER localhost 00053 #define DEFAULT_SMTP_TIMEOUT 60 00054 00055 #define SMTP_READ_BUFFER_SIZE 256 00056 00057 class SMTP:public QObject 00058 { 00059 Q_OBJECT 00060 public: 00061 explicit SMTP(char *serverhost = 0, unsigned short int port = 0, 00062 int timeout = DEFAULT_SMTP_TIMEOUT); 00063 ~SMTP(); 00064 00065 void setServerHost(const QString& serverhost); 00066 void setPort(unsigned short int port); 00067 void setTimeOut(int timeout); 00068 00069 bool isConnected(){return connected;} 00070 bool isFinished(){return finished;} 00071 QString getLastLine(){return lastLine;} 00072 00073 void setSenderAddress(const QString& sender); 00074 void setRecipientAddress(const QString& recipient); 00075 void setMessageSubject(const QString& subject); 00076 void setMessageBody(const QString& message); 00077 void setMessageHeader(const QString &header); 00078 00079 typedef enum { 00080 None = 0, // null 00081 Greet = 220, // greeting from server 00082 Goodbye = 221, // server acknolages quit 00083 Successful = 250, // command successful 00084 ReadyData = 354, // server ready to receive data 00085 Error = 501, // error 00086 Unknown = 550 // user unknown 00087 }SMTPServerStatus; 00088 00089 typedef enum { 00090 Init = 50, // not logged in yet 00091 In = 100, // logged in, got 220 00092 Ready = 150, // sent HELO, got 250 00093 SentFrom = 200, // sent MAIL FROM:, got 250 00094 SentTo = 250, // sent RCTP TO:, got 250 00095 Data = 300, // Data sent, got 354 00096 Finished = 350, // finished sending data, got 250 00097 Quit = 400, // sent Quit, got 221 00098 Out = 450, // finished, logged out 00099 CError = 500 // didn't finish, had error or connection drop 00100 }SMTPClientStatus; 00101 00102 typedef enum { 00103 NoError = 0, 00104 ConnectError = 10, 00105 NotConnected = 11, 00106 ConnectTimeout = 15, 00107 InteractTimeout = 16, 00108 UnknownResponse = 20, 00109 UnknownUser = 30, 00110 Command = 40 00111 }SMTPError; 00112 00113 protected: 00114 void processLine(QString *line); 00115 00116 public Q_SLOTS: 00117 void openConnection(); 00118 void sendMessage(); 00119 void closeConnection(); 00120 00121 void connectTimerTick(); 00122 void connectTimedOut(); 00123 void interactTimedOut(); 00124 00125 void socketReadyToRead(); 00126 void socketClosed(); 00127 void socketError(QAbstractSocket::SocketError); 00128 00129 Q_SIGNALS: 00130 void connectionClosed(); 00131 void messageSent(); 00132 void error(int); 00133 00134 private: 00135 QString serverHost; 00136 unsigned short int hostPort; 00137 int timeOut; 00138 00139 bool connected; 00140 bool finished; 00141 00142 QString senderAddress; 00143 QString recipientAddress; 00144 QString messageSubject; 00145 QString messageBody, messageHeader; 00146 00147 SMTPClientStatus state; 00148 SMTPClientStatus lastState; 00149 SMTPServerStatus serverState; 00150 00151 QString domainName; 00152 00153 QTcpSocket *sock; 00154 QTimer connectTimer; 00155 QTimer timeOutTimer; 00156 QTimer interactTimer; 00157 00158 char readBuffer[SMTP_READ_BUFFER_SIZE]; 00159 QString lineBuffer; 00160 QString lastLine; 00161 QString writeString; 00162 }; 00163 #endif
KDE 4.6 API Reference