~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kscd/smtp.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Kscd - A simple cd player for the KDE Project
 
3
 *
 
4
 * $Id: smtp.h,v 1.7 2001/03/11 15:33:54 dfoerste Exp $
 
5
 *
 
6
 * Copyright (c) 1997 Bernd Johannes wuebben@math.cornell.edu
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2, or (at your option)
 
11
 * any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 *
 
22
 */
 
23
 
 
24
#ifndef SMTP_H
 
25
#define SMTP_H
 
26
 
 
27
#include <qobject.h>
 
28
#include <qtimer.h>
 
29
#include <ksock.h>
 
30
 
 
31
/*int SMTPServerStatus[] = {
 
32
    220,  // greeting from server
 
33
    221,  // server acknolages goodbye
 
34
    250,  // command successful
 
35
    354,  // ready to recieve data
 
36
    501,  // error
 
37
    550,  // user unkown
 
38
    0     // null
 
39
};
 
40
 
 
41
int SMTPClientStatus[] = {
 
42
    50,   // not logged in yet.
 
43
    100,  // logged in, got 220
 
44
    150,  // sent helo, got 250
 
45
    200,  // sent mail from, got 250
 
46
    250,  // sent rctp to, got 250
 
47
    300,  // data sent, got 354
 
48
    350,  // sent data/., got 250
 
49
    400,  // send quit, got 221
 
50
    450,  // finished, logged out
 
51
    0     // null
 
52
};
 
53
*/
 
54
 
 
55
#define DEFAULT_SMTP_PORT 25
 
56
#define DEFAULT_SMTP_SERVER localhost
 
57
#define DEFAULT_SMTP_TIMEOUT 60
 
58
 
 
59
#define SMTP_READ_BUFFER_SIZE 256
 
60
 
 
61
class SMTP:public QObject
 
62
{
 
63
    Q_OBJECT
 
64
public:
 
65
    SMTP(char *serverhost = 0, unsigned short int port = 0, int timeout = DEFAULT_SMTP_TIMEOUT);
 
66
    ~SMTP();
 
67
    
 
68
    void setServerHost(const QString& serverhost);
 
69
    void setPort(unsigned short int port);
 
70
    void setTimeOut(int timeout);
 
71
    
 
72
    bool isConnected(){return connected;};
 
73
    bool isFinished(){return finished;};
 
74
    QString getLastLine(){return lastLine;};
 
75
    
 
76
    void setSenderAddress(const QString& sender);
 
77
    void setSenderReplyTo(const QString& replyto);
 
78
    void setRecipientAddress(const QString& recipient);
 
79
    void setMessageSubject(const QString& subject);
 
80
    void setMessageBody(const QString& message);
 
81
 
 
82
    typedef enum {
 
83
        NONE = 0,             // null
 
84
        GREET = 220,          // greeting from server
 
85
        GOODBYE = 221,        // server acknolages quit
 
86
        SUCCESSFUL = 250,     // command successful
 
87
        READYDATA = 354,      // server ready to recieve data
 
88
        ERROR = 501,          // error
 
89
        UNKNOWN = 550        // user unknown
 
90
    }SMTPServerStatus;
 
91
 
 
92
    typedef enum {
 
93
        INIT = 50,            // not logged in yet
 
94
        IN = 100,             // logged in, got 220
 
95
        READY = 150,          // sent HELO, got 250
 
96
        SENTFROM = 200,       // sent MAIL FROM:, got 250
 
97
        SENTTO = 250,         // sent RCTP TO:, got 250
 
98
        DATA = 300,           // DATA sent, got 354
 
99
        FINISHED = 350,       // finished sending data, got 250
 
100
        QUIT = 400,           // sent QUIT, got 221
 
101
        OUT = 450,            // finished, logged out
 
102
        CERROR = 500           // didn't finish, had error or connection drop
 
103
    }SMTPClientStatus;
 
104
 
 
105
    typedef enum {
 
106
        NOERROR = 0,
 
107
        CONNECTERROR = 10,
 
108
        NOTCONNECTED = 11,
 
109
        CONNECTTIMEOUT = 15,
 
110
        INTERACTTIMEOUT = 16,
 
111
        UNKNOWNRESPONSE = 20,
 
112
        UNKNOWNUSER = 30,
 
113
        COMMAND = 40
 
114
    }SMTPError;
 
115
 
 
116
protected:
 
117
    void processLine(QString *line);
 
118
 
 
119
public slots:
 
120
    void openConnection();
 
121
    void sendMessage();
 
122
    void closeConnection();
 
123
 
 
124
    void connectTimerTick();
 
125
    void connectTimedOut();
 
126
    void interactTimedOut();
 
127
 
 
128
    void socketRead(KSocket *);
 
129
    void socketClose(KSocket *);
 
130
 
 
131
signals:
 
132
    void connectionClosed();
 
133
    void messageSent();
 
134
    void error(int);
 
135
 
 
136
private:
 
137
    QString serverHost;
 
138
    unsigned short int hostPort;
 
139
    int timeOut;
 
140
 
 
141
    bool connected;
 
142
    bool finished;
 
143
    
 
144
    QString senderAddress;
 
145
    QString senderReplyTo;
 
146
    QString recipientAddress;
 
147
    QString messageSubject;
 
148
    QString messageBody;
 
149
 
 
150
    SMTPClientStatus state;
 
151
    SMTPClientStatus lastState;
 
152
    SMTPServerStatus serverState;
 
153
 
 
154
    QString domainName;
 
155
 
 
156
    KSocket *sock;
 
157
    QTimer connectTimer;
 
158
    QTimer timeOutTimer;
 
159
    QTimer interactTimer;
 
160
 
 
161
    char readBuffer[SMTP_READ_BUFFER_SIZE];
 
162
    QString lineBuffer;
 
163
    QString lastLine;
 
164
    QString writeString;
 
165
};
 
166
#endif