kio
smtp.h
Go to the documentation of this file.00001
00002
00003 #ifndef SMTP_H
00004 #define SMTP_H
00005
00006 #include <qobject.h>
00007 #include <qtimer.h>
00008 #include <ksock.h>
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #define DEFAULT_SMTP_PORT 25
00035 #define DEFAULT_SMTP_SERVER localhost
00036 #define DEFAULT_SMTP_TIMEOUT 60
00037
00038 #define SMTP_READ_BUFFER_SIZE 256
00039
00040 class SMTP:public QObject
00041 {
00042 Q_OBJECT
00043 public:
00044 SMTP(char *serverhost = 0, unsigned short int port = 0, int timeout = DEFAULT_SMTP_TIMEOUT);
00045 ~SMTP();
00046
00047 void setServerHost(const QString& serverhost);
00048 void setPort(unsigned short int port);
00049 void setTimeOut(int timeout);
00050
00051 bool isConnected(){return connected;};
00052 bool isFinished(){return finished;};
00053 QString getLastLine(){return lastLine;};
00054
00055 void setSenderAddress(const QString& sender);
00056 void setRecipientAddress(const QString& recipient);
00057 void setMessageSubject(const QString& subject);
00058 void setMessageBody(const QString& message);
00059 void setMessageHeader(const QString &header);
00060
00061 typedef enum {
00062 NONE = 0,
00063 GREET = 220,
00064 GOODBYE = 221,
00065 SUCCESSFUL = 250,
00066 READYDATA = 354,
00067 ERROR = 501,
00068 UNKNOWN = 550
00069 }SMTPServerStatus;
00070
00071 typedef enum {
00072 INIT = 50,
00073 IN = 100,
00074 READY = 150,
00075 SENTFROM = 200,
00076 SENTTO = 250,
00077 DATA = 300,
00078 FINISHED = 350,
00079 QUIT = 400,
00080 OUT = 450,
00081 CERROR = 500
00082 }SMTPClientStatus;
00083
00084 typedef enum {
00085 NOERROR = 0,
00086 CONNECTERROR = 10,
00087 NOTCONNECTED = 11,
00088 CONNECTTIMEOUT = 15,
00089 INTERACTTIMEOUT = 16,
00090 UNKNOWNRESPONSE = 20,
00091 UNKNOWNUSER = 30,
00092 COMMAND = 40
00093 }SMTPError;
00094
00095 protected:
00096 void processLine(QString *line);
00097
00098 public slots:
00099 void openConnection();
00100 void sendMessage();
00101 void closeConnection();
00102
00103 void connectTimerTick();
00104 void connectTimedOut();
00105 void interactTimedOut();
00106
00107 void socketRead(KSocket *);
00108 void socketClose(KSocket *);
00109
00110 signals:
00111 void connectionClosed();
00112 void messageSent();
00113 void error(int);
00114
00115 private:
00116 QString serverHost;
00117 unsigned short int hostPort;
00118 int timeOut;
00119
00120 bool connected;
00121 bool finished;
00122
00123 QString senderAddress;
00124 QString recipientAddress;
00125 QString messageSubject;
00126 QString messageBody, messageHeader;
00127
00128 SMTPClientStatus state;
00129 SMTPClientStatus lastState;
00130 SMTPServerStatus serverState;
00131
00132 QString domainName;
00133
00134 KSocket *sock;
00135 QTimer connectTimer;
00136 QTimer timeOutTimer;
00137 QTimer interactTimer;
00138
00139 char readBuffer[SMTP_READ_BUFFER_SIZE];
00140 QString lineBuffer;
00141 QString lastLine;
00142 QString writeString;
00143 };
00144 #endif