KIO
smtp.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
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,
00081 Greet = 220,
00082 Goodbye = 221,
00083 Successful = 250,
00084 ReadyData = 354,
00085 Error = 501,
00086 Unknown = 550
00087 }SMTPServerStatus;
00088
00089 typedef enum {
00090 Init = 50,
00091 In = 100,
00092 Ready = 150,
00093 SentFrom = 200,
00094 SentTo = 250,
00095 Data = 300,
00096 Finished = 350,
00097 Quit = 400,
00098 Out = 450,
00099 CError = 500
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