Authentication-Results: mail-b.sr.ht; dkim=pass header.d=timculverhouse.com header.i=@timculverhouse.com; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by mail-b.sr.ht (Postfix) with ESMTPS id 9F73D11EEE2 for <~rockorager/offmap@lists.sr.ht>; Wed, 30 Nov 2022 16:55:54 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 82EFC5C0167; Wed, 30 Nov 2022 11:55:54 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 30 Nov 2022 11:55:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= timculverhouse.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to; s=fm1; t=1669827354; x=1669913754; bh=dp /YJ7IM+pVmkDi3HZMeqwAf5TyZDSiH0gr/u5hAV2U=; b=Mxo/4QmGcPDvBMKwE6 vOsY+d2FK1yyStaj84Soqe4ogvgEf6IKhVwEqUwj0ACCuW5SBMMLQaq9/Xj0UAVN 436hc1mOtB0nZg3ALtQqioMOCVv3iF5x9mzL4nN7ehqCMBsX6aLzJvnPfR01mQrz V8qVl39IxlqQ358qFZXPo8gVWMqoHBALju+8TySIE/00i2pXFqC0vkDtkP50Ph6v gQXV4F6Ycc4rz/PyF+vSzvuLdnw8+aQsu5CZKAKwgPT/hrsq0x/ralML4q53w8qh SeNAw1CmuYhBBETLlGzILnmm04yM9nHXV3Vygfom3koZ67hreAjYnh+9KAq5WH/i VxlA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1669827354; x=1669913754; bh=dp/YJ7IM+pVmkDi3HZMeqwAf5TyZDSiH0gr /u5hAV2U=; b=a4Vt+pzrjqvrkU6HQplgznOK0Urvf3R8bIV5kdVQuyZOVteXuYR mLTEgDZm65IbIJkstwfRr7jYUXLCOkw84LLz4Tpb369n8ZNjqV8btWUwnB+0DdXm pIi2V71xXIlD/2iLWsT+Zo5bNB1UHP8FShyZKbmxdlXv7LJNNuXAXLgFZk5K83Cg u2Yjopq6P9rtQvpqpfqvCB0L3hpsDOcTAxSx7DKy8wkxl6n2RWtyMQg+lE6KuXBz Y38YsMQmI+H+zJQBTC/AY+loku6JG4/RglQNIOB79eTGRAJqhcY+GptI+Jn+d2wq 8mi9eQQT3DTyLy8r/dR3Og48bynHZH4L5bw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrtdefgdelfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgggfestdekredtre dttdenucfhrhhomhepvfhimhcuvehulhhvvghrhhhouhhsvgcuoehtihhmsehtihhmtghu lhhvvghrhhhouhhsvgdrtghomheqnecuggftrfgrthhtvghrnhepffevkefgfeeluefghe dujeefgffhgfeijeelhfeltdefteetgffhlefgheegjefgnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhimhesthhimhgtuhhlvhgvrhhhoh hushgvrdgtohhm X-ME-Proxy: Feedback-ID: i3ad947a1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 30 Nov 2022 11:55:54 -0500 (EST) From: Tim Culverhouse To: ~rockorager/offmap@lists.sr.ht Cc: Tim Culverhouse Subject: [PATCH offmap v2] password-cmd: support a password command Date: Wed, 30 Nov 2022 10:55:48 -0600 Message-Id: <20221130165548.108436-1-tim@timculverhouse.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Support using a command which returns the password. Update documentation. Signed-off-by: Tim Culverhouse --- doc/offmap.5.scd | 9 +++++++-- imap/imap.go | 21 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/doc/offmap.5.scd b/doc/offmap.5.scd index f7913d58e2ce..a958c74f0fcf 100644 --- a/doc/offmap.5.scd +++ b/doc/offmap.5.scd @@ -35,8 +35,13 @@ password = "my-password" *username* (required) The username to login to the IMAP server with. -*password* (required) - The password to use for the IMAP server. +*password* (optional) + The password to use for the IMAP server. Either this or *password-cmd* + are required. + +*password-cmd* (optional) + A command to run which returns the password. Either this or *password* + are required. *max-connections* (optional) The maximum number of IMAP clients to spawn. Some providers limit the diff --git a/imap/imap.go b/imap/imap.go index be500ecd4277..626be2f7528a 100644 --- a/imap/imap.go +++ b/imap/imap.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "os" + "os/exec" "path" "strconv" "strings" @@ -51,11 +52,25 @@ func NewStore(cfg *viper.Viper) (*Store, error) { if store.username == "" { return nil, fmt.Errorf("imap: no username set") } - // TODO support password commands - store.password = cfg.GetString("password") - if store.password == "" { + + switch { + case cfg.GetString("password-cmd") != "": + cmd := exec.Command("sh", "-c", cfg.GetString("password-cmd")) + out, err := cmd.Output() + if err != nil { + return nil, fmt.Errorf("imap: could not get password: %v", err) + } + lines := strings.Split(string(out), "\n") + if len(lines) < 1 { + return nil, fmt.Errorf("imap: no output from password-cmd") + } + store.password = lines[0] + case cfg.GetString("password") != "": + store.password = cfg.GetString("password") + default: return nil, fmt.Errorf("imap: no password set") } + store.maxConns = cfg.GetInt("max-connections") if store.maxConns < 1 { store.maxConns = 2 -- 2.38.1