/*
* This file is part of mailpot
*
* Copyright 2020 - Manos Pitsidianakis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
pub use std::path::PathBuf;
pub use clap::{builder::TypedValueParser, Args, CommandFactory, Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(
name = "mpot",
about = "mailing list manager",
long_about = "Tool for mailpot mailing list management.",
before_long_help = "GNU Affero version 3 or later ",
author,
version
)]
pub struct Opt {
/// Print logs.
#[arg(short, long)]
pub debug: bool,
/// Configuration file to use.
#[arg(short, long, value_parser)]
pub config: Option,
#[command(subcommand)]
pub cmd: Command,
/// Silence all output.
#[arg(short, long)]
pub quiet: bool,
/// Verbose mode (-v, -vv, -vvv, etc).
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
/// Debug log timestamp (sec, ms, ns, none).
#[arg(short, long)]
pub ts: Option,
}
#[derive(Debug, Subcommand)]
pub enum Command {
/// Prints a sample config file to STDOUT.
///
/// You can generate a new configuration file by writing the output to a
/// file, e.g: mpot sample-config --with-smtp > config.toml
SampleConfig {
/// Use an SMTP connection instead of a shell process.
#[arg(long)]
with_smtp: bool,
},
/// Dumps database data to STDOUT.
DumpDatabase,
/// Lists all registered mailing lists.
ListLists,
/// Mailing list management.
List {
/// Selects mailing list to operate on.
list_id: String,
#[command(subcommand)]
cmd: ListCommand,
},
/// Create new list.
CreateList {
/// List name.
#[arg(long)]
name: String,
/// List ID.
#[arg(long)]
id: String,
/// List e-mail address.
#[arg(long)]
address: String,
/// List description.
#[arg(long)]
description: Option,
/// List archive URL.
#[arg(long)]
archive_url: Option,
},
/// Post message from STDIN to list.
Post {
/// Show e-mail processing result without actually consuming it.
#[arg(long)]
dry_run: bool,
},
/// Flush outgoing e-mail queue.
FlushQueue {
/// Show e-mail processing result without actually consuming it.
#[arg(long)]
dry_run: bool,
},
/// Mail that has not been handled properly end up in the error queue.
ErrorQueue {
#[command(subcommand)]
cmd: QueueCommand,
},
/// Mail that has not been handled properly end up in the error queue.
Queue {
#[arg(long, value_parser = QueueValueParser)]
queue: mailpot::queue::Queue,
#[command(subcommand)]
cmd: QueueCommand,
},
/// Import a maildir folder into an existing list.
ImportMaildir {
/// List-ID or primary key value.
list_id: String,
/// Path to a maildir mailbox.
/// Must contain {cur, tmp, new} folders.
#[arg(long, value_parser)]
maildir_path: PathBuf,
},
/// Update postfix maps and master.cf (probably needs root permissions).
UpdatePostfixConfig {
#[arg(short = 'p', long)]
/// Override location of master.cf file (default:
/// /etc/postfix/master.cf)
master_cf: Option,
#[clap(flatten)]
config: PostfixConfig,
},
/// Print postfix maps and master.cf entry to STDOUT.
///
/// Map output should be added to transport_maps and local_recipient_maps
/// parameters in postfix's main.cf. It must be saved in a plain text
/// file. To make postfix be able to read them, the postmap application
/// must be executed with the path to the map file as its sole argument.
///
/// postmap /path/to/mylist_maps
///
/// postmap is usually distributed along with the other postfix binaries.
///
/// The master.cf entry must be manually appended to the master.cf file. See .
PrintPostfixConfig {
#[clap(flatten)]
config: PostfixConfig,
},
/// All Accounts.
Accounts,
/// Account info.
AccountInfo {
/// Account address.
address: String,
},
/// Add account.
AddAccount {
/// E-mail address.
#[arg(long)]
address: String,
/// SSH public key for authentication.
#[arg(long)]
password: String,
/// Name.
#[arg(long)]
name: Option,
/// Public key.
#[arg(long)]
public_key: Option,
#[arg(long)]
/// Is account enabled.
enabled: Option,
},
/// Remove account.
RemoveAccount {
#[arg(long)]
/// E-mail address.
address: String,
},
/// Update account info.
UpdateAccount {
/// Address to edit.
address: String,
/// Public key for authentication.
#[arg(long)]
password: Option,
/// Name.
#[arg(long)]
name: Option