MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / EmailReportTo

Function EmailReportTo

src/tripwire/twcmdlineutil.cpp:546–632  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// EmailReportTo - send only the relevant portions of the report the address //////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

544//
545///////////////////////////////////////////////////////////////////////////////
546static bool EmailReportTo(const TSTRING& toAddress,
547 const cFCOReportHeader& header,
548 const cFCOReport& report,
549 const cTWModeCommon* modeCommon,
550 const bool bForceFullReport)
551{
552 TW_UNIQUE_PTR<cMailMessage> reportMail;
553
554 // allocate the right kind of emailer object based on what came out of the config file.
555 switch (modeCommon->mMailMethod)
556 {
557#if SUPPORTS_NETWORKING
558 case cMailMessage::MAIL_BY_SMTP:
559 reportMail = TW_UNIQUE_PTR<cMailMessage>(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort));
560 break;
561#endif
562 case cMailMessage::MAIL_BY_PIPE:
563 reportMail = TW_UNIQUE_PTR<cMailMessage>(new cPipedMailMessage(modeCommon->mMailProgram));
564 break;
565 default:
566 return false;
567 }
568
569 TSTRING strTempFilename;
570
571 // send the report
572 try
573 {
574 // we have to write the text report to a temporary file...
575 iFSServices::GetInstance()->GetTempDirName(strTempFilename);
576 strTempFilename += _T("tripwire-report-XXXXXX");
577 iFSServices::GetInstance()->MakeTempFilename(strTempFilename);
578 strTempFilename += _T(".txt");
579
580 // print the report
581 cEmailReportViewer trv(header, report, toAddress, bForceFullReport);
582 trv.PrintTextReport(strTempFilename, modeCommon->mEmailReportLevel);
583
584 // format the subject line with number of violations and the most severe violation found
585 // set up the cMailMessage class, and send it if they need it or want it
586 // (Yes, it seems odd to generate the report, only to potentially delete it without sending it.)
587 if (trv.GetNumberViolations() > 0 || modeCommon->mMailNoViolations)
588 {
589 // print message that we're emailing to this specific recipient
590 iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL,
591 _T("%s %s\n"),
592 TSS_GetString(cTripwire, tripwire::STR_EMAIL_REPORT_TO).c_str(),
593 cDisplayEncoder::EncodeInline(toAddress).c_str());
594 reportMail->AddRecipient(toAddress);
595
596 if (!modeCommon->mMailFrom.empty())
597 reportMail->SetFrom(modeCommon->mMailFrom);
598 else
599 {
600 TSTRING machineName;
601 iFSServices::GetInstance()->GetMachineNameFullyQualified(machineName);
602 reportMail->SetFrom(TSS_GetString(cTripwire, tripwire::STR_EMAIL_FROM) + machineName);
603 }

Callers 1

DoEmailReportsFunction · 0.85

Calls 15

GetTempDirNameMethod · 0.80
PrintTextReportMethod · 0.80
GetNumberViolationsMethod · 0.80
NotifyMethod · 0.80
c_strMethod · 0.80
AddRecipientMethod · 0.80
emptyMethod · 0.80
SetFromMethod · 0.80
SetFromNameMethod · 0.80
SetSubjectMethod · 0.80
SingleLineReportMethod · 0.80

Tested by

no test coverage detected