diff --git a/src/xvaga/xvaga.cpp b/src/xvaga/xvaga.cpp index 92a965a57..fcbac12ce 100755 --- a/src/xvaga/xvaga.cpp +++ b/src/xvaga/xvaga.cpp @@ -3855,7 +3855,9 @@ BOOLEAN xvt_fsys_dir_exists(const char *pathname) BOOLEAN xvt_fsys_file_exists(const char *pathname) { - return xvt_fsys_access(pathname, 0) == 0; + int err = xvt_fsys_access(pathname, 0); + // Ritorno true se non ho trovato errori o non ho l'accesso al file (potrebbe essere anche bloccato) + return err == 0 || err == EACCES; } BOOLEAN xvt_fsys_mkdir(const char *pathname) diff --git a/src/xvaga/xvt.h b/src/xvaga/xvt.h index f6285e1d8..b136053d8 100755 --- a/src/xvaga/xvt.h +++ b/src/xvaga/xvt.h @@ -552,8 +552,12 @@ XVTDLL void xvt_treelist_set_node_images(WINDOW win, XVT_TREEVIEW_N XVTDLL void xvt_treelist_set_node_string(WINDOW win, XVT_TREEVIEW_NODE node, const char* text); XVTDLL void xvt_treelist_suspend(WINDOW win); +// Send email using normal methods XVTDLL BOOLEAN xvt_mail_send(const char* to, const char* cc, const char* ccn, const char* subject, const char* msg, const char* attach, short flags); // 0x1=UI; 0x2=Receipt +// Send email using Microsoft Powershell +XVTDLL BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, + const char* subject, const char* msg, const char* attach, short flags, const char* usr); // 0x1=UI; 0x2=Receipt XVTDLL short xvt_mail_installed(); XVTDLL void xvt_btn_set_images(WINDOW win, XVT_IMAGE up, XVT_IMAGE down); diff --git a/src/xvaga/xvtmail.cpp b/src/xvaga/xvtmail.cpp index 974b2b33f..856c076a1 100755 --- a/src/xvaga/xvtmail.cpp +++ b/src/xvaga/xvtmail.cpp @@ -278,4 +278,95 @@ BOOLEAN xvt_mail_send(const char* to, const char* cc, const char* ccn, } return ok; +} + +BOOLEAN xvt_powermail_send(const char* to, const char* cc, const char* ccn, + const char* subject, const char* msg, + const char* attach, short flags, const char* usr) +{ + wxString server, port, user, password, from; + // Controllo che Windows sia almeno 8 e che riesca a ricevere i parametri E-mail + if(xvt_sys_get_os_version() < XVT_WS_WIN_8 || !GetMailParams(server, port, user, password, from)) + xvt_mail_send(to, cc, ccn, subject, msg, attach, flags); + + DIRECTORY tmp; xvt_fsys_get_temp_dir(&tmp); + // Per togliere il rischio di sovrapposizioni vado nella cartella dell'utente + wxString userTemp; userTemp << tmp.path << "\\" << usr; + + wxString powerFile; + static int powerNumber = 0; + wxString powerName = "powermail_"; powerName << ++powerNumber; + xvt_fsys_build_pathname(powerFile.GetWriteBuf(_MAX_PATH), NULL, userTemp, powerName, "ps1", NULL); + powerFile.UngetWriteBuf(); + + // Creo il file + wxFile file(powerFile, wxFile::write); + + // Hard code and no play makes Tolla a dull programmer + file.Write("$Server = \""); file.Write(server); file.Write("\";\n"); + wxStringTokenizer portTok(port, " "); + file.Write("$Port = \""); file.Write(portTok.GetNextToken()); file.Write("\";\n"); + file.Write("$SSL = "); + if(portTok.GetNextToken().Upper() == "-SSL") + file.Write("$true"); + else + file.Write("$false"); + file.Write("\n"); + file.Write("$Username = \""); file.Write(user); file.Write("\";\n"); + file.Write("$Password = \""); file.Write(password); file.Write("\";\n"); + file.Write("$From = \""); file.Write(from); file.Write("\";\n"); + file.Write("$To = \""); file.Write(to); file.Write("\";\n"); + file.Write("$Subject = \""); file.Write(subject); file.Write("\";\n"); + file.Write("$Body = \""); file.Write(msg); file.Write("\";\n"); + file.Write( + "$message = new-object Net.Mail.MailMessage;\n" + "$message.From = $From\n" + "$message.To.Add($To);\n" +#ifndef DBG + "$message.Bcc.Add($From);\n" +#endif + "$message.Subject = $Subject;\n" + "$message.Body = $Body;\n" + ); + + // Aggiungo a schiena gli allegati + if (attach && *attach) + { + wxStringTokenizer tokAttach(attach, _T(";")); + int i = 0; + while (tokAttach.HasMoreTokens()) + { + wxString attachmentLine; + attachmentLine << "$attach" << ++i << "= New-Object Net.Mail.Attachment(\"" + << tokAttach.GetNextToken() << "\");\n" << "$message.Attachments.Add(" + << "$attach" << i << ");\n"; + file.Write(attachmentLine); + } + } + + file.Write( + "$smtp = new-object Net.Mail.SmtpClient($Server, $Port);\n" + "$smtp.EnableSSL = $SSL;\n" + "$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);\n" + "$exitCode = 1\n" + "try\n" + "{\n" + " $smtp.send($message);\n" + " write-host \"E-Mail sent\" ; \n" + " exit 1\n" + "}\n" + "catch\n" + "{\n" + " write-host \"E-Mail not sent\" ; \n" + " $exitCode = 0\n" + "}\n" + "$host.SetShouldExit($exitCode);\n" + ); + file.Close(); + + wxString command; + command << "PowerShell -NonInteractive -NoProfile -Command \"& {"<< powerFile <<"; exit $LastExitCode }\""; + + int exitCode = system(command); + return exitCode; } \ No newline at end of file