pkg://icqmail-2.0a1.tar.gz:49734/
icqmail-2.0a1/
src/icqmail.hh
downloads
/*
* $id: icqmail.hh,v 1.8 2000/01/10 08:14:25 lord Exp $
*
* ICQMAIL Simple ICQ->EMail Gateway
* Vadim Zaliva <lord@crocodile.org>
* http://www.crocodile.org/
*
* Copyright (C) 1999 Vadim Zaliva
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef ICQMAIL_HH_FLAG
#define ICQMAIL_HH_FLAG
#include <map>
#include <icq.h>
#include "cfg.hh"
#include "log.hh"
/* mimelib */
#include <mimelib/mimepp.h>
#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 2048
#endif
class IcqMailException
{
public:
IcqMailException(const DwString &r)
{
reason=r;
}
DwString reason;
};
class IcqMailSmtpException: public IcqMailException
{
public:
int code;
IcqMailSmtpException(const DwString &r, int pcode):IcqMailException(r)
{
code=pcode;
}
};
class IcqMail
{
private:
// constans
static const int CONNECT_DELAY ; // pause between connect attempts.
static const int LOGIN_DELAY ; // seconds
static const int KEEP_ALIVE_DELAY ; // seconds
static const int MAXMACRONAME ; // max chars in macro name
static const char *DEFAULT_CFG_NAME ; // default cfg file name
static const char *ICQMAILCOPYRIGHT ; // copyright message
public:
IcqMail(int ac, char **av);
int run(void (*init_hooks)());
int getICQLogLevel();
typedef unsigned long uin_t;
class UinCompare
{
public:
bool operator()(const uin_t a, const uin_t b) const
{
return a<b;
}
};
typedef std::map<uin_t, unsigned int, UinCompare> MonitorList;
MonitorList monitorlist;
typedef enum
{
status_ch_online = 1,
status_ch_offline = 2,
status_ch_changed = 4
} status_change_type;
// Protocol callbacks
void IcqMail::ctrlc(int st);
void serverAck(unsigned short seq);
void doLog(time_t time, unsigned char level, const char *str);
void connectionLost();
void loginOK();
void processMessage(uin_t uin,
unsigned char hour,
unsigned char minute,
unsigned char day,
unsigned char month,
unsigned short year,
const char *msg);
void processURL(uin_t uin,
unsigned char hour,
unsigned char minute,
unsigned char day,
unsigned char month,
unsigned short year,
const char *url,
const char *descr);
void RespondAuthReq (uin_t uin,
unsigned char hour,
unsigned char minute,
unsigned char day,
unsigned char month,
unsigned short year,
const char *nick,
const char *first,
const char *last,
const char *email,
const char *reason);
void userOnline(uin_t uin, unsigned long status, unsigned long ip, unsigned long port, unsigned long real_ip);
void userOffline(uin_t uin);
void userStatusUpdate(uin_t uin, unsigned long status);
int IcqMail::call_script_procedure(const char *name, Cfg *data);
private:
void addRecipients(DwAddressList &lst, DwSmtpClient &smtp_client) throw(IcqMailException);
void addOneRecipient(DwMailbox *to, DwSmtpClient &smtp_client) throw(IcqMailException);
void quotePeriod(DwString &s);
void sendMessage(DwMessage *) throw(IcqMailException);
void IcqMail::login(unsigned long status,
uin_t uin,
const DwString pass);
int do_connect(const DwString &server, int port);
unsigned int str2uin(const DwString data, uin_t *res);
DwString uin2name (uin_t uin);
DwString uin2replyto (uin_t uin) throw(CfgNotFoundException);
void icqIP2str(unsigned long ip, char *res);
void IcqMail::emailStatusChange(uin_t uin,
status_change_type type,
unsigned long status,
unsigned long ip,
unsigned long port,
unsigned long real_ip
);
void IcqMail::sendEmail(uin_t uin,
const char *name,
const char *email,
int isurl,
int is_email_express,
const char *msg0);
int doICQProtocol();
bool watching(uin_t uin, int mask);
void add_to_monitor_list(uin_t uin, int mask);
int read_cfg_file(char *name);
int loadTemplates();
char *loadFile(const DwString &fname) const;
const char * substitute(const char *from,
char *to,
size_t bufsize,
const Cfg *resolver);
char *dup(const char *s);
int IcqMail::start_daemon();
bool IcqMail::isEmailExpress(const char *msg);
bool IcqMail::isContacts(const char *msg);
Cfg *cfg;
Cfg *aliases;
Log *log;
enum
{
NOT_YET,
RECONNECT,
EXIT
} done;
bool dodaemon ;
bool login_ok ;
int login_attempt ;
time_t last_ack ;
// cfg values
int icqloglevel;
int port;
DwString server;
uin_t uin;
DwString password;
DwString email;
DwString smtp_server;
DwString subject;
DwString returnsuffix;
DwString replymsg;
bool send_replymsg;
int status;
bool sendassubj;
int login_attempts;
const char *message_template ;
const char *contacts_template ;
const char *one_contact_template ;
const char *email_template ;
const char *offline_template ;
const char *online_template ;
const char *status_change_template ;
const char *url_template ;
DwString scriptfile ; /* hack */
bool call_scripts ;
};
#endif