imap-send: enable specifying the folder using the command line

Some users may very often want to imap-send messages to a folder other than the default set in the config. Add a command line argument for the same. While at it, fix minor mark-up inconsistencies in the existing documentation text. Signed-off-by: Aditya Garg <gargaditya08@live.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Aditya Garg committed Jun 20, 2025 at 12:10 UTC 3168514e6b72668d699ae192f6492cddb4eebb4a
3 files changed +23 -7
Documentation/config/imap.adoc
+4 -2
@@ -1,7 +1,9 @@
1 imap.folder::
2 The folder to drop the mails into, which is typically the Drafts
3 - folder. For example: "INBOX.Drafts", "INBOX/Drafts" or
4 - "[Gmail]/Drafts". Required.
3 + folder. For example: `INBOX.Drafts`, `INBOX/Drafts` or
4 + `[Gmail]/Drafts`. The IMAP folder to interact with MUST be specified;
5 + the value of this configuration variable is used as the fallback
6 + default value when the `--folder` option is not given.
7
8 imap.tunnel::
9 Command used to set up a tunnel to the IMAP server through which
Documentation/git-imap-send.adoc
+11 -4
@@ -9,21 +9,23 @@ git-imap-send - Send a collection of patches from stdin to an IMAP folder
9 SYNOPSIS
10 --------
11 [verse]
12 -'git imap-send' [-v] [-q] [--[no-]curl]
12 +'git imap-send' [-v] [-q] [--[no-]curl] [(--folder|-f) <folder>]
13
14
15 DESCRIPTION
16 -----------
17 -This command uploads a mailbox generated with 'git format-patch'
17 +This command uploads a mailbox generated with `git format-patch`
18 into an IMAP drafts folder. This allows patches to be sent as
19 other email is when using mail clients that cannot read mailbox
20 files directly. The command also works with any general mailbox
21 -in which emails have the fields "From", "Date", and "Subject" in
21 +in which emails have the fields `From`, `Date`, and `Subject` in
22 that order.
23
24 Typical usage is something like:
25
26 -git format-patch --signoff --stdout --attach origin | git imap-send
26 +------
27 +$ git format-patch --signoff --stdout --attach origin | git imap-send
28 +------
29
30
31 OPTIONS
@@ -37,6 +39,11 @@ OPTIONS
39 --quiet::
40 Be quiet.
41
42 +-f <folder>::
43 +--folder=<folder>::
44 + Specify the folder in which the emails have to saved.
45 + For example: `--folder=[Gmail]/Drafts` or `-f INBOX/Drafts`.
46 +
47 --curl::
48 Use libcurl to communicate with the IMAP server, unless tunneling
49 into it. Ignored if Git was built without the USE_CURL_FOR_IMAP_SEND
imap-send.c
+8 -1
@@ -46,12 +46,14 @@
46
47 static int verbosity;
48 static int use_curl = USE_CURL_DEFAULT;
49 +static char *opt_folder;
50
50 -static const char * const imap_send_usage[] = { "git imap-send [-v] [-q] [--[no-]curl] < <mbox>", NULL };
51 +static const char * const imap_send_usage[] = { "git imap-send [-v] [-q] [--[no-]curl] [(--folder|-f) <folder>] < <mbox>", NULL };
52
53 static struct option imap_send_options[] = {
54 OPT__VERBOSITY(&verbosity),
55 OPT_BOOL(0, "curl", &use_curl, "use libcurl to communicate with the IMAP server"),
56 + OPT_STRING('f', "folder", &opt_folder, "folder", "specify the IMAP folder"),
57 OPT_END()
58 };
59
@@ -1722,6 +1724,11 @@ int cmd_main(int argc, const char **argv)
1724
1725 argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0);
1726
1727 + if (opt_folder) {
1728 + free(server.folder);
1729 + server.folder = xstrdup(opt_folder);
1730 + }
1731 +
1732 if (argc)
1733 usage_with_options(imap_send_usage, imap_send_options);
1734