Patch level : 4.0

Files correlati     : ba7
Ricompilazione Demo : [ ]
Commento            :
Aggiunto supporto per log delle transazioni del postino


git-svn-id: svn://10.65.10.50/trunk@15245 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2007-04-19 15:31:42 +00:00
parent 9a36f6bf59
commit 4d8ae81dbe
5 changed files with 230 additions and 156 deletions

View File

@ -6,17 +6,15 @@
#include <execp.h> #include <execp.h>
#include <expr.h> #include <expr.h>
#include <golem.h> #include <golem.h>
#include <tabutil.h> #include <netsock.h>
#include <prefix.h> #include <prefix.h>
#include <tabutil.h>
#include <recarray.h> #include <recarray.h>
#include <sheet.h> #include <sheet.h>
#include <utility.h> #include <utility.h>
#include <viswin.h> #include <viswin.h>
#include <browfile.h> #include <browfile.h>
#define NO_MFC
#include <netsock.h>
#include "ba7.h" #include "ba7.h"
#include "ba7100a.h" #include "ba7100a.h"
#define NOT_TRANS -883 #define NOT_TRANS -883
@ -26,18 +24,17 @@
// TConfig utilities // TConfig utilities
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
TString& set_ini_var(int cfg, const char* para, const TString& set_ini_var(int cfg, const char* para,
const char* var, const char* val) const char* var, const char* val)
{ {
static TString80 prev;
TConfig ini(cfg, para); TConfig ini(cfg, para);
prev = ini.get(var); const TString& prev = ini.get(var);
if (val != NULL) if (val != NULL)
ini.set(var, val); ini.set(var, val);
return prev; return prev.full() ? (get_tmp_string()=prev) : EMPTY_STRING;
} }
inline TString& get_ini_var(int cfg, const char* para, const char* var) inline const TString& get_ini_var(int cfg, const char* para, const char* var)
{ return set_ini_var(cfg, para, var, NULL); } { return set_ini_var(cfg, para, var, NULL); }
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -67,16 +64,16 @@ public:
bool TMail_box::default_params(TString& server, TString& user,TString& password) bool TMail_box::default_params(TString& server, TString& user,TString& password)
{ {
bool ok = TRUE; bool ok = true;
if (server.empty()) if (server.blank())
{ {
server = get_ini_var(CONFIG_INSTALL, "Server", "POP3"); server = get_ini_var(CONFIG_INSTALL, "Server", "POP3");
if (server.empty()) if (server.empty())
ok = FALSE; ok = false;
} }
if (user.empty()) if (user.blank())
user = ::user(); user = ::user();
if (password.empty()) if (password.blank())
{ {
const TString& pwd = cache().get(LF_USER, user).get("PASSWORD"); const TString& pwd = cache().get(LF_USER, user).get("PASSWORD");
password = ::decode(pwd); password = ::decode(pwd);
@ -90,22 +87,21 @@ bool TMail_box::logon(const char* ser, const char* usr, const char* pwd)
logoff(); logoff();
if (!IsOk()) if (!IsOk())
return error_box("Impossibile inizializzare il client POP3"); return error_box(TR("Impossibile inizializzare il client POP3"));
TString server(ser); TString server(ser);
TString user(usr); TString user(usr);
TString password(pwd); TString password(pwd);
if (!default_params(server, user, password)) if (!default_params(server, user, password))
return error_box("E' necessario specificare un server POP3, un utente ed una password"); return error_box(TR("E' necessario specificare un server POP3, un utente ed una password"));
_connection = QueryConnection("110", server); _connection = QueryConnection("110", server);
if (_connection != 0) if (_connection != 0)
{ {
TString buf; TString buf, req;
TString req;
ReadLine(_connection, buf); ReadLine(_connection, buf);
if (buf[0] != '+') if (buf[0] != '+')
return error_box("Il server POP3 %s non risponde\nRisultato : %s", return error_box(FR("Il server POP3 %s non risponde\nRisultato : %s"),
(const char*)server, (const char *)buf); (const char*)server, (const char *)buf);
buf = "USER "; buf << user << "\r\n"; buf = "USER "; buf << user << "\r\n";
@ -113,7 +109,7 @@ bool TMail_box::logon(const char* ser, const char* usr, const char* pwd)
req = buf; req = buf;
ReadLine(_connection, buf); ReadLine(_connection, buf);
if (buf[0] != '+') if (buf[0] != '+')
return error_box("Il server POP3 %s non accetta l'utente %s\nRichiesta : %sRisultato : %s", return error_box(FR("Il server POP3 %s non accetta l'utente %s\nRichiesta : %sRisultato : %s"),
(const char*)server, (const char*)user, (const char *) req, (const char *)buf); (const char*)server, (const char*)user, (const char *) req, (const char *)buf);
buf = "PASS "; buf << password << "\r\n"; buf = "PASS "; buf << password << "\r\n";
@ -121,14 +117,14 @@ bool TMail_box::logon(const char* ser, const char* usr, const char* pwd)
req = buf; req = buf;
ReadLine(_connection, buf); ReadLine(_connection, buf);
if (buf[0] != '+') if (buf[0] != '+')
return error_box("Il server POP3 %s non accetta la password dell'utente %s\nRichiesta : %sRisultato : %s", return error_box(FR("Il server POP3 %s non accetta la password dell'utente %s\nRichiesta : %sRisultato : %s"),
(const char*)server, (const char*)user, (const char *) req, (const char *)buf); (const char*)server, (const char*)user, (const char *) req, (const char *)buf);
} }
else else
return error_box("Impossibile contattare il server POP3 %s", return error_box(FR("Impossibile contattare il server POP3 %s"),
(const char*)server); (const char*)server);
return TRUE; return true;
} }
void TMail_box::logoff() void TMail_box::logoff()
@ -173,7 +169,7 @@ HIDDEN int str2month(const char* str)
int m; int m;
for (m = 11; m > 0; m--) for (m = 11; m > 0; m--)
{ {
if (stricmp(str, mese[m]) == 0) if (xvt_str_compare_ignoring_case(str, mese[m]) == 0)
break; break;
} }
return m+1; return m+1;
@ -184,7 +180,7 @@ enum EncodingType { enc_plain_text, enc_quoted_printable, enc_base64 };
int TMail_box::get(TMail_messages& m) int TMail_box::get(TMail_messages& m)
{ {
// Lista dei caratteri validi // Lista dei caratteri validi
const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+*"; const char* const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+*";
// Lista per decodifica dei caratteri validi // Lista per decodifica dei caratteri validi
char Deco64[256]; char Deco64[256];
@ -209,9 +205,9 @@ int TMail_box::get(TMail_messages& m)
ReadLine(_connection, buf); ReadLine(_connection, buf);
bool ok = buf[0] == '+'; bool ok = buf[0] == '+';
EncodingType encoding = enc_plain_text; EncodingType encoding = enc_plain_text;
bool in_body = FALSE; bool in_body = false;
bool in_section = FALSE; bool in_section = false;
bool buf_already_read = FALSE; bool buf_already_read = false;
boundary.cut(0); boundary.cut(0);
while (ok) while (ok)
@ -220,12 +216,12 @@ int TMail_box::get(TMail_messages& m)
{ {
if (!ReadLine(_connection, buf)) if (!ReadLine(_connection, buf))
{ {
ok = FALSE; ok = false;
break; // Unexpected EOF break; // Unexpected EOF
} }
} }
else else
buf_already_read = FALSE; buf_already_read = false;
if (buf[0] == '.') if (buf[0] == '.')
{ {
buf.ltrim(1); buf.ltrim(1);
@ -299,56 +295,56 @@ int TMail_box::get(TMail_messages& m)
else else
{ {
if (buf.find(boundary) >= 0) if (buf.find(boundary) >= 0)
in_section = TRUE; in_section = true;
} }
} }
else else
{ {
if (buf.blank()) if (buf.blank())
{ {
in_body = TRUE; in_body = true;
continue; continue;
} }
} }
if (buf.compare("From:", 5, TRUE) == 0) if (buf.compare("From:", 5, true) == 0)
{ {
buf.ltrim(6); buf.trim(); buf.ltrim(6); buf.trim();
msg.set_sender(buf); msg.set_sender(buf);
continue; continue;
} }
if (buf.compare("To:", 3, TRUE) == 0) if (buf.compare("To:", 3, true) == 0)
{ {
buf.ltrim(4); buf.trim(); buf.ltrim(4); buf.trim();
msg.add_recipient(buf); msg.add_recipient(buf);
continue; continue;
} }
if (buf.compare("Cc:", 3, TRUE) == 0) if (buf.compare("Cc:", 3, true) == 0)
{ {
buf.ltrim(4); buf.trim(); buf.ltrim(4); buf.trim();
msg.add_copy_recipient(buf); msg.add_copy_recipient(buf);
continue; continue;
} }
if (buf.compare("Subject:", 8, TRUE) == 0) if (buf.compare("Subject:", 8, true) == 0)
{ {
buf.ltrim(9); buf.trim(); buf.ltrim(9); buf.trim();
msg.set_subject(buf); msg.set_subject(buf);
continue; continue;
} }
if (buf.compare("Date:", 5, TRUE) == 0) if (buf.compare("Date:", 5, true) == 0)
{ {
TToken_string d(buf.mid(6), ' '); d.trim(); TToken_string d(buf.mid(6), ' '); d.trim();
int giorno = d.get_int(1); int giorno = d.get_int(1);
int mese = str2month(d.get()); int mese = str2month(d.get());
int anno = d.get_int(); int anno = d.get_int();
if (anno < 1000) anno += anno >= 98 ? 1900 : 2000; if (anno < 100) anno += 2000;
TString16 ora = d.get(); TString16 ora = d.get();
buf.cut(0); buf.cut(0);
buf << anno << '/' << mese << '/' << giorno << ' ' << ora; buf << anno << '/' << mese << '/' << giorno << ' ' << ora;
msg.set_date_time(buf); msg.set_date_time(buf);
continue; continue;
} }
if (buf.compare("Content-Transfer-Encoding:", 26, TRUE) == 0) if (buf.compare("Content-Transfer-Encoding:", 26, true) == 0)
{ {
if (buf.find("base64") > 0) if (buf.find("base64") > 0)
encoding = enc_base64; else encoding = enc_base64; else
@ -356,7 +352,7 @@ int TMail_box::get(TMail_messages& m)
encoding = enc_quoted_printable; encoding = enc_quoted_printable;
continue; continue;
} }
if (buf.compare("Content-Type:", 13, TRUE) == 0) if (buf.compare("Content-Type:", 13, true) == 0)
{ {
int bnd = buf.find("oundary="); // Funziona per Boundary e boundary int bnd = buf.find("oundary="); // Funziona per Boundary e boundary
if (bnd < 0) if (bnd < 0)
@ -364,7 +360,7 @@ int TMail_box::get(TMail_messages& m)
ReadLine(_connection, buf); ReadLine(_connection, buf);
bnd = buf.find("oundary="); bnd = buf.find("oundary=");
if (bnd < 0) if (bnd < 0)
buf_already_read = TRUE; buf_already_read = true;
} }
if (bnd > 0) if (bnd > 0)
{ {
@ -434,14 +430,12 @@ TFilter_expr::TFilter_expr(TAutomask& m, int logicnum, const char* expr)
if (logicnum < LF_USER || logicnum >= prefix().items()) if (logicnum < LF_USER || logicnum >= prefix().items())
logicnum = LF_TABCOM; // Niente errori fatali, se possibile logicnum = LF_TABCOM; // Niente errori fatali, se possibile
TLocalisamfile isf(logicnum); const TRectype rec(logicnum);
TRectype& rec = isf.curr();
for (int i = 0; i < numvar(); i++) if (!rec.exist(varname(i))) for (int i = 0; i < numvar(); i++) if (!rec.exist(varname(i)))
{ {
_error = 883; _error = 883;
TString msg; TString msg;
msg << "Il campo " << varname(i) msg.format(FR("Il campo %s non appartiene al file %d"), varname(i), logicnum);
<< " non appartiene al file " << logicnum;
print_error(msg); print_error(msg);
break; break;
} }
@ -477,12 +471,15 @@ protected:
TToken_string& get_key1(int lf) const; TToken_string& get_key1(int lf) const;
bool build_key1(int lf, const TString& body, TToken_string& key) const; bool build_key1(int lf, const TString& body, TToken_string& key) const;
bool build_key1(const TMail_message& msg, TToken_string& key) const;
void find_redundant_messages(); void find_redundant_messages();
void track(const TMail_message& msg, const TString& app, const TString& action, int err);
bool exec_app(int & err, const TString& appname, TMail_message & msg);
public: public:
void test_delete(); void test_delete();
int fill_messages(); int fill_messages();
bool exec_app(int & err, const char * appname, TMail_message & msg);
bool save_sheet_line(int& err, int line = -1); bool save_sheet_line(int& err, int line = -1);
void save_all_lines(); void save_all_lines();
void auto_save_all(); void auto_save_all();
@ -498,15 +495,16 @@ void TMailer_mask::test_delete()
{ {
TWait_cursor hourglass; TWait_cursor hourglass;
xvtil_statbar_set("Eliminazione messaggi POP3..."); xvtil_statbar_set(TR("Eliminazione messaggi POP3..."));
do_events(); do_events();
TSheet_field& sf = sfield(F_MESSAGES); TString4 mailer;
TString16 mailer, id; TString16 id;
TMail_messages mapidel; // Lista dei messaggi MAPI da cancellare TMail_messages mapidel; // Lista dei messaggi MAPI da cancellare
TMail_box mailbox; TMail_box mailbox;
TSheet_field& sf = sfield(F_MESSAGES);
FOR_EACH_SHEET_ROW_BACK(sf, nrow, row) if (*row->get(0) == 'X') FOR_EACH_SHEET_ROW_BACK(sf, nrow, row) if (*row->get(0) == 'X')
{ {
row->get(sf.cid2index(F_MAILER), mailer); row->get(sf.cid2index(F_MAILER), mailer);
@ -519,7 +517,7 @@ void TMailer_mask::test_delete()
break; break;
} }
if (!mailbox.remove(id)) if (!mailbox.remove(id))
error_box("Impossibile cancellare il messaggio POP3 %s", (const char*)id); error_box(FR("Impossibile cancellare il messaggio POP3 %s"), (const char*)id);
} }
else else
{ {
@ -533,12 +531,12 @@ void TMailer_mask::test_delete()
if (mapidel.items() > 0) if (mapidel.items() > 0)
{ {
xvtil_statbar_set("Eliminazione messaggi MAPI..."); xvtil_statbar_set(TR("Eliminazione messaggi MAPI..."));
do_events(); do_events();
mapidel.remove(); mapidel.remove();
} }
xvtil_statbar_set("Pronto"); xvtil_statbar_set(TR("Pronto"));
do_events(); do_events();
} }
@ -596,12 +594,12 @@ int TMailer_mask::fill_messages()
if (get_bool(F_MAPI)) if (get_bool(F_MAPI))
{ {
xvtil_statbar_set("Ricezione messaggi MAPI..."); xvtil_statbar_set(TR("Ricezione messaggi MAPI..."));
do_events(); do_events();
totmapi = _box.get(); totmapi = _box.get();
} }
xvtil_statbar_set("Ricezione messaggi POP3..."); xvtil_statbar_set(TR("Ricezione messaggi POP3..."));
do_events(); do_events();
mailbox.logon(server, user, password); mailbox.logon(server, user, password);
mailbox.get(_box); mailbox.get(_box);
@ -626,10 +624,12 @@ int TMailer_mask::fill_messages()
{ {
mess << *msgrow; mess << *msgrow;
if (mess.len() >= 1024) if (mess.len() >= 1024)
{
mess.cut(1024);
break; break;
} }
}
row.add(mess, sf.cid2index(F_BODY)); row.add(mess, sf.cid2index(F_BODY));
row.add(m<totmapi?"MAPI":"POP3", sf.cid2index(F_MAILER));
if (m < totmapi) if (m < totmapi)
{ {
row.add("MAPI", sf.cid2index(F_MAILER)); row.add("MAPI", sf.cid2index(F_MAILER));
@ -643,14 +643,14 @@ int TMailer_mask::fill_messages()
} }
sf.force_update(); sf.force_update();
xvtil_statbar_set("Pronto"); xvtil_statbar_set(TR("Pronto"));
return sf.items(); return sf.items();
} }
bool TMailer_mask::file2app(const TString& file, TString& app) const bool TMailer_mask::file2app(const TString& file, TString& app) const
{ {
bool ok = FALSE; bool ok = false;
const TString* run = (const TString*)_apps.objptr(file); const TString* run = (const TString*)_apps.objptr(file);
if (run == NULL) if (run == NULL)
@ -680,7 +680,7 @@ bool TMailer_mask::file2app(const TString& file, TString& app) const
} }
} }
else else
ok = TRUE; ok = true;
((TMailer_mask*)this)->_apps.add(file, app); // Fool const ((TMailer_mask*)this)->_apps.add(file, app); // Fool const
} }
@ -695,17 +695,17 @@ bool TMailer_mask::file2app(const TString& file, TString& app) const
bool is_incomplete(const TString& l) bool is_incomplete(const TString& l)
{ {
if (l[0] == '[') if (l[0] == '[')
return FALSE; return false;
const char a = l.right(1)[0]; const char a = l.right(1)[0];
if (a == '=') if (a == '=')
return TRUE; return true;
const int eq = l.find("= '"); const int eq = l.find("= '");
if (eq > 0 && eq < 20) if (eq > 0 && eq < 20)
return a != '\''; return a != '\'';
return FALSE; return false;
} }
void adjust_long_lines(const TFilename& tmp) void adjust_long_lines(const TFilename& tmp)
@ -713,17 +713,17 @@ void adjust_long_lines(const TFilename& tmp)
TFilename dst_name; dst_name.temp(); TFilename dst_name; dst_name.temp();
ofstream dst(dst_name); ofstream dst(dst_name);
bool adjusted = FALSE; bool adjusted = false;
TScanner org(tmp); TScanner org(tmp);
while (TRUE) while (true)
{ {
const TString& l = org.line(); const TString& l = org.line();
if (l.empty()) if (l.empty())
break; break;
if (is_incomplete(l)) if (is_incomplete(l))
{ {
adjusted = TRUE; adjusted = true;
dst << l; dst << l;
org.line(); org.line();
char s = l[0]; char s = l[0];
@ -746,16 +746,64 @@ void adjust_long_lines(const TFilename& tmp)
dst.close(); dst.close();
if (adjusted) if (adjusted)
fcopy(dst_name, tmp); fcopy(dst_name, tmp);
remove(dst_name); remove_file(dst_name);
} }
bool TMailer_mask::exec_app(int & err, const char * appname, TMail_message & msg) void TMailer_mask::track(const TMail_message& msg, const TString& app, const TString& action, int err)
{ {
const TString& fname = get(F_TRACKING);
if (fname.full())
{
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;
TToken_string k1; build_key1(msg, k1);
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;
}
}
bool TMailer_mask::exec_app(int& err, const TString& appname, TMail_message& msg)
{
err = NOERR;
TString action;
if (appname.compare("sink", -1, true) == 0)
{
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(); TFilename tmp; tmp.temp();
{ {
ofstream outf(tmp); ofstream outf(tmp);
const int items = msg.items(); const int items = msg.items();
bool long_lines = FALSE; bool long_lines = false;
TString message; TString message;
for (int i = 0; i < items; i++) for (int i = 0; i < items; i++)
{ {
@ -768,6 +816,7 @@ bool TMailer_mask::exec_app(int & err, const char * appname, TMail_message & msg
TConfig ini(tmp, "Transaction"); TConfig ini(tmp, "Transaction");
ini.set("From", msg.sender()); ini.set("From", msg.sender());
action = ini.get("Action");
} }
TString command_line(appname); TString command_line(appname);
@ -775,20 +824,21 @@ bool TMailer_mask::exec_app(int & err, const char * appname, TMail_message & msg
TExternal_app app(command_line); TExternal_app app(command_line);
err = app.run(); err = app.run();
xvt_sys_sleep(1000); xvt_sys_sleep(1000);
bool ok = err == NOERR;
if (ok) if (err == NOERR)
{ {
TConfig ini(tmp, "Transaction"); TConfig ini(tmp, "Transaction");
ok = ini.get("Result") == "OK"; if (ini.get("Result") == "OK")
if (ok)
err = 0; err = 0;
else else
err = ini.get_int("Error"); err = ini.get_int("Error");
} }
::remove(tmp); remove_file(tmp);
}
return ok; track(msg, appname, action, err);
return err == NOERR;
} }
bool TMailer_mask::save_sheet_line(int& err, int nrow) bool TMailer_mask::save_sheet_line(int& err, int nrow)
@ -807,7 +857,7 @@ bool TMailer_mask::save_sheet_line(int& err, int nrow)
if (msg.find("[Transaction]") < 0) if (msg.find("[Transaction]") < 0)
{ {
err = NOT_TRANS; err = NOT_TRANS;
return FALSE; // It's not a transaction return false; // It's not a transaction
} }
TString subj = m.get(F_SUBJECT); TString subj = m.get(F_SUBJECT);
@ -821,7 +871,7 @@ bool TMailer_mask::save_sheet_line(int& err, int nrow)
if (!file2app(subj, appname)) // It hasn't a valid application if (!file2app(subj, appname)) // It hasn't a valid application
{ {
err = NOT_GEST; err = NOT_GEST;
return FALSE; return false;
} }
TMail_message& full_msg = _box.msg(nrow); TMail_message& full_msg = _box.msg(nrow);
@ -852,7 +902,7 @@ bool TMailer_mask::save_sheet_line(int& err, int nrow)
} }
// Restore mail recipient // Restore mail recipient
// if (old_mailto.not_empty()) // if (old_mailto.full())
// set_ini_var(CONFIG_INSTALL, "Main", "MailTo", old_mailto); // set_ini_var(CONFIG_INSTALL, "Main", "MailTo", old_mailto);
return ok; return ok;
@ -860,22 +910,22 @@ bool TMailer_mask::save_sheet_line(int& err, int nrow)
TToken_string& TMailer_mask::get_key1(int lf) const TToken_string& TMailer_mask::get_key1(int lf) const
{ {
TString_array& k1 = (TString_array&)_key1; // fool const; TString_array& k = (TString_array&)_key1; // Fool constness
if (k1.objptr(lf) == NULL) TToken_string* key = k.rowptr(lf);
if (key == NULL)
{ {
TLocalisamfile file(lf); key = new TToken_string; // Creo una nuova entry
const RecDes* recd = file.curr().rec_des(); // Descrizione del record della testata const RecDes& recd = prefix().get_recdes(lf); // Descrizione del record della testata
const KeyDes& kd = recd->Ky[0]; // Elenco dei campi della chiave 1 const KeyDes& kd = recd.Ky[0]; // Elenco dei campi della chiave 1
TToken_string key;
for (int i = 0; i < kd.NkFields; i++) for (int i = 0; i < kd.NkFields; i++)
{ {
const int nf = kd.FieldSeq[i] % MaxFields; const int nf = kd.FieldSeq[i] % MaxFields;
const RecFieldDes& rf = recd->Fd[nf]; const RecFieldDes& rf = recd.Fd[nf];
key.add(rf.Name); key->add(rf.Name);
} }
k1.add(key, lf); k.add(key, lf);
} }
return k1.row(lf); return *key;
} }
bool TMailer_mask::build_key1(int lf, const TString& body, TToken_string& key) const bool TMailer_mask::build_key1(int lf, const TString& body, TToken_string& key) const
@ -891,13 +941,13 @@ bool TMailer_mask::build_key1(int lf, const TString& body, TToken_string& key) c
field = fld; field.insert("\n"); field = fld; field.insert("\n");
const int start = body.find(field); const int start = body.find(field);
if (start < 0) if (start < 0)
return FALSE; return false;
const int equal = body.find('=', start); const int equal = body.find('=', start);
if (equal < 0) if (equal < 0)
return FALSE; return false;
const int stop = body.find('\n', equal); const int stop = body.find('\n', equal);
if (stop < 0) if (stop < 0)
return FALSE; return false;
value = body.sub(equal+1, stop); value = body.sub(equal+1, stop);
value.trim(); value.trim();
if (value[0] == '"' && value.right(1) == "\"") // Toglie eventuali virgolette if (value[0] == '"' && value.right(1) == "\"") // Toglie eventuali virgolette
@ -907,7 +957,27 @@ bool TMailer_mask::build_key1(int lf, const TString& body, TToken_string& key) c
} }
key.add(value); key.add(value);
} }
return TRUE; return true;
}
bool TMailer_mask::build_key1(const TMail_message& msg, TToken_string& key) const
{
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à è comune ed aggiunge il simbolino %
{
TString4 para; para << '[' << LF_TABCOM << ']';
if (body.find(para) > 0)
lfile = LF_TABCOM;
}
else
lfile = atoi(subj);
return build_key1(lfile, body, key);
} }
void TMailer_mask::find_redundant_messages() void TMailer_mask::find_redundant_messages()
@ -931,7 +1001,7 @@ void TMailer_mask::find_redundant_messages()
int lfile = LF_TAB; // Numero logico del file int lfile = LF_TAB; // Numero logico del file
if (isalpha(subj[0])) // Controlla se la tabella in realtà è comune ed aggiunge il simbolino % if (isalpha(subj[0])) // Controlla se la tabella in realtà è comune ed aggiunge il simbolino %
{ {
TString8 para; para << '[' << LF_TABCOM << ']'; TString4 para; para << '[' << LF_TABCOM << ']';
if (body.find(para) > 0) if (body.find(para) > 0)
lfile = LF_TABCOM; lfile = LF_TABCOM;
} }
@ -953,20 +1023,19 @@ void TMailer_mask::save_all_lines()
TBrowsefile_field& bf = (TBrowsefile_field&)field(F_LOG); TBrowsefile_field& bf = (TBrowsefile_field&)field(F_LOG);
TViswin& vv = bf.vis_win(); TViswin& vv = bf.vis_win();
TSheet_field& sf = sfield(F_MESSAGES); TString msg;
TString body, msg;
time_t tempo; time_t tempo; time(&tempo);
time(&tempo);
const struct tm* d = localtime(&tempo); const struct tm* d = localtime(&tempo);
msg.format("- Inizio elaborazione: %02d-%02d-%04d %02d:%02d:%02d", msg.format(FR("- Inizio elaborazione: %02d-%02d-%04d %02d:%02d:%02d"),
d->tm_mday, d->tm_mon+1, 1900+d->tm_year, d->tm_mday, d->tm_mon+1, 1900+d->tm_year,
d->tm_hour, d->tm_min, d->tm_sec); d->tm_hour, d->tm_min, d->tm_sec);
vv.add_line(msg); vv.add_line(msg);
find_redundant_messages(); find_redundant_messages();
bool one_saved = FALSE; bool one_saved = false;
TSheet_field& sf = sfield(F_MESSAGES);
FOR_EACH_SHEET_ROW(sf, nrow, row) FOR_EACH_SHEET_ROW(sf, nrow, row)
{ {
msg.format("Messaggio %d ", nrow+1); msg.format("Messaggio %d ", nrow+1);
@ -983,7 +1052,7 @@ void TMailer_mask::save_all_lines()
if (mark <= ' ') if (mark <= ' ')
{ {
row->get(sf.cid2index(F_BODY), body); TString body; row->get(sf.cid2index(F_BODY), body);
if (body.find("[Transaction]") >= 0) if (body.find("[Transaction]") >= 0)
{ {
int err = 0; int err = 0;
@ -991,7 +1060,7 @@ void TMailer_mask::save_all_lines()
if (yes) if (yes)
{ {
msg << "elaborato con successo"; msg << "elaborato con successo";
one_saved = TRUE; one_saved = true;
} }
else else
if (err == NOT_GEST) if (err == NOT_GEST)
@ -1070,7 +1139,7 @@ bool TMailer_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
if (e == se_query_add) if (e == se_query_add)
{ {
auto_save_all(); auto_save_all();
return FALSE; return false;
} }
break; break;
case DLG_USER: case DLG_USER:
@ -1080,16 +1149,16 @@ bool TMailer_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
if (!save_sheet_line(err)) if (!save_sheet_line(err))
{ {
if (err == NOT_TRANS) if (err == NOT_TRANS)
message_box("Messaggio ignorato in quanto transazione non riconosciuta"); message_box(TR("Messaggio ignorato: transazione non riconosciuta"));
else else
if (err == NOT_GEST) if (err == NOT_GEST)
{ {
TSheet_field& sf = sfield(F_MESSAGES); TSheet_field& sf = sfield(F_MESSAGES);
TMask& m = sf.sheet_mask(); TMask& m = sf.sheet_mask();
error_box("Definire il programma gestore del file %s", (const char*)m.get(F_SUBJECT)); error_box(FR("Definire il programma gestore del file %s"), (const char*)m.get(F_SUBJECT));
} }
else else
message_box("Messaggio non elaborato a causa di un errore (n.ro %d)", err); message_box(FR("Messaggio non elaborato a causa di un errore (n.ro %d)"), err);
} }
} }
@ -1110,7 +1179,7 @@ bool TMailer_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
{ {
test_delete(); test_delete();
fill_messages(); fill_messages();
return FALSE; return false;
} }
} }
break; break;
@ -1120,7 +1189,7 @@ bool TMailer_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
if (e == fe_button) if (e == fe_button)
{ {
TMask& m = o.mask(); TMask& m = o.mask();
TArray_sheet sht(-1,-1,-4,-4,"Selezione archivio", "Codice@6R|Descrizione archivio@70"); TArray_sheet sht(-1,-1,-4,-4,TR("Selezione archivio"), HR("Codice@6R|Descrizione archivio@70"));
const TPrefix& pref = prefix(); const TPrefix& pref = prefix();
const int total = pref.items(); const int total = pref.items();
if (total > 0) if (total > 0)
@ -1166,20 +1235,20 @@ bool TMailer_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
TBrowsefile_field& bf = (TBrowsefile_field&)field(F_LOG); TBrowsefile_field& bf = (TBrowsefile_field&)field(F_LOG);
TViswin& vv = bf.vis_win(); TViswin& vv = bf.vis_win();
vv.text().print(); vv.text().print();
return FALSE; // Don't close return false; // Don't close
} }
break; break;
default: default:
break; break;
} }
return TRUE; return true;
} }
void TMailer_mask::save_sheet(TConfig& ini, short dlg, const char* var) const void TMailer_mask::save_sheet(TConfig& ini, short dlg, const char* var) const
{ {
TSheet_field& sf = sfield(dlg); TSheet_field& sf = sfield(dlg);
FOR_EACH_SHEET_ROW(sf, r, row) FOR_EACH_SHEET_ROW(sf, r, row)
ini.set(var, *row, NULL, TRUE, r); ini.set(var, *row, NULL, true, r);
} }
void TMailer_mask::load_sheet(TConfig& ini, short dlg, const char* var) void TMailer_mask::load_sheet(TConfig& ini, short dlg, const char* var)
@ -1196,7 +1265,7 @@ void TMailer_mask::auto_save_all()
{ {
TSheet_field& sf = sfield(F_MESSAGES); TSheet_field& sf = sfield(F_MESSAGES);
#ifdef DBG #ifdef DBG
if (sf.items() > 0 && yesno_box("Si desidera eliminare i messaggi processati?")) if (sf.items() > 0 && yesno_box(TR("Si desidera eliminare i messaggi processati?")))
#endif #endif
test_delete(); test_delete();
fill_messages(); fill_messages();
@ -1236,6 +1305,7 @@ void TMailer_mask::save() const
ini.set("User", get(F_USER)); ini.set("User", get(F_USER));
ini.set("Password", encode(get(F_PASSWORD))); ini.set("Password", encode(get(F_PASSWORD)));
ini.set("Timer", get(F_TIMER)); ini.set("Timer", get(F_TIMER));
ini.set("Log", get(F_TRACKING));
save_sheet(ini, F_ADDRESSES, "Recipient"); save_sheet(ini, F_ADDRESSES, "Recipient");
save_sheet(ini, F_PARAMS, "Filter"); save_sheet(ini, F_PARAMS, "Filter");
} }
@ -1247,21 +1317,20 @@ void TMailer_mask::load()
set(F_USER, ini.get("User")); set(F_USER, ini.get("User"));
set(F_PASSWORD, decode(ini.get("Password"))); set(F_PASSWORD, decode(ini.get("Password")));
set(F_TIMER, ini.get_int("Timer")); set(F_TIMER, ini.get_int("Timer"));
set(F_TRACKING, ini.get("Log"));
load_sheet(ini, F_ADDRESSES, "Recipient"); load_sheet(ini, F_ADDRESSES, "Recipient");
load_sheet(ini, F_PARAMS, "Filter"); load_sheet(ini, F_PARAMS, "Filter");
_sequential = ini.get_bool("StopOnError", "ba7");
} }
TMailer_mask::TMailer_mask() TMailer_mask::TMailer_mask()
: TAutomask("ba7100a"), : TAutomask("ba7100a"), _timer_id(XVT_TIMER_ERROR), _mail_semaphore(0)
_timer_id(XVT_TIMER_ERROR), _mail_semaphore(0)
{ {
load(); load();
if (user() != ::dongle().administrator())
{ const bool is_super = user() == ::dongle().administrator();
disable(- G_SUPERUSER); enable(-G_SUPERUSER, is_super);
}
TConfig c(CONFIG_DITTA, "ba7");
_sequential = c.get_bool("StopOnError");
} }
TMailer_mask::~TMailer_mask() TMailer_mask::~TMailer_mask()
@ -1294,6 +1363,6 @@ void TMailer::main_loop()
int ba7100(int argc, char* argv[]) int ba7100(int argc, char* argv[])
{ {
TMailer app; TMailer app;
app.run(argc, argv, "Postino"); app.run(argc, argv, TR("Postino"));
return 0; return 0;
} }

View File

@ -3,6 +3,7 @@
#define F_PASSWORD 203 #define F_PASSWORD 203
#define F_MAPI 204 #define F_MAPI 204
#define F_TIMER 205 #define F_TIMER 205
#define F_TRACKING 206
#define F_MESSAGES 210 #define F_MESSAGES 210
#define F_ADDRESSES 211 #define F_ADDRESSES 211

View File

@ -1,6 +1,6 @@
#include "ba7100a.h" #include "ba7100a.h"
TOOLBAR "Toolbar" 0 -3 0 3 TOOLBAR "Toolbar" 0 -2 0 2
BUTTON DLG_SAVEREC 10 2 BUTTON DLG_SAVEREC 10 2
BEGIN BEGIN
@ -18,7 +18,7 @@ END
ENDPAGE ENDPAGE
PAGE "Ricezione" -1 -1 78 20 PAGE "Ricezione" 0 0 0 -2
BOOLEAN F_MAPI BOOLEAN F_MAPI
BEGIN BEGIN
@ -57,9 +57,14 @@ BEGIN
GROUP G_SUPERUSER GROUP G_SUPERUSER
END END
SPREADSHEET F_MESSAGES 0 -2 STRING F_TRACKING 256 55
BEGIN BEGIN
PROMPT 0 2 "" PROMPT 1 2 "Log transazioni (CSV) "
END
SPREADSHEET F_MESSAGES 0 -3
BEGIN
PROMPT 0 3 ""
ITEM "@1" ITEM "@1"
ITEM "Da@40" ITEM "Da@40"
ITEM "Data@10" ITEM "Data@10"
@ -81,7 +86,7 @@ END
ENDPAGE ENDPAGE
PAGE "Spedizione" -1 -1 78 20 PAGE "Spedizione" 0 0 0 -2
TEXT DLG_NULL TEXT DLG_NULL
BEGIN BEGIN
@ -114,9 +119,9 @@ END
ENDPAGE ENDPAGE
PAGE "Log" -1 -1 78 20 PAGE "Log" 0 0 0 -2
BROWSEFILE F_LOG 0 -3 BROWSEFILE F_LOG -1 -2
BEGIN BEGIN
PROMPT 0 1 "" PROMPT 0 1 ""
END END
@ -136,9 +141,9 @@ END
ENDPAGE ENDPAGE
ENDMASK ENDMASK
PAGE "Message" -1 -1 78 19 PAGE "Message" -1 -1 78 19
BOOLEAN F_CHECKED BOOLEAN F_CHECKED

View File

@ -9,7 +9,6 @@
#include <sheet.h> #include <sheet.h>
#include <utility.h> #include <utility.h>
#include <direct.h>
#include "ba7300.h" #include "ba7300.h"
class TFile_selector : public TAutomask class TFile_selector : public TAutomask
@ -525,7 +524,7 @@ void TMail_flood_app::send_records(TCursor& cur)
{ {
TFilename dir; dir.tempdir(); TFilename dir; dir.tempdir();
dir.add("transpos"); dir.add("transpos");
::mkdir(dir); make_dir(dir);
const TRectype& curr = cur.curr(); const TRectype& curr = cur.curr();
@ -561,7 +560,7 @@ void TMail_flood_app::send_records(TCursor& cur)
ininame << SLASH << "tr" << i << ".ini"; ininame << SLASH << "tr" << i << ".ini";
::remove(ininame); ::remove(ininame);
} }
::rmdir(dir); xvt_fsys_rmdir(dir);
} }
void TMail_flood_app::fill_rows(const TRectype& parent, int logicnum, TConfig& ini) const void TMail_flood_app::fill_rows(const TRectype& parent, int logicnum, TConfig& ini) const

View File

@ -37,7 +37,7 @@ bool TInstall_SV ::install_com()
// riconverte le macro delle date // riconverte le macro delle date
tabstd.dump(tempfile); tabstd.dump(tempfile);
TScanner scan(tempfile); TScanner scan(tempfile);
FILE *dest=fopen((const char *)stdtabname,"w"); FILE* dest = fopen(stdtabname,"w");
while (TRUE) { while (TRUE) {
TString &line=scan.line(); TString &line=scan.line();
if (line.empty()) break; if (line.empty()) break;