Skip to content

Commit 8cda0d2

Browse files
committed
Merge branch 'ag/imap-send-resurrection' into seen
"git imap-send" has been broken for a long time, which has been resurrected and then taught to talk OAuth2.0 etc. Getting there. * ag/imap-send-resurrection: imap-send: add ability to list the available folders imap-send: display the destination mailbox when sending a message imap-send: display port alongwith host when git credential is invoked imap-send: fix minor mistakes in the logs imap-send: enable specifying the folder using the command line imap-send: add PLAIN authentication method to OpenSSL imap-send: add support for OAuth2.0 authentication imap-send: gracefully fail if CRAM-MD5 authentication is requested without OpenSSL imap-send: fix memory leak in case auth_cram_md5 fails imap-send: fix bug causing cfg->folder being set to NULL
2 parents 8c611fa + 2a68048 commit 8cda0d2

File tree

3 files changed

+414
-77
lines changed

3 files changed

+414
-77
lines changed

Documentation/config/imap.adoc

Lines changed: 7 additions & 4 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
@@ -40,5 +42,6 @@ imap.authMethod::
4042
Specify the authentication method for authenticating with the IMAP server.
4143
If Git was built with the NO_CURL option, or if your curl version is older
4244
than 7.34.0, or if you're running git-imap-send with the `--no-curl`
43-
option, the only supported method is 'CRAM-MD5'. If this is not set
44-
then 'git imap-send' uses the basic IMAP plaintext LOGIN command.
45+
option, the only supported methods are `PLAIN`, `CRAM-MD5`, `OAUTHBEARER`
46+
and `XOAUTH2`. If this is not set then `git imap-send` uses the basic IMAP
47+
plaintext `LOGIN` command.

Documentation/git-imap-send.adoc

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@ 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>]
13+
'git imap-send' --list
1314

1415

1516
DESCRIPTION
1617
-----------
17-
This command uploads a mailbox generated with 'git format-patch'
18+
This command uploads a mailbox generated with `git format-patch`
1819
into an IMAP drafts folder. This allows patches to be sent as
1920
other email is when using mail clients that cannot read mailbox
2021
files directly. The command also works with any general mailbox
21-
in which emails have the fields "From", "Date", and "Subject" in
22+
in which emails have the fields `From`, `Date`, and `Subject` in
2223
that order.
2324

2425
Typical usage is something like:
2526

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

2831

2932
OPTIONS
@@ -37,6 +40,11 @@ OPTIONS
3740
--quiet::
3841
Be quiet.
3942

43+
-f <folder>::
44+
--folder=<folder>::
45+
Specify the folder in which the emails have to saved.
46+
For example: `--folder=[Gmail]/Drafts` or `-f INBOX/Drafts`.
47+
4048
--curl::
4149
Use libcurl to communicate with the IMAP server, unless tunneling
4250
into it. Ignored if Git was built without the USE_CURL_FOR_IMAP_SEND
@@ -47,6 +55,8 @@ OPTIONS
4755
using libcurl. Ignored if Git was built with the NO_OPENSSL option
4856
set.
4957

58+
--list::
59+
Run the IMAP LIST command to output a list of all the folders present.
5060

5161
CONFIGURATION
5262
-------------
@@ -102,20 +112,56 @@ Using Gmail's IMAP interface:
102112

103113
---------
104114
[imap]
105-
folder = "[Gmail]/Drafts"
106-
host = imaps://imap.gmail.com
107-
108-
port = 993
115+
folder = "[Gmail]/Drafts"
116+
host = imaps://imap.gmail.com
117+
118+
port = 993
109119
---------
110120

121+
Gmail does not allow using your regular password for `git imap-send`.
122+
If you have multi-factor authentication set up on your Gmail account, you
123+
can generate an app-specific password for use with `git imap-send`.
124+
Visit https://security.google.com/settings/security/apppasswords to create
125+
it. Alternatively, use OAuth2.0 authentication as described below.
126+
111127
[NOTE]
112128
You might need to instead use: `folder = "[Google Mail]/Drafts"` if you get an error
113-
that the "Folder doesn't exist".
129+
that the "Folder doesn't exist". You can also run `git imap-send --list` to get a
130+
list of available folders.
114131

115132
[NOTE]
116133
If your Gmail account is set to another language than English, the name of the "Drafts"
117134
folder will be localized.
118135

136+
If you want to use OAuth2.0 based authentication, you can specify
137+
`OAUTHBEARER` or `XOAUTH2` mechanism in your config. It is more secure
138+
than using app-specific passwords, and also does not enforce the need of
139+
having multi-factor authentication. You will have to use an OAuth2.0
140+
access token in place of your password when using this authentication.
141+
142+
---------
143+
[imap]
144+
folder = "[Gmail]/Drafts"
145+
host = imaps://imap.gmail.com
146+
147+
port = 993
148+
authmethod = OAUTHBEARER
149+
---------
150+
151+
Using Outlook's IMAP interface:
152+
153+
Unlike Gmail, Outlook only supports OAuth2.0 based authentication. Also, it
154+
supports only `XOAUTH2` as the mechanism.
155+
156+
---------
157+
[imap]
158+
folder = "Drafts"
159+
host = imaps://outlook.office365.com
160+
161+
port = 993
162+
authmethod = XOAUTH2
163+
---------
164+
119165
Once the commits are ready to be sent, run the following command:
120166

121167
$ git format-patch --cover-letter -M --stdout origin/master | git imap-send
@@ -124,6 +170,10 @@ Just make sure to disable line wrapping in the email client (Gmail's web
124170
interface will wrap lines no matter what, so you need to use a real
125171
IMAP client).
126172

173+
In case you are using OAuth2.0 authentication, it is easier to use credential
174+
helpers to generate tokens. Credential helpers suggested in
175+
linkgit:git-send-email[1] can be used for `git imap-send` as well.
176+
127177
CAUTION
128178
-------
129179
It is still your responsibility to make sure that the email message

0 commit comments

Comments
 (0)