1999-04-06 15:34:39 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <automask.h>
|
2007-07-20 09:30:35 +00:00
|
|
|
|
#include <browfile.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
|
#include <defmask.h>
|
2000-10-03 13:45:12 +00:00
|
|
|
|
#include <dongle.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
|
#include <execp.h>
|
|
|
|
|
#include <expr.h>
|
|
|
|
|
#include <golem.h>
|
2007-04-19 15:31:42 +00:00
|
|
|
|
#include <netsock.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
|
#include <recarray.h>
|
2008-03-21 16:40:17 +00:00
|
|
|
|
#include <relation.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
|
#include <sheet.h>
|
2011-01-26 09:22:41 +00:00
|
|
|
|
#include <tabmod.h>
|
2007-07-20 09:30:35 +00:00
|
|
|
|
#include <tabutil.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
|
#include <utility.h>
|
2000-10-03 13:45:12 +00:00
|
|
|
|
#include <viswin.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
#include "ba7.h"
|
|
|
|
|
#include "ba7100a.h"
|
2000-10-03 13:45:12 +00:00
|
|
|
|
#define NOT_TRANS -883
|
|
|
|
|
#define NOT_GEST -884
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TConfig utilities
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2007-07-20 09:30:35 +00:00
|
|
|
|
const TString& set_ini_var(int cfg, const char* para, const char* var, const char* val)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
TConfig ini(cfg, para);
|
2007-04-19 15:31:42 +00:00
|
|
|
|
const TString& prev = ini.get(var);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
if (val != NULL)
|
|
|
|
|
ini.set(var, val);
|
2007-05-10 13:58:42 +00:00
|
|
|
|
if (prev.blank())
|
|
|
|
|
return EMPTY_STRING;
|
|
|
|
|
TString& tmp = get_tmp_string();
|
|
|
|
|
tmp = prev;
|
|
|
|
|
return tmp;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
inline const TString& get_ini_var(int cfg, const char* para, const char* var)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{ return set_ini_var(cfg, para, var, NULL); }
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TMail_box
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TMail_box : public TSocketClient
|
|
|
|
|
{
|
|
|
|
|
unsigned long _connection;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool default_params(TString& server, TString& user,TString& password);
|
|
|
|
|
|
|
|
|
|
bool logon(const char* server = NULL,
|
|
|
|
|
const char* usr = NULL, const char* pwd = NULL);
|
|
|
|
|
virtual bool ok() const { return _connection != NULL; }
|
|
|
|
|
|
|
|
|
|
bool list(TString_array& a);
|
|
|
|
|
int get(TMail_messages& m);
|
|
|
|
|
bool remove(const char* id);
|
|
|
|
|
|
|
|
|
|
void logoff();
|
|
|
|
|
|
|
|
|
|
TMail_box();
|
|
|
|
|
~TMail_box();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TMail_box::default_params(TString& server, TString& user,TString& password)
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
bool ok = true;
|
|
|
|
|
if (server.blank())
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
server = get_ini_var(CONFIG_INSTALL, "Server", "POP3");
|
|
|
|
|
if (server.empty())
|
2007-04-19 15:31:42 +00:00
|
|
|
|
ok = false;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (user.blank())
|
1999-04-06 15:34:39 +00:00
|
|
|
|
user = ::user();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (password.blank())
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
1999-05-24 13:34:11 +00:00
|
|
|
|
const TString& pwd = cache().get(LF_USER, user).get("PASSWORD");
|
|
|
|
|
password = ::decode(pwd);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMail_box::logon(const char* ser, const char* usr, const char* pwd)
|
|
|
|
|
{
|
|
|
|
|
if (_connection)
|
|
|
|
|
logoff();
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
if (!IsOk())
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return error_box(TR("Impossibile inizializzare il client POP3"));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
TString server(ser);
|
|
|
|
|
TString user(usr);
|
|
|
|
|
TString password(pwd);
|
|
|
|
|
if (!default_params(server, user, password))
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return error_box(TR("E' necessario specificare un server POP3, un utente ed una password"));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
_connection = QueryConnection("110", server);
|
|
|
|
|
if (_connection != 0)
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
TString buf, req;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
ReadLine(_connection, buf);
|
|
|
|
|
if (buf[0] != '+')
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return error_box(FR("Il server POP3 %s non risponde\nRisultato : %s"),
|
2000-10-03 13:45:12 +00:00
|
|
|
|
(const char*)server, (const char *)buf);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
buf = "USER "; buf << user << "\r\n";
|
1999-04-06 15:34:39 +00:00
|
|
|
|
WriteLine(_connection, buf);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
req = buf;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
ReadLine(_connection, buf);
|
|
|
|
|
if (buf[0] != '+')
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return error_box(FR("Il server POP3 %s non accetta l'utente %s\nRichiesta : %sRisultato : %s"),
|
2000-10-03 13:45:12 +00:00
|
|
|
|
(const char*)server, (const char*)user, (const char *) req, (const char *)buf);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
buf = "PASS "; buf << password << "\r\n";
|
1999-04-06 15:34:39 +00:00
|
|
|
|
WriteLine(_connection, buf);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
req = buf;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
ReadLine(_connection, buf);
|
|
|
|
|
if (buf[0] != '+')
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return error_box(FR("Il server POP3 %s non accetta la password dell'utente %s\nRichiesta : %sRisultato : %s"),
|
2000-10-03 13:45:12 +00:00
|
|
|
|
(const char*)server, (const char*)user, (const char *) req, (const char *)buf);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return error_box(FR("Impossibile contattare il server POP3 %s"),
|
1999-04-06 15:34:39 +00:00
|
|
|
|
(const char*)server);
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return true;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMail_box::logoff()
|
|
|
|
|
{
|
|
|
|
|
if (_connection)
|
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
WriteLine(_connection, "QUIT\r\n");
|
1999-04-06 15:34:39 +00:00
|
|
|
|
RemoveConnection(_connection);
|
|
|
|
|
_connection = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMail_box::list(TString_array& a)
|
|
|
|
|
{
|
|
|
|
|
bool ok = _connection != NULL;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
TString buf;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
buf = "LIST\r\n";
|
1999-04-06 15:34:39 +00:00
|
|
|
|
WriteLine(_connection, buf);
|
|
|
|
|
ReadLine(_connection, buf);
|
|
|
|
|
ok = buf[0] == '+';
|
|
|
|
|
while (ok)
|
|
|
|
|
{
|
|
|
|
|
if (!ReadLine(_connection, buf))
|
|
|
|
|
break; // Unexpected EOF
|
|
|
|
|
if (buf[0] == '.')
|
|
|
|
|
break;
|
|
|
|
|
int pos = buf.find(' ');
|
|
|
|
|
if (pos > 0)
|
|
|
|
|
buf.cut(pos);
|
|
|
|
|
a.add(buf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HIDDEN int str2month(const char* str)
|
|
|
|
|
{
|
|
|
|
|
const char* const mese[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
|
|
|
|
int m;
|
|
|
|
|
for (m = 11; m > 0; m--)
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (xvt_str_compare_ignoring_case(str, mese[m]) == 0)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return m+1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-05 15:25:49 +00:00
|
|
|
|
enum EncodingType { enc_plain_text, enc_quoted_printable, enc_base64 };
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
int TMail_box::get(TMail_messages& m)
|
|
|
|
|
{
|
|
|
|
|
// Lista dei caratteri validi
|
2007-07-20 09:30:35 +00:00
|
|
|
|
const char* const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+*";
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
// Lista per decodifica dei caratteri validi
|
|
|
|
|
char Deco64[256];
|
2007-07-20 09:30:35 +00:00
|
|
|
|
memset(Deco64, ' ', sizeof(Deco64));
|
2000-05-05 15:25:49 +00:00
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
for (int i = 0; Base64[i]; i++)
|
|
|
|
|
Deco64[Base64[i]] = i;
|
|
|
|
|
TString_array a;
|
|
|
|
|
list(a);
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TString buf, boundary, msg_line;
|
|
|
|
|
|
|
|
|
|
m.destroy();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
FOR_EACH_ARRAY_ROW(a, r, row)
|
|
|
|
|
{
|
|
|
|
|
TMail_message* msgptr = new TMail_message(user());
|
|
|
|
|
m.add(msgptr);
|
|
|
|
|
TMail_message& msg = *msgptr;
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
buf = "RETR "; buf << *row << "\r\n";
|
1999-04-06 15:34:39 +00:00
|
|
|
|
WriteLine(_connection, buf);
|
|
|
|
|
ReadLine(_connection, buf);
|
|
|
|
|
bool ok = buf[0] == '+';
|
2000-05-05 15:25:49 +00:00
|
|
|
|
EncodingType encoding = enc_plain_text;
|
2007-04-19 15:31:42 +00:00
|
|
|
|
bool in_body = false;
|
|
|
|
|
bool in_section = false;
|
|
|
|
|
bool buf_already_read = false;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
boundary.cut(0);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
while (ok)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (!buf_already_read)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (!ReadLine(_connection, buf))
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
ok = false;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
break; // Unexpected EOF
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
else
|
2007-04-19 15:31:42 +00:00
|
|
|
|
buf_already_read = false;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
if (buf[0] == '.')
|
|
|
|
|
{
|
|
|
|
|
buf.ltrim(1);
|
|
|
|
|
if (buf.blank())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (in_body)
|
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (buf[0] == '-' && boundary.not_empty() && buf.find(boundary) >= 0)
|
|
|
|
|
break; // Ignora sezioni di attachment
|
|
|
|
|
|
|
|
|
|
switch (encoding)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
case enc_base64:
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
unsigned val = 0;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
int bits = 0;
|
|
|
|
|
msg_line.cut(0);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
for (const char* s = buf; *s && *s != '='; s++)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (*s==0x0A || *s==0x0D || *s==0x20 || *s==0x09)
|
|
|
|
|
continue; // Salta eventuali blanks
|
|
|
|
|
val <<= 6;
|
|
|
|
|
val |= Deco64[*s];
|
|
|
|
|
bits += 6;
|
|
|
|
|
if (bits >= 8)
|
|
|
|
|
{
|
|
|
|
|
const char c = char((val >> (bits - 8)) & 0xFF);
|
2001-04-30 14:22:43 +00:00
|
|
|
|
msg_line << c;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
bits -= 8;
|
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
msg.add_line(msg_line);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
2000-05-05 15:25:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case enc_quoted_printable:
|
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
msg_line.cut(0);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
for (const char* s = buf; *s; s++)
|
|
|
|
|
{
|
|
|
|
|
if (*s == '=')
|
|
|
|
|
{
|
|
|
|
|
s++;
|
|
|
|
|
if (*s >= ' ')
|
|
|
|
|
{
|
|
|
|
|
int c; sscanf(s, "%2X", &c);
|
2001-04-30 14:22:43 +00:00
|
|
|
|
msg_line << char(c);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
s++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2001-04-30 14:22:43 +00:00
|
|
|
|
msg_line << *s;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
msg.add_line(msg_line);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
buf.rtrim();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
msg.add_line(buf);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (boundary.not_empty())
|
|
|
|
|
{
|
|
|
|
|
if (buf.blank())
|
|
|
|
|
{
|
|
|
|
|
in_body = in_section;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (buf.find(boundary) >= 0)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
in_section = true;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (buf.blank())
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
in_body = true;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (buf.compare("From:", 5, true) == 0)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
buf.ltrim(6); buf.trim();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
msg.set_sender(buf);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (buf.compare("To:", 3, true) == 0)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
buf.ltrim(4); buf.trim();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
msg.add_recipient(buf);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (buf.compare("Cc:", 3, true) == 0)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
buf.ltrim(4); buf.trim();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
msg.add_copy_recipient(buf);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (buf.compare("Subject:", 8, true) == 0)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
buf.ltrim(9); buf.trim();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
msg.set_subject(buf);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (buf.compare("Date:", 5, true) == 0)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
TToken_string d(buf.mid(6), ' '); d.trim();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
int giorno = d.get_int(1);
|
|
|
|
|
int mese = str2month(d.get());
|
|
|
|
|
int anno = d.get_int();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (anno < 100) anno += 2000;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
TString16 ora = d.get();
|
|
|
|
|
buf.cut(0);
|
|
|
|
|
buf << anno << '/' << mese << '/' << giorno << ' ' << ora;
|
|
|
|
|
msg.set_date_time(buf);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (buf.compare("Content-Transfer-Encoding:", 26, true) == 0)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (buf.find("base64") > 0)
|
|
|
|
|
encoding = enc_base64; else
|
|
|
|
|
if (buf.find("quoted-printable") > 0)
|
|
|
|
|
encoding = enc_quoted_printable;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (buf.compare("Content-Type:", 13, true) == 0)
|
2000-05-05 15:25:49 +00:00
|
|
|
|
{
|
|
|
|
|
int bnd = buf.find("oundary="); // Funziona per Boundary e boundary
|
|
|
|
|
if (bnd < 0)
|
|
|
|
|
{
|
|
|
|
|
ReadLine(_connection, buf);
|
|
|
|
|
bnd = buf.find("oundary=");
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (bnd < 0)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
buf_already_read = true;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
}
|
|
|
|
|
if (bnd > 0)
|
|
|
|
|
{
|
|
|
|
|
const int apicia = buf.find('"', bnd);
|
|
|
|
|
const int apicic = buf.find('"', apicia+1);
|
|
|
|
|
if (apicia > 0 && apicic > apicia)
|
|
|
|
|
boundary = buf.sub(apicia+1, apicic);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return m.items();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMail_box::remove(const char* id)
|
|
|
|
|
{
|
|
|
|
|
bool ok = _connection != NULL;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
TString buf;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
buf << "DELE " << id << "\r\n";
|
1999-04-06 15:34:39 +00:00
|
|
|
|
WriteLine(_connection, buf);
|
|
|
|
|
ReadLine(_connection, buf);
|
|
|
|
|
ok = buf[0] == '+';
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMail_box::TMail_box() : _connection(NULL)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMail_box::~TMail_box()
|
|
|
|
|
{
|
|
|
|
|
logoff();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TFilter_expr
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TFilter_expr : public TExpression
|
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TAutomask& _mask;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual bool print_error(const char* msg) const;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TFilter_expr(TAutomask& m, int logicnum, const char* expr);
|
|
|
|
|
virtual ~TFilter_expr() { }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TFilter_expr::print_error(const char* msg) const
|
|
|
|
|
{
|
|
|
|
|
return _mask.error_box(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TFilter_expr::TFilter_expr(TAutomask& m, int logicnum, const char* expr)
|
|
|
|
|
: _mask(m)
|
|
|
|
|
{
|
|
|
|
|
bool ok = set(expr, _strexpr);
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
if (logicnum < LF_USER || logicnum >= prefix().items())
|
2002-12-20 16:15:03 +00:00
|
|
|
|
logicnum = LF_TABCOM; // Niente errori fatali, se possibile
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
const TRectype rec(logicnum);
|
2008-03-21 16:40:17 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numvar(); i++)
|
|
|
|
|
{
|
|
|
|
|
const TFixed_string name(varname(i));
|
|
|
|
|
int num = logicnum;
|
|
|
|
|
bool ok = rec.exist(name);
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
const TFieldref f(name, 0);
|
|
|
|
|
int num = table2logic(f.id());
|
|
|
|
|
const TRectype join(num);
|
|
|
|
|
ok = join.exist(f.name());
|
|
|
|
|
}
|
|
|
|
|
if (!ok)
|
2008-04-07 11:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
_error = 883;
|
|
|
|
|
TString msg;
|
|
|
|
|
msg.format(FR("Il campo %s non appartiene al file %d"), varname(i), logicnum);
|
|
|
|
|
print_error(msg);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TMailer_mask
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TMailer_mask : public TAutomask
|
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
long _timer_id;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
long _secs;
|
2008-02-28 10:46:40 +00:00
|
|
|
|
long _interval;
|
1999-05-24 13:34:11 +00:00
|
|
|
|
int _mail_semaphore;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TMail_messages _box;
|
2002-09-13 14:06:05 +00:00
|
|
|
|
bool _sequential;
|
2009-09-30 14:56:48 +00:00
|
|
|
|
clock_t _last_use;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
2002-12-20 16:15:03 +00:00
|
|
|
|
TString_array _key1; // Elenco dei campi della chiave principale dei files
|
|
|
|
|
TAssoc_array _apps; // Elenco delle applicazioni per processare i files
|
1999-05-24 13:34:11 +00:00
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
protected:
|
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2009-10-20 15:23:26 +00:00
|
|
|
|
virtual long handler(WINDOW win, EVENT* ep);
|
2011-09-09 11:10:24 +00:00
|
|
|
|
void log(const char* text);
|
|
|
|
|
|
1999-05-24 13:34:11 +00:00
|
|
|
|
protected:
|
1999-04-06 15:34:39 +00:00
|
|
|
|
bool file2app(const TString& file, TString& app) const;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
void expand_tabs(TMail_message& str, const int tab = 8) const;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
void save_sheet(TConfig& ini, short dlg, const char* var) const;
|
|
|
|
|
void load_sheet(TConfig& ini, short dlg, const char* var);
|
|
|
|
|
|
2002-12-20 16:15:03 +00:00
|
|
|
|
TToken_string& get_key1(int lf) const;
|
2009-09-30 14:56:48 +00:00
|
|
|
|
bool build_key1(int lf, const TString& body, TToken_string& key, TString& action) const;
|
|
|
|
|
bool build_key1(const TMail_message& msg, TToken_string& key, TString& action) const;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
void find_redundant_messages();
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
void track(const TMail_message& msg, const TString& app, const TString& action, int err);
|
2008-05-22 11:34:38 +00:00
|
|
|
|
bool exec_app(int & err, const TString& appname, TMail_message & msg, TToken_string & sh_row);
|
2007-07-20 09:30:35 +00:00
|
|
|
|
void scan_dir(const TFilename& dir, TMail_messages& box) const;
|
2009-09-30 14:56:48 +00:00
|
|
|
|
bool unattended() const;
|
2007-04-19 15:31:42 +00:00
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
public:
|
|
|
|
|
void test_delete();
|
2008-03-20 09:25:41 +00:00
|
|
|
|
void fill_messages();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
bool save_sheet_line(int& err, int line = -1);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
void save_all_lines();
|
2011-09-09 11:10:24 +00:00
|
|
|
|
void exec_scripts();
|
1999-05-24 13:34:11 +00:00
|
|
|
|
void auto_save_all();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
void save() const;
|
|
|
|
|
void load();
|
|
|
|
|
|
|
|
|
|
TMailer_mask();
|
|
|
|
|
virtual ~TMailer_mask();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void TMailer_mask::test_delete()
|
|
|
|
|
{
|
2008-03-20 09:25:41 +00:00
|
|
|
|
if (_mail_semaphore != 0)
|
|
|
|
|
return;
|
|
|
|
|
_mail_semaphore = 1;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
TWait_cursor hourglass;
|
1999-05-24 13:34:11 +00:00
|
|
|
|
|
2007-07-20 09:30:35 +00:00
|
|
|
|
xvtil_statbar_set(TR("Eliminazione messaggi..."));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
do_events();
|
|
|
|
|
|
2007-07-20 09:30:35 +00:00
|
|
|
|
TSheet_field& sf = sfield(F_MESSAGES);
|
|
|
|
|
const int sender_pos = sf.cid2index(F_SENDER);
|
|
|
|
|
const int mailer_pos = sf.cid2index(F_MAILER);
|
|
|
|
|
const int msgid_pos = sf.cid2index(F_ID);
|
2007-04-19 15:31:42 +00:00
|
|
|
|
TString4 mailer;
|
2007-07-20 09:30:35 +00:00
|
|
|
|
TString id;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
TMail_messages mapidel; // Lista dei messaggi MAPI da cancellare
|
|
|
|
|
|
|
|
|
|
TMail_box mailbox;
|
|
|
|
|
FOR_EACH_SHEET_ROW_BACK(sf, nrow, row) if (*row->get(0) == 'X')
|
|
|
|
|
{
|
2007-07-20 09:30:35 +00:00
|
|
|
|
row->get(mailer_pos, mailer);
|
|
|
|
|
row->get(msgid_pos, id);
|
|
|
|
|
bool deleted = false;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
if (mailer == "POP3")
|
|
|
|
|
{
|
|
|
|
|
if (!mailbox.ok())
|
|
|
|
|
{
|
|
|
|
|
if (!mailbox.logon(get(F_SERVER), get(F_USER), get(F_PASSWORD)))
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-07-20 09:30:35 +00:00
|
|
|
|
deleted = mailbox.remove(id);
|
|
|
|
|
}
|
2008-03-20 09:25:41 +00:00
|
|
|
|
else
|
|
|
|
|
if (mailer == "CNP")
|
|
|
|
|
{
|
|
|
|
|
TFilename file;
|
|
|
|
|
row->get(sender_pos, file); // Cartella di provenienza
|
|
|
|
|
file.add(id);
|
|
|
|
|
file.ext("ini");
|
2008-06-19 15:35:28 +00:00
|
|
|
|
file.fremove();
|
2008-04-02 10:37:51 +00:00
|
|
|
|
deleted = true;
|
2008-03-20 09:25:41 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (mailer == "MAPI")
|
|
|
|
|
{
|
|
|
|
|
TMail_message* msg = new TMail_message("");
|
|
|
|
|
msg->set_id(id);
|
|
|
|
|
mapidel.add(msg);
|
|
|
|
|
deleted = true;
|
|
|
|
|
}
|
2007-07-20 09:30:35 +00:00
|
|
|
|
if (deleted)
|
|
|
|
|
{
|
|
|
|
|
_box.destroy(nrow);
|
|
|
|
|
sf.destroy(nrow);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TString err = TR("Impossibile cancellare il messaggio");
|
|
|
|
|
err << ' ' << id;
|
|
|
|
|
xvtil_statbar_set(err);
|
|
|
|
|
do_events();
|
|
|
|
|
beep(2); // Error sound
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-20 09:30:35 +00:00
|
|
|
|
if (mailbox.ok())
|
|
|
|
|
mailbox.logoff();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
if (mapidel.items() > 0)
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
xvtil_statbar_set(TR("Eliminazione messaggi MAPI..."));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
do_events();
|
|
|
|
|
mapidel.remove();
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
xvtil_statbar_set(TR("Pronto"));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
do_events();
|
2008-03-20 09:25:41 +00:00
|
|
|
|
_mail_semaphore = 0;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
void TMailer_mask::expand_tabs(TMail_message& msg, const int tab) const
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
const int items = msg.items();
|
|
|
|
|
for (int n = 0; n < items; n++)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TString & str = msg.row(n);
|
|
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; str[i]; i++)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
switch(str[i])
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
case '\n':
|
|
|
|
|
case '\r':
|
|
|
|
|
start = i+1;
|
|
|
|
|
break;
|
|
|
|
|
case '\t':
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
const int t = tab - ((i-start) % tab) - 1;
|
|
|
|
|
str[i] = ' ';
|
|
|
|
|
if (t > 0)
|
|
|
|
|
{
|
|
|
|
|
TString80 spac; spac.spaces(t);
|
|
|
|
|
str.insert(spac, i+1);
|
|
|
|
|
i += t;
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-20 09:30:35 +00:00
|
|
|
|
void TMailer_mask::scan_dir(const TFilename& dir, TMail_messages& box) const
|
|
|
|
|
{
|
|
|
|
|
TString_array msg;
|
2008-06-19 15:35:28 +00:00
|
|
|
|
TFilename mask = dir;
|
2007-07-20 09:30:35 +00:00
|
|
|
|
mask.add("*.ini");
|
|
|
|
|
::list_files(mask, msg);
|
|
|
|
|
|
|
|
|
|
TString subject, text, strdata;
|
|
|
|
|
TToken_string id(_MAX_FNAME, '_');
|
|
|
|
|
FOR_EACH_ARRAY_ROW(msg, r, row)
|
|
|
|
|
{
|
|
|
|
|
const int size = fsize(*row);
|
2008-06-11 10:52:31 +00:00
|
|
|
|
if (size > 64 && size < 48*1024)
|
2007-07-20 09:30:35 +00:00
|
|
|
|
{
|
|
|
|
|
char* buffer = text.get_buffer(size);
|
|
|
|
|
TScanner scanner(*row);
|
2008-05-22 11:34:38 +00:00
|
|
|
|
|
|
|
|
|
memset(buffer, 0 , size);
|
2007-07-20 09:30:35 +00:00
|
|
|
|
scanner.read(buffer, size);
|
|
|
|
|
buffer[size] = '\0';
|
|
|
|
|
|
|
|
|
|
subject.cut(0);
|
|
|
|
|
int parc = text.find(']'); // fine primo paragrafo
|
|
|
|
|
if (parc > 0)
|
|
|
|
|
{
|
|
|
|
|
int para = text.find('[', parc+1);
|
|
|
|
|
if (para > 0)
|
|
|
|
|
{
|
|
|
|
|
parc = text.find(']', para+1);
|
|
|
|
|
if (parc > 0)
|
|
|
|
|
subject = text.sub(para+1, parc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (subject.full())
|
|
|
|
|
{
|
|
|
|
|
xvt_fsys_parse_pathname (*row, NULL, NULL, id.get_buffer(), NULL, NULL);
|
|
|
|
|
|
|
|
|
|
TMail_message* msg = new TMail_message(user(), subject, text, dir);
|
|
|
|
|
msg->set_id(id);
|
|
|
|
|
|
|
|
|
|
if (id.items() == 3) // Nome file in formato YYMMDD_HHMMSS_NN.ini
|
|
|
|
|
{
|
|
|
|
|
strdata = id.get(0); strdata.insert("20");
|
|
|
|
|
const TDate data(strdata);
|
|
|
|
|
const long hhmmss = id.get_long(1);
|
|
|
|
|
msg->set_date_time(data, hhmmss);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
msg->set_date_time(TDate(TODAY));
|
|
|
|
|
|
|
|
|
|
box.add(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-20 09:25:41 +00:00
|
|
|
|
void TMailer_mask::fill_messages()
|
|
|
|
|
{
|
|
|
|
|
if (_mail_semaphore != 0)
|
|
|
|
|
return;
|
|
|
|
|
_mail_semaphore = 1;
|
|
|
|
|
|
2009-09-30 14:56:48 +00:00
|
|
|
|
disable(DLG_DELREC);
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
TWait_cursor hourglass;
|
|
|
|
|
|
2007-07-20 09:30:35 +00:00
|
|
|
|
TFilename server(get(F_SERVER));
|
2008-06-19 15:35:28 +00:00
|
|
|
|
TString80 user(get(F_USER));
|
|
|
|
|
TString80 password(get(F_PASSWORD));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
TMail_box mailbox;
|
|
|
|
|
if (mailbox.default_params(server, user, password))
|
|
|
|
|
{
|
|
|
|
|
set(F_SERVER, server);
|
|
|
|
|
set(F_USER, user);
|
|
|
|
|
set(F_PASSWORD, password);
|
|
|
|
|
}
|
2008-06-19 15:35:28 +00:00
|
|
|
|
expand_sys_vars(server);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2007-07-20 09:30:35 +00:00
|
|
|
|
int totmapi = 0;
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
if (get_bool(F_MAPI))
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
xvtil_statbar_set(TR("Ricezione messaggi MAPI..."));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
do_events();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
totmapi = _box.get();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-20 09:30:35 +00:00
|
|
|
|
TString4 mailer;
|
|
|
|
|
if (isalpha(server[0]) && server[1] == ':' && is_slash(server[2]) && server.exist())
|
|
|
|
|
{
|
|
|
|
|
mailer = "CNP";
|
|
|
|
|
xvtil_statbar_set(TR("Ricezione messaggi CNP ..."));
|
|
|
|
|
do_events();
|
|
|
|
|
scan_dir(server, _box);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mailer = "POP3";
|
2011-09-09 11:10:24 +00:00
|
|
|
|
if (server.full())
|
|
|
|
|
{
|
|
|
|
|
xvtil_statbar_set(TR("Ricezione messaggi POP3..."));
|
|
|
|
|
do_events();
|
|
|
|
|
mailbox.logon(server, user, password);
|
|
|
|
|
mailbox.get(_box);
|
|
|
|
|
mailbox.logoff();
|
|
|
|
|
}
|
2007-07-20 09:30:35 +00:00
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
|
|
|
|
TSheet_field& sf = sfield(F_MESSAGES);
|
|
|
|
|
sf.destroy();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TString mess;
|
|
|
|
|
for (int m = 0; m < _box.items(); m++)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TMail_message& msg = _box.msg(m);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
TToken_string& row = sf.row(m);
|
|
|
|
|
row.add(msg.sender(), sf.cid2index(F_SENDER));
|
|
|
|
|
row.add(msg.date(), sf.cid2index(F_DATE));
|
|
|
|
|
const real t = msg.time();
|
|
|
|
|
row.add(t.string("@@:@@:@@"), sf.cid2index(F_TIME));
|
|
|
|
|
row.add(msg.subject(), sf.cid2index(F_SUBJECT));
|
|
|
|
|
expand_tabs(msg);
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
|
|
|
|
mess.cut(0);
|
|
|
|
|
FOR_EACH_ARRAY_ROW(msg, i, msgrow)
|
|
|
|
|
{
|
|
|
|
|
mess << *msgrow;
|
|
|
|
|
if (mess.len() >= 1024)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
{
|
|
|
|
|
mess.cut(1024);
|
2001-04-30 14:22:43 +00:00
|
|
|
|
break;
|
2007-04-19 15:31:42 +00:00
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
row.add(mess, sf.cid2index(F_BODY));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
if (m < totmapi)
|
|
|
|
|
{
|
|
|
|
|
row.add("MAPI", sf.cid2index(F_MAILER));
|
|
|
|
|
row.add(msg.id(), sf.cid2index(F_ID));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-07-20 09:30:35 +00:00
|
|
|
|
row.add(mailer, sf.cid2index(F_MAILER));
|
|
|
|
|
if (mailer == "CNP")
|
|
|
|
|
row.add(msg.id(), sf.cid2index(F_ID));
|
|
|
|
|
else
|
|
|
|
|
row.add(m-totmapi+1, sf.cid2index(F_ID));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sf.force_update();
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
xvtil_statbar_set(TR("Pronto"));
|
1999-05-24 13:34:11 +00:00
|
|
|
|
|
2008-03-20 09:25:41 +00:00
|
|
|
|
_mail_semaphore = 0;
|
|
|
|
|
return;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TMailer_mask::file2app(const TString& file, TString& app) const
|
2001-04-30 14:22:43 +00:00
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
bool ok = false;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
|
|
|
|
|
const TString* run = (const TString*)_apps.objptr(file);
|
|
|
|
|
if (run == NULL)
|
2002-07-29 15:19:18 +00:00
|
|
|
|
{
|
|
|
|
|
TString16 appname; appname << "Edit_" << file;
|
2011-01-26 09:22:41 +00:00
|
|
|
|
app = ini_get_string(CONFIG_DITTA, "ba7", appname);
|
2002-07-29 15:19:18 +00:00
|
|
|
|
if (app.empty())
|
2001-04-30 14:22:43 +00:00
|
|
|
|
{
|
2002-07-29 15:19:18 +00:00
|
|
|
|
if (isdigit(file[0]))
|
2001-04-30 14:22:43 +00:00
|
|
|
|
{
|
2002-07-29 15:19:18 +00:00
|
|
|
|
const int filenum = atoi(file);
|
|
|
|
|
if (filenum >= LF_USER && filenum < prefix().items())
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile isf(filenum);
|
|
|
|
|
ok = isf.get_relapp(app);
|
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
2002-07-29 15:19:18 +00:00
|
|
|
|
else
|
2001-04-30 14:22:43 +00:00
|
|
|
|
{
|
2002-07-29 15:19:18 +00:00
|
|
|
|
const int len = file.len();
|
|
|
|
|
if (len == 3 || (len == 4 && file[0] == '%'))
|
|
|
|
|
{
|
|
|
|
|
TTable table(file);
|
|
|
|
|
ok = table.get_relapp(app);
|
2011-01-26 09:22:41 +00:00
|
|
|
|
} else
|
|
|
|
|
if (len >= 4 && file[0] == '&')
|
|
|
|
|
{
|
|
|
|
|
TModule_table tabmod(file);
|
|
|
|
|
ok = tabmod.get_relapp(app);
|
2002-07-29 15:19:18 +00:00
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
2002-07-29 15:19:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-04-19 15:31:42 +00:00
|
|
|
|
ok = true;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
|
|
|
|
|
((TMailer_mask*)this)->_apps.add(file, app); // Fool const
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-12-20 16:15:03 +00:00
|
|
|
|
app = *run;
|
2006-12-13 16:22:33 +00:00
|
|
|
|
ok = app.full();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
bool is_incomplete(const TString& l)
|
|
|
|
|
{
|
|
|
|
|
if (l[0] == '[')
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
|
|
|
|
const char a = l.right(1)[0];
|
|
|
|
|
if (a == '=')
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return true;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
|
|
|
|
const int eq = l.find("= '");
|
|
|
|
|
if (eq > 0 && eq < 20)
|
|
|
|
|
return a != '\'';
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void adjust_long_lines(const TFilename& tmp)
|
|
|
|
|
{
|
|
|
|
|
TFilename dst_name; dst_name.temp();
|
|
|
|
|
ofstream dst(dst_name);
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
bool adjusted = false;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
|
|
|
|
TScanner org(tmp);
|
2007-04-19 15:31:42 +00:00
|
|
|
|
while (true)
|
2001-04-30 14:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
const TString& l = org.line();
|
|
|
|
|
if (l.empty())
|
|
|
|
|
break;
|
|
|
|
|
if (is_incomplete(l))
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
adjusted = true;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
dst << l;
|
|
|
|
|
org.line();
|
2001-06-25 10:41:20 +00:00
|
|
|
|
char s = l[0];
|
|
|
|
|
if (s == '\'' || s == '"')
|
2001-04-30 14:22:43 +00:00
|
|
|
|
{
|
2001-06-25 10:41:20 +00:00
|
|
|
|
char c = l.right(1)[0];
|
|
|
|
|
while (c != '\'' && c != '"')
|
|
|
|
|
{
|
|
|
|
|
dst << l;
|
|
|
|
|
org.line();
|
|
|
|
|
c = l.right(1)[0];
|
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
2001-06-25 10:41:20 +00:00
|
|
|
|
else
|
|
|
|
|
dst << '\n';
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
dst << l << '\n';
|
|
|
|
|
}
|
|
|
|
|
org.close();
|
|
|
|
|
dst.close();
|
|
|
|
|
if (adjusted)
|
|
|
|
|
fcopy(dst_name, tmp);
|
2008-06-19 15:35:28 +00:00
|
|
|
|
dst_name.fremove();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
void TMailer_mask::track(const TMail_message& msg, const TString& app, const TString& action, int err)
|
|
|
|
|
{
|
|
|
|
|
const TString& fname = get(F_TRACKING);
|
2009-09-30 14:56:48 +00:00
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (fname.full())
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
const char fldsep = '\t';
|
|
|
|
|
const char recsep = '\n';
|
|
|
|
|
|
|
|
|
|
ofstream log(fname, ios::app);
|
|
|
|
|
|
|
|
|
|
log << msg.sender() << fldsep;
|
|
|
|
|
|
|
|
|
|
log << msg.date() << fldsep;
|
|
|
|
|
const real t = msg.time();
|
|
|
|
|
log << t.string("@@:@@:@@") << fldsep;
|
|
|
|
|
|
2009-09-30 14:56:48 +00:00
|
|
|
|
TToken_string k1;
|
|
|
|
|
TString act;
|
|
|
|
|
build_key1(msg, k1, act);
|
2007-04-19 15:31:42 +00:00
|
|
|
|
log << k1.get(0) << fldsep;
|
|
|
|
|
|
|
|
|
|
const int pipe = k1.find(k1.separator());
|
|
|
|
|
k1.ltrim(pipe+1);
|
|
|
|
|
log << k1 << fldsep;
|
|
|
|
|
|
|
|
|
|
log << app << fldsep << action << fldsep << err << fldsep;
|
|
|
|
|
|
|
|
|
|
log << recsep;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
2008-05-22 11:34:38 +00:00
|
|
|
|
bool TMailer_mask::exec_app(int& err, const TString& appname, TMail_message& msg, TToken_string & sh_row)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
{
|
|
|
|
|
err = NOERR;
|
|
|
|
|
TString action;
|
|
|
|
|
if (appname.compare("sink", -1, true) == 0)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
FOR_EACH_ARRAY_ROW(msg, r, row)
|
|
|
|
|
{
|
|
|
|
|
int s = row->find("\nAction");
|
|
|
|
|
if (s > 0)
|
|
|
|
|
{
|
|
|
|
|
s = row->find('=', s);
|
|
|
|
|
const int e = row->find('\n', s);
|
|
|
|
|
action = row->sub(s+1, e);
|
|
|
|
|
action.trim();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TFilename tmp; tmp.temp();
|
|
|
|
|
{
|
|
|
|
|
ofstream outf(tmp);
|
|
|
|
|
const int items = msg.items();
|
|
|
|
|
bool long_lines = false;
|
|
|
|
|
TString message;
|
|
|
|
|
for (int i = 0; i < items; i++)
|
|
|
|
|
{
|
|
|
|
|
message = msg.row(i);
|
|
|
|
|
message.replace('\r', '\n');
|
|
|
|
|
outf << message;
|
|
|
|
|
}
|
|
|
|
|
outf.close();
|
|
|
|
|
adjust_long_lines(tmp);
|
|
|
|
|
|
|
|
|
|
TConfig ini(tmp, "Transaction");
|
|
|
|
|
ini.set("From", msg.sender());
|
|
|
|
|
action = ini.get("Action");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TString command_line(appname);
|
|
|
|
|
command_line << " /i" << tmp;
|
|
|
|
|
TExternal_app app(command_line);
|
2008-06-19 15:35:28 +00:00
|
|
|
|
err = app.run(false, true, false); // Don't iconize (nor restore) the task window!
|
2007-04-19 15:31:42 +00:00
|
|
|
|
xvt_sys_sleep(1000);
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
|
|
|
|
TConfig ini(tmp, "Transaction");
|
2008-06-19 15:35:28 +00:00
|
|
|
|
if (ini.get("Result").compare("OK", -1, true) == 0 ||
|
|
|
|
|
ini.get("Action").compare("RUN", -1, true) == 0)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
err = 0;
|
2008-07-21 11:23:24 +00:00
|
|
|
|
else
|
|
|
|
|
if (get_bool(F_DELCANCEL) && ini.get("Result").compare("Cancel", -1, true) == 0)
|
|
|
|
|
err = 0;
|
|
|
|
|
else
|
|
|
|
|
err = ini.get_int("Error");
|
2008-05-22 11:34:38 +00:00
|
|
|
|
|
2008-06-19 15:35:28 +00:00
|
|
|
|
TFilename backup = get(F_BACKUP);
|
|
|
|
|
expand_sys_vars(backup);
|
|
|
|
|
if (backup.exist())
|
2008-05-22 11:34:38 +00:00
|
|
|
|
{
|
2008-06-19 15:35:28 +00:00
|
|
|
|
const TSheet_field& sf = sfield(F_MESSAGES);
|
|
|
|
|
|
|
|
|
|
TString id;
|
2008-05-22 11:34:38 +00:00
|
|
|
|
TFilename file;
|
|
|
|
|
sh_row.get(sf.cid2index(F_ID), id);
|
|
|
|
|
sh_row.get(sf.cid2index(F_SENDER), file); // Cartella di provenienza
|
2008-06-19 15:35:28 +00:00
|
|
|
|
file.add(id);
|
2008-05-22 11:34:38 +00:00
|
|
|
|
file.ext("ini");
|
|
|
|
|
|
2008-06-19 15:35:28 +00:00
|
|
|
|
TFilename dest = backup;
|
|
|
|
|
dest.add(file.name());
|
|
|
|
|
fcopy(tmp, dest);
|
2008-05-22 11:34:38 +00:00
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
}
|
2008-06-19 15:35:28 +00:00
|
|
|
|
tmp.fremove();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
track(msg, appname, action, err);
|
|
|
|
|
|
|
|
|
|
return err == NOERR;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
bool TMailer_mask::save_sheet_line(int& err, int nrow)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
TSheet_field& sf = sfield(F_MESSAGES);
|
|
|
|
|
TMask& m = sf.sheet_mask();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
|
|
|
|
|
if (nrow < 0)
|
|
|
|
|
nrow = sf.selected();
|
|
|
|
|
else
|
|
|
|
|
sf.update_mask(nrow);
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
TToken_string& row = sf.row(nrow);
|
|
|
|
|
|
|
|
|
|
const TString& msg = m.get(F_BODY);
|
|
|
|
|
if (msg.find("[Transaction]") < 0)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
err = NOT_TRANS;
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false; // It's not a transaction
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TString subj = m.get(F_SUBJECT);
|
2009-11-04 12:04:45 +00:00
|
|
|
|
TIsam_handle logic = LF_TAB;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
if (isalpha(subj[0])) // Controlla se la tabella in realt<6C> <20> comune ed aggiunge il simbolino %
|
|
|
|
|
{
|
|
|
|
|
TString8 para; para << '[' << LF_TABCOM << ']';
|
|
|
|
|
if (msg.find(para) > 0)
|
|
|
|
|
subj.insert("%");
|
2009-11-04 12:04:45 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logic = atoi(subj);
|
|
|
|
|
if (logic == LF_TAB || logic == LF_TABCOM)
|
|
|
|
|
{
|
|
|
|
|
TString8 para; para << '[' << logic << ']';
|
|
|
|
|
int pos = msg.find(para);
|
|
|
|
|
if (pos > 0)
|
|
|
|
|
{
|
|
|
|
|
pos = msg.find("\nCOD", pos+3);
|
|
|
|
|
if (pos > 0)
|
|
|
|
|
{
|
|
|
|
|
TToken_string line(msg.mid(pos, 10), '=');
|
|
|
|
|
line.strip_spaces();
|
|
|
|
|
if (line.items() == 2)
|
|
|
|
|
{
|
|
|
|
|
subj = line.get(1);
|
|
|
|
|
if (logic == LF_TABCOM)
|
|
|
|
|
subj.insert("%");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
2009-11-04 12:04:45 +00:00
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
TFilename appname;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (!file2app(subj, appname)) // It hasn't a valid application
|
|
|
|
|
{
|
|
|
|
|
err = NOT_GEST;
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TMail_message& full_msg = _box.msg(nrow);
|
2008-05-22 11:34:38 +00:00
|
|
|
|
bool ok = exec_app(err, appname, full_msg, row);
|
2001-04-30 14:22:43 +00:00
|
|
|
|
if (!ok && err == _iskeynotfound)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
TString & first_row = full_msg.row(0);
|
|
|
|
|
int pos = first_row.find("MODIFY");
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (pos > 0)
|
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
first_row.overwrite("INSERT", pos);
|
2008-05-22 11:34:38 +00:00
|
|
|
|
ok = exec_app(err, appname, full_msg, row);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
if (m.is_running())
|
|
|
|
|
{
|
|
|
|
|
m.set(F_CHECKED, "X");
|
|
|
|
|
m.stop_run(K_AUTO_ENTER);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
row.add("X", 0);
|
|
|
|
|
sf.force_update(nrow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Restore mail recipient
|
2007-04-19 15:31:42 +00:00
|
|
|
|
// if (old_mailto.full())
|
2001-04-30 14:22:43 +00:00
|
|
|
|
// set_ini_var(CONFIG_INSTALL, "Main", "MailTo", old_mailto);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
return ok;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-12-20 16:15:03 +00:00
|
|
|
|
TToken_string& TMailer_mask::get_key1(int lf) const
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
TString_array& k = (TString_array&)_key1; // Fool constness
|
|
|
|
|
TToken_string* key = k.rowptr(lf);
|
|
|
|
|
if (key == NULL)
|
2002-12-20 16:15:03 +00:00
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
key = new TToken_string; // Creo una nuova entry
|
|
|
|
|
const RecDes& recd = prefix().get_recdes(lf); // Descrizione del record della testata
|
|
|
|
|
const KeyDes& kd = recd.Ky[0]; // Elenco dei campi della chiave 1
|
2002-12-20 16:15:03 +00:00
|
|
|
|
for (int i = 0; i < kd.NkFields; i++)
|
|
|
|
|
{
|
|
|
|
|
const int nf = kd.FieldSeq[i] % MaxFields;
|
2007-04-19 15:31:42 +00:00
|
|
|
|
const RecFieldDes& rf = recd.Fd[nf];
|
|
|
|
|
key->add(rf.Name);
|
2002-12-20 16:15:03 +00:00
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
k.add(key, lf);
|
2002-12-20 16:15:03 +00:00
|
|
|
|
}
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return *key;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-30 14:56:48 +00:00
|
|
|
|
bool TMailer_mask::build_key1(int lf, const TString& body, TToken_string& key, TString& action) const
|
2002-12-20 16:15:03 +00:00
|
|
|
|
{
|
|
|
|
|
key.format("%d", lf);
|
|
|
|
|
|
|
|
|
|
TString16 field; // Nome del campo chiave
|
|
|
|
|
TString value; // Valore del campo chiave
|
|
|
|
|
|
|
|
|
|
TToken_string& key1 = get_key1(lf); // Elenco dei campi chiave
|
|
|
|
|
FOR_EACH_TOKEN(key1, fld)
|
|
|
|
|
{
|
|
|
|
|
field = fld; field.insert("\n");
|
|
|
|
|
const int start = body.find(field);
|
|
|
|
|
if (start < 0)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
const int equal = body.find('=', start);
|
|
|
|
|
if (equal < 0)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
const int stop = body.find('\n', equal);
|
|
|
|
|
if (stop < 0)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
value = body.sub(equal+1, stop);
|
|
|
|
|
value.trim();
|
|
|
|
|
if (value[0] == '"' && value.right(1) == "\"") // Toglie eventuali virgolette
|
|
|
|
|
{
|
|
|
|
|
value.rtrim(1);
|
|
|
|
|
value.ltrim(1);
|
|
|
|
|
}
|
|
|
|
|
key.add(value);
|
|
|
|
|
}
|
2009-09-30 14:56:48 +00:00
|
|
|
|
|
|
|
|
|
const int act = body.find("\nAction");
|
2009-11-04 12:04:45 +00:00
|
|
|
|
const int ugu = act > 0 ? body.find('=', act) : -1;
|
|
|
|
|
const int nwl = ugu > 0 ? body.find('\n', ugu) : -1;
|
2009-09-30 14:56:48 +00:00
|
|
|
|
if (act > 0 && ugu > act && ugu < nwl)
|
|
|
|
|
{
|
|
|
|
|
action = body.sub(ugu+1,nwl);
|
|
|
|
|
action.trim();
|
|
|
|
|
action.upper();
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-30 14:56:48 +00:00
|
|
|
|
bool TMailer_mask::build_key1(const TMail_message& msg, TToken_string& key, TString& action) const
|
2007-04-19 15:31:42 +00:00
|
|
|
|
{
|
|
|
|
|
TString body;
|
|
|
|
|
FOR_EACH_ARRAY_ROW(msg, r, row)
|
|
|
|
|
body << *row << '\n';
|
|
|
|
|
|
|
|
|
|
const TString& subj = msg.subject();
|
|
|
|
|
int lfile = LF_TAB; // Numero logico del file
|
|
|
|
|
if (isalpha(subj[0])) // Controlla se la tabella in realt<6C> <20> comune ed aggiunge il simbolino %
|
|
|
|
|
{
|
|
|
|
|
TString4 para; para << '[' << LF_TABCOM << ']';
|
|
|
|
|
if (body.find(para) > 0)
|
|
|
|
|
lfile = LF_TABCOM;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
lfile = atoi(subj);
|
|
|
|
|
|
2009-09-30 14:56:48 +00:00
|
|
|
|
return build_key1(lfile, body, key, action);
|
2002-12-20 16:15:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMailer_mask::find_redundant_messages()
|
|
|
|
|
{
|
|
|
|
|
// Elenco dei records (chiavi primarie) gi<67> processati (virtualmente)
|
|
|
|
|
TAssoc_array andreotti;
|
|
|
|
|
|
|
|
|
|
TSheet_field& sf = sfield(F_MESSAGES);
|
2009-09-30 14:56:48 +00:00
|
|
|
|
TString subj, body, action;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
TToken_string key1;
|
|
|
|
|
|
|
|
|
|
// Scorro tutti i messaggi non ancora elaborati
|
2009-09-30 14:56:48 +00:00
|
|
|
|
FOR_EACH_SHEET_ROW_BACK(sf, nrow, row) if (row->get_char(0) != 'X')
|
2002-12-20 16:15:03 +00:00
|
|
|
|
{
|
|
|
|
|
row->get(sf.cid2index(F_BODY), body);
|
|
|
|
|
if (body.find("[Transaction]") < 0) // Scarto i messaggi che non siano transazioni
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
row->get(sf.cid2index(F_SUBJECT), subj);
|
|
|
|
|
|
|
|
|
|
int lfile = LF_TAB; // Numero logico del file
|
|
|
|
|
if (isalpha(subj[0])) // Controlla se la tabella in realt<6C> <20> comune ed aggiunge il simbolino %
|
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
TString4 para; para << '[' << LF_TABCOM << ']';
|
2002-12-20 16:15:03 +00:00
|
|
|
|
if (body.find(para) > 0)
|
|
|
|
|
lfile = LF_TABCOM;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
lfile = atoi(subj);
|
|
|
|
|
|
2009-09-30 14:56:48 +00:00
|
|
|
|
if (build_key1(lfile, body, key1, action))
|
2002-12-20 16:15:03 +00:00
|
|
|
|
{
|
2009-09-30 14:56:48 +00:00
|
|
|
|
if (andreotti.is_key(key1) && action != "INSERT") // Non considero ridondanti gli inserimenti!
|
2002-12-20 16:15:03 +00:00
|
|
|
|
row->add("R", 0); // Messaggio ridondante!
|
|
|
|
|
else
|
|
|
|
|
andreotti.add(key1); // Messaggio da processare!
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-09 11:10:24 +00:00
|
|
|
|
void TMailer_mask::log(const char* text)
|
|
|
|
|
{
|
|
|
|
|
TBrowsefile_field& bf = (TBrowsefile_field&)field(F_LOG);
|
|
|
|
|
TViswin& vv = bf.vis_win();
|
|
|
|
|
|
|
|
|
|
if (text && *text)
|
|
|
|
|
{
|
|
|
|
|
time_t tempo; time(&tempo);
|
|
|
|
|
const struct tm* d = localtime(&tempo);
|
|
|
|
|
TString256 msg;
|
|
|
|
|
msg.format("- %02d-%02d-%04d %02d:%02d:%02d %s",
|
|
|
|
|
d->tm_mday, d->tm_mon+1, 1900+d->tm_year,
|
|
|
|
|
d->tm_hour, d->tm_min, d->tm_sec,
|
|
|
|
|
text);
|
|
|
|
|
vv.add_line(msg);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vv.add_line("");
|
|
|
|
|
vv.goto_end();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
void TMailer_mask::save_all_lines()
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2008-03-20 09:25:41 +00:00
|
|
|
|
if (_mail_semaphore != 0)
|
|
|
|
|
return;
|
|
|
|
|
_mail_semaphore = 1;
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
TString msg;
|
2008-06-19 15:35:28 +00:00
|
|
|
|
|
2011-09-09 11:10:24 +00:00
|
|
|
|
log(TR("Inizio elaborazione"));
|
2002-12-20 16:15:03 +00:00
|
|
|
|
|
|
|
|
|
find_redundant_messages();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
bool one_saved = false;
|
|
|
|
|
TSheet_field& sf = sfield(F_MESSAGES);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
FOR_EACH_SHEET_ROW(sf, nrow, row)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
msg.format("Messaggio %d ", nrow+1);
|
2002-12-20 16:15:03 +00:00
|
|
|
|
const char mark = *row->get(0);
|
|
|
|
|
|
|
|
|
|
if (mark == 'X')
|
|
|
|
|
msg << "ignorato in quanto gi<67> elaborato";
|
|
|
|
|
|
|
|
|
|
if (mark == 'R')
|
|
|
|
|
{
|
|
|
|
|
msg << "ignorato in quanto ridondante";
|
|
|
|
|
row->add("X", 0); // Marcalo come elaborato comunque
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mark <= ' ')
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
2007-04-19 15:31:42 +00:00
|
|
|
|
TString body; row->get(sf.cid2index(F_BODY), body);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (body.find("[Transaction]") >= 0)
|
|
|
|
|
{
|
|
|
|
|
int err = 0;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
const bool yes = save_sheet_line(err, nrow);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (yes)
|
|
|
|
|
{
|
|
|
|
|
msg << "elaborato con successo";
|
2007-04-19 15:31:42 +00:00
|
|
|
|
one_saved = true;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (err == NOT_GEST)
|
|
|
|
|
{
|
2002-12-20 16:15:03 +00:00
|
|
|
|
const TMask& m = sf.sheet_mask();
|
2000-10-03 13:45:12 +00:00
|
|
|
|
msg << " definire il programma gestore del file " << m.get(F_SUBJECT);
|
|
|
|
|
}
|
|
|
|
|
else
|
2002-09-13 14:06:05 +00:00
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
msg << "non elaborato a causa di un errore (n.ro " << err << ')';
|
2002-09-13 14:06:05 +00:00
|
|
|
|
if (_sequential)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
msg << "ignorato in quanto transazione non riconosciuta";
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
2011-09-09 11:10:24 +00:00
|
|
|
|
log(msg);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-09 11:10:24 +00:00
|
|
|
|
log(TR("Fine elaborazione"));
|
|
|
|
|
log("");
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
2002-12-20 16:15:03 +00:00
|
|
|
|
sf.force_update(); // Fai apparire tutte le X
|
2009-09-30 14:56:48 +00:00
|
|
|
|
|
2011-09-09 11:10:24 +00:00
|
|
|
|
TBrowsefile_field& bf = (TBrowsefile_field&)field(F_LOG);
|
2009-09-30 14:56:48 +00:00
|
|
|
|
enable(DLG_DELLOG, bf.lines() > 0);
|
2011-09-09 11:10:24 +00:00
|
|
|
|
enable(DLG_DELREC);
|
2002-12-20 16:15:03 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
#ifdef DBG
|
2009-09-30 14:56:48 +00:00
|
|
|
|
one_saved &= yesno_box("Si desidera eliminare i messaggi processati?");
|
2000-10-03 13:45:12 +00:00
|
|
|
|
#endif
|
2009-09-30 14:56:48 +00:00
|
|
|
|
|
|
|
|
|
_mail_semaphore = 0;
|
|
|
|
|
if (one_saved)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
1999-04-06 15:34:39 +00:00
|
|
|
|
test_delete();
|
|
|
|
|
fill_messages();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-09 11:10:24 +00:00
|
|
|
|
void TMailer_mask::exec_scripts()
|
|
|
|
|
{
|
|
|
|
|
TSheet_field& sf = sfield(F_SCRIPTS);
|
|
|
|
|
if (_mail_semaphore != 0 || sf.items()== 0)
|
|
|
|
|
return;
|
|
|
|
|
_mail_semaphore = 1;
|
|
|
|
|
|
|
|
|
|
TString cmd, des;
|
|
|
|
|
FOR_EACH_SHEET_ROW(sf, nrow, row) if (row->starts_with("X"))
|
|
|
|
|
{
|
|
|
|
|
row->get(1, cmd);
|
|
|
|
|
if (cmd.full())
|
|
|
|
|
{
|
|
|
|
|
row->get(2, des);
|
|
|
|
|
log(des.full() ? des : cmd);
|
|
|
|
|
TExternal_app app(cmd);
|
|
|
|
|
const long ret = app.run();
|
|
|
|
|
if (ret != 0)
|
|
|
|
|
{
|
|
|
|
|
TString80 msg; msg.format(FR("Errore %ld nell'esecuzione di %s"), ret, (const char*)cmd);
|
|
|
|
|
log(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log("");
|
|
|
|
|
|
|
|
|
|
_mail_semaphore = 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
bool TMailer_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
2001-04-30 14:22:43 +00:00
|
|
|
|
case F_TIMER:
|
1999-05-24 13:34:11 +00:00
|
|
|
|
if (e == fe_init || e == fe_modify)
|
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (_timer_id != XVT_TIMER_ERROR)
|
1999-05-24 13:34:11 +00:00
|
|
|
|
{
|
|
|
|
|
xvt_timer_destroy(_timer_id);
|
|
|
|
|
_timer_id = XVT_TIMER_ERROR;
|
|
|
|
|
}
|
2008-04-07 11:06:28 +00:00
|
|
|
|
_interval = atol(o.get());
|
|
|
|
|
|
|
|
|
|
if (_interval > 0)
|
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
_timer_id = xvt_timer_create(win(), 1000L);
|
|
|
|
|
_secs = 0L;
|
1999-05-24 13:34:11 +00:00
|
|
|
|
if (_timer_id == XVT_TIMER_ERROR)
|
|
|
|
|
return error_box("Impossibile impostare il timer");
|
2008-04-07 11:06:28 +00:00
|
|
|
|
}
|
2011-09-09 11:10:24 +00:00
|
|
|
|
}
|
1999-05-24 13:34:11 +00:00
|
|
|
|
break;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
case F_MESSAGES:
|
|
|
|
|
if (e == fe_init)
|
|
|
|
|
{
|
|
|
|
|
if (!field(F_SERVER).empty() &&
|
|
|
|
|
!field(F_USER).empty() &&
|
|
|
|
|
!field(F_PASSWORD).empty())
|
2001-04-30 14:22:43 +00:00
|
|
|
|
fill_messages();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
} else
|
|
|
|
|
if (e == se_query_add)
|
|
|
|
|
{
|
1999-05-24 13:34:11 +00:00
|
|
|
|
auto_save_all();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DLG_USER:
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
int err = 0;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
if (!save_sheet_line(err))
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (err == NOT_TRANS)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
message_box(TR("Messaggio ignorato: transazione non riconosciuta"));
|
2000-10-03 13:45:12 +00:00
|
|
|
|
else
|
|
|
|
|
if (err == NOT_GEST)
|
|
|
|
|
{
|
|
|
|
|
TSheet_field& sf = sfield(F_MESSAGES);
|
|
|
|
|
TMask& m = sf.sheet_mask();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
error_box(FR("Definire il programma gestore del file %s"), (const char*)m.get(F_SUBJECT));
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-04-19 15:31:42 +00:00
|
|
|
|
message_box(FR("Messaggio non elaborato a causa di un errore (n.ro %d)"), err);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
break;
|
|
|
|
|
case DLG_SAVEREC:
|
2001-04-30 14:22:43 +00:00
|
|
|
|
if (e == fe_button && jolly == 0)
|
|
|
|
|
{
|
|
|
|
|
if (curr_page() == 0)
|
2000-05-05 15:25:49 +00:00
|
|
|
|
save_all_lines();
|
2001-04-30 14:22:43 +00:00
|
|
|
|
else
|
|
|
|
|
save();
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
break;
|
|
|
|
|
case DLG_DELREC:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (jolly == 0)
|
|
|
|
|
{
|
|
|
|
|
test_delete();
|
|
|
|
|
fill_messages();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_FILE:
|
|
|
|
|
if (jolly == 3)
|
|
|
|
|
{
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
TMask& m = o.mask();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
TArray_sheet sht(-1,-1,-4,-4,TR("Selezione archivio"), HR("Codice@6R|Descrizione archivio@70"));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
const TPrefix& pref = prefix();
|
|
|
|
|
const int total = pref.items();
|
|
|
|
|
if (total > 0)
|
|
|
|
|
{
|
|
|
|
|
TWait_cursor hourglass;
|
|
|
|
|
for (int i = LF_USER; i < total; i++)
|
|
|
|
|
{
|
|
|
|
|
TToken_string* row = new TToken_string;
|
|
|
|
|
*row << i;
|
|
|
|
|
row->add(pref.description(*row));
|
|
|
|
|
sht.rows_array().add(row);
|
|
|
|
|
}
|
|
|
|
|
sht.select(m.get_int(o.dlg()) - LF_USER);
|
|
|
|
|
}
|
|
|
|
|
if (sht.run() == K_ENTER)
|
|
|
|
|
m.set(o.dlg(), sht.selected() + LF_USER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_EXPR:
|
|
|
|
|
if (jolly == 3)
|
|
|
|
|
{
|
|
|
|
|
if (e == fe_modify || e == fe_close)
|
|
|
|
|
{
|
|
|
|
|
TAutomask& m = (TAutomask&)o.mask();
|
|
|
|
|
const int num = m.get_int(F_FILE);
|
|
|
|
|
TFilter_expr expr(m, num, o.get());
|
|
|
|
|
return expr.error() == 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-04-30 14:22:43 +00:00
|
|
|
|
case DLG_DELLOG:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
TBrowsefile_field& bf = (TBrowsefile_field&)field(F_LOG);
|
|
|
|
|
TViswin& vv = bf.vis_win();
|
|
|
|
|
vv.destroy_lines();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DLG_PRINT:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
TBrowsefile_field& bf = (TBrowsefile_field&)field(F_LOG);
|
|
|
|
|
TViswin& vv = bf.vis_win();
|
|
|
|
|
vv.text().print();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return false; // Don't close
|
2001-04-30 14:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-09-30 14:56:48 +00:00
|
|
|
|
|
|
|
|
|
_last_use = clock();
|
|
|
|
|
|
2007-04-19 15:31:42 +00:00
|
|
|
|
return true;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMailer_mask::save_sheet(TConfig& ini, short dlg, const char* var) const
|
|
|
|
|
{
|
|
|
|
|
TSheet_field& sf = sfield(dlg);
|
|
|
|
|
FOR_EACH_SHEET_ROW(sf, r, row)
|
2007-04-19 15:31:42 +00:00
|
|
|
|
ini.set(var, *row, NULL, true, r);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMailer_mask::load_sheet(TConfig& ini, short dlg, const char* var)
|
|
|
|
|
{
|
|
|
|
|
TSheet_field& sf = sfield(dlg);
|
|
|
|
|
sf.destroy();
|
|
|
|
|
for (int r = 0; ini.exist(var, r); r++)
|
|
|
|
|
sf.row(r) = ini.get(var, NULL, r);
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-24 13:34:11 +00:00
|
|
|
|
void TMailer_mask::auto_save_all()
|
|
|
|
|
{
|
|
|
|
|
if (_mail_semaphore == 0)
|
2001-04-30 14:22:43 +00:00
|
|
|
|
{
|
2002-12-20 16:15:03 +00:00
|
|
|
|
TSheet_field& sf = sfield(F_MESSAGES);
|
1999-05-24 13:34:11 +00:00
|
|
|
|
test_delete();
|
2008-04-02 10:37:51 +00:00
|
|
|
|
if (sf.items() == 0)
|
2008-04-07 11:06:28 +00:00
|
|
|
|
fill_messages();
|
2009-09-30 14:56:48 +00:00
|
|
|
|
if (_interval > 0 && sf.items() > 0)
|
|
|
|
|
save_all_lines();
|
2011-09-09 11:10:24 +00:00
|
|
|
|
|
|
|
|
|
exec_scripts();
|
1999-05-24 13:34:11 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
NFCHECK("Can't save locked mail");
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-30 14:56:48 +00:00
|
|
|
|
bool TMailer_mask::unattended() const
|
|
|
|
|
{
|
|
|
|
|
if (!xvt_vobj_is_focusable(win()))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
RCT r; xvt_vobj_get_outer_rect(TASK_WIN, &r);
|
|
|
|
|
if (r.bottom - r.top < 64)
|
|
|
|
|
return true; // Finestra principale iconizzata
|
|
|
|
|
|
|
|
|
|
return (clock()-_last_use) > 10*CLOCKS_PER_SEC;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-20 15:23:26 +00:00
|
|
|
|
long TMailer_mask::handler(WINDOW win, EVENT* ep)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2009-10-20 15:23:26 +00:00
|
|
|
|
if (ep->type == E_TIMER && ep->v.timer.id == _timer_id)
|
1999-05-24 13:34:11 +00:00
|
|
|
|
{
|
2009-10-20 15:23:26 +00:00
|
|
|
|
_secs++;
|
|
|
|
|
if (_secs >= _interval)
|
|
|
|
|
{
|
|
|
|
|
_secs = 0L;
|
|
|
|
|
if (_mail_semaphore == 0 && unattended())
|
|
|
|
|
auto_save_all();
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
2009-10-20 15:23:26 +00:00
|
|
|
|
return 0L;
|
1999-05-24 13:34:11 +00:00
|
|
|
|
}
|
2009-10-20 15:23:26 +00:00
|
|
|
|
return TAutomask::handler(win, ep);
|
1999-05-24 13:34:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
void TMailer_mask::save() const
|
|
|
|
|
{
|
|
|
|
|
TConfig ini(CONFIG_DITTA, "MailTransactions");
|
|
|
|
|
ini.remove_all();
|
|
|
|
|
ini.set("Server", get(F_SERVER));
|
|
|
|
|
ini.set("User", get(F_USER));
|
|
|
|
|
ini.set("Password", encode(get(F_PASSWORD)));
|
1999-05-24 13:34:11 +00:00
|
|
|
|
ini.set("Timer", get(F_TIMER));
|
2007-04-19 15:31:42 +00:00
|
|
|
|
ini.set("Log", get(F_TRACKING));
|
2008-05-22 11:34:38 +00:00
|
|
|
|
ini.set("Backup", get(F_BACKUP));
|
2008-07-21 11:23:24 +00:00
|
|
|
|
ini.set("DelCancel", get(F_DELCANCEL));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
save_sheet(ini, F_ADDRESSES, "Recipient");
|
|
|
|
|
save_sheet(ini, F_PARAMS, "Filter");
|
2011-09-09 11:10:24 +00:00
|
|
|
|
save_sheet(ini, F_SCRIPTS, "Script");
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TMailer_mask::load()
|
|
|
|
|
{
|
|
|
|
|
TConfig ini(CONFIG_DITTA, "MailTransactions");
|
|
|
|
|
set(F_SERVER, ini.get("Server"));
|
|
|
|
|
set(F_USER, ini.get("User"));
|
|
|
|
|
set(F_PASSWORD, decode(ini.get("Password")));
|
1999-05-24 13:34:11 +00:00
|
|
|
|
set(F_TIMER, ini.get_int("Timer"));
|
2007-04-19 15:31:42 +00:00
|
|
|
|
set(F_TRACKING, ini.get("Log"));
|
2008-05-22 11:34:38 +00:00
|
|
|
|
set(F_BACKUP, ini.get("Backup"));
|
2008-07-21 11:23:24 +00:00
|
|
|
|
set(F_DELCANCEL, ini.get("DelCancel"));
|
1999-04-06 15:34:39 +00:00
|
|
|
|
load_sheet(ini, F_ADDRESSES, "Recipient");
|
|
|
|
|
load_sheet(ini, F_PARAMS, "Filter");
|
2011-09-09 11:10:24 +00:00
|
|
|
|
load_sheet(ini, F_SCRIPTS, "Script");
|
2007-04-19 15:31:42 +00:00
|
|
|
|
|
|
|
|
|
_sequential = ini.get_bool("StopOnError", "ba7");
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-05-24 13:34:11 +00:00
|
|
|
|
TMailer_mask::TMailer_mask()
|
2009-09-30 14:56:48 +00:00
|
|
|
|
: TAutomask("ba7100a"), _timer_id(XVT_TIMER_ERROR), _mail_semaphore(0), _last_use(0)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
load();
|
2007-04-19 15:31:42 +00:00
|
|
|
|
|
|
|
|
|
const bool is_super = user() == ::dongle().administrator();
|
|
|
|
|
enable(-G_SUPERUSER, is_super);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMailer_mask::~TMailer_mask()
|
|
|
|
|
{
|
1999-05-24 13:34:11 +00:00
|
|
|
|
if (_timer_id != XVT_TIMER_ERROR)
|
|
|
|
|
{
|
|
|
|
|
xvt_timer_destroy(_timer_id);
|
|
|
|
|
_timer_id = XVT_TIMER_ERROR;
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TMailer
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2008-06-19 15:35:28 +00:00
|
|
|
|
const char* const appname = TR("Postino");
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
class TMailer : public TSkeleton_application
|
|
|
|
|
{
|
2011-04-12 13:02:16 +00:00
|
|
|
|
protected:
|
|
|
|
|
virtual bool create();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
virtual void main_loop();
|
|
|
|
|
};
|
|
|
|
|
|
2011-04-12 13:02:16 +00:00
|
|
|
|
bool TMailer::create()
|
|
|
|
|
{
|
|
|
|
|
if (xvt_vobj_get_attr(NULL_WIN, ATTR_APPL_ALREADY_RUNNING))
|
|
|
|
|
return error_box(FR("Il programma %s <20> gi<67> in esecuzione!"), appname);
|
|
|
|
|
return TSkeleton_application::create();
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
void TMailer::main_loop()
|
|
|
|
|
{
|
2008-06-19 15:35:28 +00:00
|
|
|
|
WINDOW tray = xvt_trayicon_create(TASK_WIN, 0, appname);
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
open_files(LF_USER, 0);
|
|
|
|
|
TMailer_mask mm;
|
|
|
|
|
mm.run();
|
2008-06-19 15:35:28 +00:00
|
|
|
|
|
|
|
|
|
xvt_trayicon_destroy(tray);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ba7100(int argc, char* argv[])
|
|
|
|
|
{
|
2009-10-20 15:23:26 +00:00
|
|
|
|
#if XVT_OS==XVT_OS_WIN32
|
2008-06-19 15:35:28 +00:00
|
|
|
|
long style = xvt_vobj_get_attr(NULL_WIN, ATTR_WIN_PM_TWIN_STARTUP_STYLE);
|
|
|
|
|
style |= WSF_NO_TASKBAR;
|
|
|
|
|
xvt_vobj_set_attr(NULL_WIN, ATTR_WIN_PM_TWIN_STARTUP_STYLE, style);
|
2009-10-20 15:23:26 +00:00
|
|
|
|
#endif
|
1999-04-06 15:34:39 +00:00
|
|
|
|
TMailer app;
|
2008-06-19 15:35:28 +00:00
|
|
|
|
app.run(argc, argv, appname);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|