HsInt primCopyFile(char* from, char* to) { #ifndef _WIN32 /* Don't even try to re-implement the functionality of cp(1) -- it would have been nice to have its functionality available as an API though.. */ char* stuff; char* ptr; int i; stuff = (char*)alloca(sizeof(char) * (strlen(from) + strlen(to) + 6)); /* Construct the string: ("cp " ++ from ++ ' ':to) */ strcpy(stuff, "cp "); /* It better be called 'cp' ! */ i = 3; ptr = from; while (*ptr) { stuff[i++] = *ptr++; } stuff[i++] = ' '; ptr = to; while (*ptr) { stuff[i++] = *ptr++; } stuff[i] = '\0'; return systemCmd(stuff); #else return CopyFile(from,to,TRUE/*fail if exists*/); #endif }
// send the mail - SMTP void CSCMail::sendFileText(const std::string& fileName, bool text=true) { TraceNoise("CSCMail::sendFileText", fileName.c_str(), 0); // metasend -b -e 7bit -f /home/sc/alert.html -F "Site Confidence Web Monitoring <*****@*****.**>" // -s Alert -m "text/html" -t [email protected] std::string systemCmd("/usr/bin/metasend -S 10000000 -b -e 7bit -F \""); systemCmd += m_fromEMail; systemCmd += "\" -m \"text/html\" "; if (text) { systemCmd += " -E "; } // add to people if (!m_to.empty()) { systemCmd += " -t \""; } systemCmd += getEmailsString(m_to); if (!m_to.empty()) { systemCmd += "\""; } if (!m_cc.empty()) { systemCmd += " -c \""; } systemCmd += getEmailsString(m_cc); if (!m_cc.empty()) { systemCmd += "\""; } systemCmd += " -s \""; systemCmd += m_subject; systemCmd += "\" "; systemCmd += " -f "; systemCmd += fileName; if (CConfig::isMailEnabled() && !(m_to.empty() && m_cc.empty())) { // send mail... Trace("Sending Email", systemCmd.c_str(), 0); system(systemCmd.c_str()); } else if (!CConfig::isMailEnabled()) { LogError("MAIL Disabled by file mail.disable in opt.", systemCmd.c_str(),0); } else if (!(m_to.empty() && m_cc.empty())) { LogError("MAIL not sent as no recipients.", systemCmd.c_str(),0); } else { LogError("MAIL not sent for some other reason.", systemCmd.c_str(),0); } }
// send the mail - SMTP void CSCMail::send(bool text) { TraceNoise("CSCMail::send", "", int(text)); // metasend -b -e 7bit -f /home/sc/alert.html -F "Site Confidence Web Monitoring <*****@*****.**>" // -s Alert -m "text/html" -t [email protected] char tmpName[] = TMP_WTT_MAIL_FILENAME; int filePtr; // create temp output file if ((filePtr = mkstemp(tmpName)) == -1) { // can't create file - just send nothing LogError("CSCMail::send()", "Unable to create temp file", 0); strcpy(tmpName, "/dev/null"); } else { // output the body to the file write(filePtr, m_body.c_str(), m_body.size()); close(filePtr); } Trace("Temp file name", tmpName, 0); std::string systemCmd("/usr/bin/metasend -S 10000000 -b -e 7bit -F \""); systemCmd += m_fromEMail; systemCmd += "\" -m \"text/html\" "; if (text) { systemCmd += " -E "; } // add to people if (!m_to.empty()) { systemCmd += " -t \""; } systemCmd += getEmailsString(m_to); if (!m_to.empty()) { systemCmd += "\""; } if (!m_cc.empty()) { systemCmd += " -c \""; } systemCmd += getEmailsString(m_cc); if (!m_cc.empty()) { systemCmd += "\""; } systemCmd += " -s \""; systemCmd += m_subject; systemCmd += "\" "; systemCmd += " -f "; systemCmd += tmpName; if (CConfig::isMailEnabled() && !(m_to.empty() && m_cc.empty())) { // send mail... Trace("Sending Email", systemCmd.c_str(), 0); system(systemCmd.c_str()); } else if (!CConfig::isMailEnabled()) { LogError("MAIL Disabled by file mail.disable in opt.", systemCmd.c_str(),0); } else if (m_to.empty() && m_cc.empty()) { LogError("MAIL not sent as no recipients.", systemCmd.c_str(),0); } else { LogError("MAIL not sent for some other reason.", systemCmd.c_str(),0); } // remove temp file unlink(tmpName); }
// send the mail - using mutt for attachments void CSCMail::sendAttach() { TraceNoise("CSCMail::sendAttach", "", 0); // mutt -x -a <filename> -b <blind> -s <subj> <addr>" // -s Alert -m "text/html" -t [email protected] char tmpName[] = TMP_WTT_MAIL_FILENAME; int filePtr; // create temp output file if ((filePtr = mkstemp(tmpName)) == -1) { // can't create file - just send nothing LogError("CSCMail::send()", "Unable to create temp file", 0); strcpy(tmpName, "/dev/null"); } else { // output the body to the file write(filePtr, m_body.c_str(), m_body.size()); close(filePtr); } Trace("Temp file name", tmpName, 0); // add file std::string systemCmd("mutt -x "); // add subject systemCmd += " -s \""; systemCmd += m_subject; systemCmd += "\" "; // add filename if (m_attFileName.length() != 0) { systemCmd += " -a "; systemCmd += m_attFileName; systemCmd += " "; } // add cc people if (!m_cc.empty()) { systemCmd += " -c \""; } systemCmd += getEmailsString(m_cc); if (!m_cc.empty()) { systemCmd += "\""; } // add bcc people if (!m_bcc.empty()) { systemCmd += " -b \""; } systemCmd += getEmailsString(m_bcc); if (!m_bcc.empty()) { systemCmd += "\""; } // add to people systemCmd += " \""; systemCmd += getEmailsString(m_to); systemCmd += "\""; // send empty file systemCmd += " < "; systemCmd += tmpName; if (CConfig::isMailEnabled() && !(m_to.empty() && m_cc.empty())) { // send mail... Trace("Sending Email", systemCmd.c_str(), 0); system(systemCmd.c_str()); } else if (!CConfig::isMailEnabled()) { LogError("MAIL Disabled by file mail.disable in opt.", systemCmd.c_str(),0); } else if (m_to.empty() && m_cc.empty()) { LogError("MAIL not sent as no recipients.", systemCmd.c_str(),0); } else { LogError("MAIL not sent for some other reason.", systemCmd.c_str(),0); } // remove temp file unlink(tmpName); }