Skip to content

Commit abaa69f

Browse files
AdityaGarg8gitster
authored andcommitted
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. Signed-off-by: Aditya Garg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2c75b6 commit abaa69f

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

Documentation/config/imap.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
imap.folder::
22
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.
57

68
imap.tunnel::
79
Command used to set up a tunnel to the IMAP server through which

Documentation/git-imap-send.adoc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ git-imap-send - Send a collection of patches from stdin to an IMAP folder
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git imap-send' [-v] [-q] [--[no-]curl]
12+
'git imap-send' [-v] [-q] [--[no-]curl] [(--folder|-f) <folder>]
1313

1414

1515
DESCRIPTION
1616
-----------
17-
This command uploads a mailbox generated with 'git format-patch'
17+
This command uploads a mailbox generated with `git format-patch`
1818
into an IMAP drafts folder. This allows patches to be sent as
1919
other email is when using mail clients that cannot read mailbox
2020
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
2222
that order.
2323

2424
Typical usage is something like:
2525

26-
git format-patch --signoff --stdout --attach origin | git imap-send
26+
------
27+
$ git format-patch --signoff --stdout --attach origin | git imap-send
28+
------
2729

2830

2931
OPTIONS
@@ -37,6 +39,11 @@ OPTIONS
3739
--quiet::
3840
Be quiet.
3941

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+
4047
--curl::
4148
Use libcurl to communicate with the IMAP server, unless tunneling
4249
into it. Ignored if Git was built without the USE_CURL_FOR_IMAP_SEND

imap-send.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@
4646

4747
static int verbosity;
4848
static int use_curl = USE_CURL_DEFAULT;
49+
static char *opt_folder = NULL;
4950

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 };
5152

5253
static struct option imap_send_options[] = {
5354
OPT__VERBOSITY(&verbosity),
5455
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"),
5557
OPT_END()
5658
};
5759

@@ -1729,6 +1731,11 @@ int cmd_main(int argc, const char **argv)
17291731

17301732
argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0);
17311733

1734+
if (opt_folder) {
1735+
free(server.folder);
1736+
server.folder = xstrdup(opt_folder);
1737+
}
1738+
17321739
if (argc)
17331740
usage_with_options(imap_send_usage, imap_send_options);
17341741

0 commit comments

Comments
 (0)