You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
3.7 KiB
145 lines
3.7 KiB
15 years ago
|
/* $Id$ */
|
||
|
|
||
|
#ifndef SMTP_H
|
||
|
#define SMTP_H
|
||
|
|
||
15 years ago
|
#include <tqobject.h>
|
||
|
#include <tqtimer.h>
|
||
15 years ago
|
#include <ksock.h>
|
||
|
|
||
14 years ago
|
/*int SMTPServerStatus[] = {
|
||
15 years ago
|
220, // greeting from server
|
||
|
221, // server acknolages goodbye
|
||
|
250, // command successful
|
||
|
354, // ready to receive data
|
||
|
501, // error
|
||
|
550, // user unknown
|
||
|
0 // null
|
||
|
};
|
||
|
|
||
14 years ago
|
int SMTPClientStatus[] = {
|
||
15 years ago
|
50, // not logged in yet.
|
||
|
100, // logged in, got 220
|
||
|
150, // sent helo, got 250
|
||
|
200, // sent mail from, got 250
|
||
|
250, // sent rctp to, got 250
|
||
|
300, // data sent, got 354
|
||
|
350, // sent data/., got 250
|
||
|
400, // send quit, got 221
|
||
|
450, // finished, logged out
|
||
|
0 // null
|
||
|
};
|
||
|
*/
|
||
|
|
||
|
#define DEFAULT_SMTP_PORT 25
|
||
|
#define DEFAULT_SMTP_SERVER localhost
|
||
|
#define DEFAULT_SMTP_TIMEOUT 60
|
||
|
|
||
|
#define SMTP_READ_BUFFER_SIZE 256
|
||
|
|
||
14 years ago
|
class SMTP:public QObject
|
||
15 years ago
|
{
|
||
|
Q_OBJECT
|
||
|
public:
|
||
|
SMTP(char *serverhost = 0, unsigned short int port = 0, int timeout = DEFAULT_SMTP_TIMEOUT);
|
||
|
~SMTP();
|
||
|
|
||
15 years ago
|
void setServerHost(const TQString& serverhost);
|
||
15 years ago
|
void setPort(unsigned short int port);
|
||
|
void setTimeOut(int timeout);
|
||
|
|
||
|
bool isConnected(){return connected;};
|
||
|
bool isFinished(){return finished;};
|
||
15 years ago
|
TQString getLastLine(){return lastLine;};
|
||
15 years ago
|
|
||
15 years ago
|
void setSenderAddress(const TQString& sender);
|
||
|
void setRecipientAddress(const TQString& recipient);
|
||
|
void setMessageSubject(const TQString& subject);
|
||
|
void setMessageBody(const TQString& message);
|
||
|
void setMessageHeader(const TQString &header);
|
||
15 years ago
|
|
||
|
typedef enum {
|
||
|
NONE = 0, // null
|
||
|
GREET = 220, // greeting from server
|
||
|
GOODBYE = 221, // server acknolages quit
|
||
|
SUCCESSFUL = 250, // command successful
|
||
|
READYDATA = 354, // server ready to receive data
|
||
|
ERROR = 501, // error
|
||
|
UNKNOWN = 550 // user unknown
|
||
14 years ago
|
}SMTPServerStatus;
|
||
15 years ago
|
|
||
|
typedef enum {
|
||
|
INIT = 50, // not logged in yet
|
||
|
IN = 100, // logged in, got 220
|
||
|
READY = 150, // sent HELO, got 250
|
||
|
SENTFROM = 200, // sent MAIL FROM:, got 250
|
||
|
SENTTO = 250, // sent RCTP TO:, got 250
|
||
|
DATA = 300, // DATA sent, got 354
|
||
|
FINISHED = 350, // finished sending data, got 250
|
||
|
QUIT = 400, // sent QUIT, got 221
|
||
|
OUT = 450, // finished, logged out
|
||
|
CERROR = 500 // didn't finish, had error or connection drop
|
||
14 years ago
|
}SMTPClientStatus;
|
||
15 years ago
|
|
||
|
typedef enum {
|
||
|
NOERROR = 0,
|
||
|
CONNECTERROR = 10,
|
||
|
NOTCONNECTED = 11,
|
||
|
CONNECTTIMEOUT = 15,
|
||
|
INTERACTTIMEOUT = 16,
|
||
|
UNKNOWNRESPONSE = 20,
|
||
|
UNKNOWNUSER = 30,
|
||
|
COMMAND = 40
|
||
|
}SMTPError;
|
||
|
|
||
|
protected:
|
||
15 years ago
|
void processLine(TQString *line);
|
||
15 years ago
|
|
||
|
public slots:
|
||
|
void openConnection();
|
||
|
void sendMessage();
|
||
|
void closeConnection();
|
||
|
|
||
|
void connectTimerTick();
|
||
|
void connectTimedOut();
|
||
|
void interactTimedOut();
|
||
|
|
||
12 years ago
|
void socketRead(TDESocket *);
|
||
|
void socketClose(TDESocket *);
|
||
15 years ago
|
|
||
|
signals:
|
||
|
void connectionClosed();
|
||
|
void messageSent();
|
||
|
void error(int);
|
||
|
|
||
|
private:
|
||
15 years ago
|
TQString serverHost;
|
||
15 years ago
|
unsigned short int hostPort;
|
||
|
int timeOut;
|
||
|
|
||
|
bool connected;
|
||
|
bool finished;
|
||
|
|
||
15 years ago
|
TQString senderAddress;
|
||
|
TQString recipientAddress;
|
||
|
TQString messageSubject;
|
||
|
TQString messageBody, messageHeader;
|
||
15 years ago
|
|
||
14 years ago
|
SMTPClientStatus state;
|
||
|
SMTPClientStatus lastState;
|
||
|
SMTPServerStatus serverState;
|
||
15 years ago
|
|
||
15 years ago
|
TQString domainName;
|
||
15 years ago
|
|
||
12 years ago
|
TDESocket *sock;
|
||
15 years ago
|
TQTimer connectTimer;
|
||
|
TQTimer timeOutTimer;
|
||
|
TQTimer interactTimer;
|
||
15 years ago
|
|
||
|
char readBuffer[SMTP_READ_BUFFER_SIZE];
|
||
15 years ago
|
TQString lineBuffer;
|
||
|
TQString lastLine;
|
||
|
TQString writeString;
|
||
15 years ago
|
};
|
||
|
#endif
|