From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id CDFE1695BB
 for <pbs-devel@lists.proxmox.com>; Thu, 11 Mar 2021 09:25:25 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id C0A4C24D0C
 for <pbs-devel@lists.proxmox.com>; Thu, 11 Mar 2021 09:24:55 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 8591624CFF
 for <pbs-devel@lists.proxmox.com>; Thu, 11 Mar 2021 09:24:54 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5008F46280
 for <pbs-devel@lists.proxmox.com>; Thu, 11 Mar 2021 09:24:54 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Thu, 11 Mar 2021 09:24:52 +0100
Message-Id: <20210311082453.17920-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.192 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pbs-devel] [PATCH proxmox-backup v2 1/2]
 tape/send_load_media_email: move to server/email_notifications
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 11 Mar 2021 08:25:25 -0000

and reuse 'send_job_status_mail' there so that we get consistent
formatted mails from pbs (e.g. html part and author)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* better commit subject/message
* move code to email related module
* do not make send_job_status_mail pub

 src/server/email_notifications.rs | 24 +++++++++++++++++++++
 src/tape/changer/email.rs         | 36 -------------------------------
 src/tape/changer/mod.rs           |  3 ---
 src/tape/drive/mod.rs             |  6 ++++--
 4 files changed, 28 insertions(+), 41 deletions(-)
 delete mode 100644 src/tape/changer/email.rs

diff --git a/src/server/email_notifications.rs b/src/server/email_notifications.rs
index 306e84d0..229443f6 100644
--- a/src/server/email_notifications.rs
+++ b/src/server/email_notifications.rs
@@ -448,6 +448,30 @@ pub fn send_tape_backup_status(
     Ok(())
 }
 
+/// Send email to a person to request a manual media change
+pub fn send_load_media_email(
+    drive: &str,
+    label_text: &str,
+    to: &str,
+    reason: Option<String>,
+) -> Result<(), Error> {
+
+    let subject = format!("Load Media '{}' request for drive '{}'", label_text, drive);
+
+    let mut text = String::new();
+
+    if let Some(reason) = reason {
+        text.push_str(&format!("The drive has the wrong or no tape inserted. Error:\n{}\n\n", reason));
+    }
+
+    text.push_str("Please insert the requested media into the backup drive.\n\n");
+
+    text.push_str(&format!("Drive: {}\n", drive));
+    text.push_str(&format!("Media: {}\n", label_text));
+
+    send_job_status_mail(to, &subject, &text)
+}
+
 fn get_server_url() -> (String, usize) {
 
     // user will surely request that they can change this
diff --git a/src/tape/changer/email.rs b/src/tape/changer/email.rs
deleted file mode 100644
index abd7ead8..00000000
--- a/src/tape/changer/email.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-use anyhow::Error;
-
-use proxmox::tools::email::sendmail;
-
-/// Send email to a person to request a manual media change
-pub fn send_load_media_email(
-    drive: &str,
-    label_text: &str,
-    to: &str,
-    reason: Option<String>,
-) -> Result<(), Error> {
-
-    let subject = format!("Load Media '{}' request for drive '{}'", label_text, drive);
-
-    let mut text = String::new();
-
-    if let Some(reason) = reason {
-        text.push_str(&format!("The drive has the wrong or no tape inserted. Error:\n{}\n\n", reason));
-    }
-
-    text.push_str("Please insert the requested media into the backup drive.\n\n");
-
-    text.push_str(&format!("Drive: {}\n", drive));
-    text.push_str(&format!("Media: {}\n", label_text));
-
-    sendmail(
-        &[to],
-        &subject,
-        Some(&text),
-        None,
-        None,
-        None,
-    )?;
-
-    Ok(())
-}
diff --git a/src/tape/changer/mod.rs b/src/tape/changer/mod.rs
index 1e58a437..a25df49b 100644
--- a/src/tape/changer/mod.rs
+++ b/src/tape/changer/mod.rs
@@ -1,8 +1,5 @@
 //! Media changer implementation (SCSI media changer)
 
-mod email;
-pub use email::*;
-
 pub mod sg_pt_changer;
 
 pub mod mtx;
diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs
index a386abf8..1267a481 100644
--- a/src/tape/drive/mod.rs
+++ b/src/tape/drive/mod.rs
@@ -51,7 +51,10 @@ use crate::{
         VirtualTapeDrive,
         LinuxTapeDrive,
     },
-    server::WorkerTask,
+    server::{
+        send_load_media_email,
+        WorkerTask,
+    },
     tape::{
         TapeWrite,
         TapeRead,
@@ -66,7 +69,6 @@ use crate::{
         changer::{
             MediaChange,
             MtxMediaChanger,
-            send_load_media_email,
         },
     },
 };
-- 
2.20.1