////////////////////////////////////////////////////////////////////////// EmailReportTo - send only the relevant portions of the report the address //////////////////////////////////////////////////////////////////////////
| 544 | // |
| 545 | /////////////////////////////////////////////////////////////////////////////// |
| 546 | static 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 | } |
no test coverage detected