# Re: [PATCH] imap-send: add option to mark sent messages as read or unread

3 messages from 2025-07-23 to 2025-07-23. Participants: Aditya Garg, Junio C Hamano.
Thread: https://gitlist.dev/t/63832

## Aditya Garg, 2025-07-23 15:45

Subject: Re: [PATCH] imap-send: add option to mark sent messages as read or unread
Message-ID: <PN0PR01MB95888028E0BD985DA07B9C60B85FA@PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM>
URL: https://gitlist.dev/e/PN0PR01MB95888028E0BD985DA07B9C60B85FA%40PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM

```


> On 23 Jul 2025, at 5:59 PM, Aditya Garg <gargaditya08@live.com> wrote:
> 
> ﻿The current behaviour of `git imap-send` is to mark sent messages as read
> if curl is used, and unread if OpenSSL is used.
> 
> Fix this inconsistency by marking the message as read by default in both
> cases. Also introduce `--[no-]mark-as-read` and `imap.markAsRead` option
> to allow users to change this behaviour.
> 
> While at it, also clarify that `imap.folder` will be used if --folder is
> not specified.
> 
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
> Documentation/config/imap.adoc   |  4 ++++
> Documentation/git-imap-send.adoc | 10 +++++++++-
> imap-send.c                      | 18 ++++++++++++++++--
> 3 files changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/config/imap.adoc b/Documentation/config/imap.adoc
> index 4682a6bd03..afae49391c 100644
> --- a/Documentation/config/imap.adoc
> +++ b/Documentation/config/imap.adoc
> @@ -45,3 +45,7 @@ imap.authMethod::
>   option, the only supported methods are `PLAIN`, `CRAM-MD5`, `OAUTHBEARER`
>   and `XOAUTH2`. If this is not set then `git imap-send` uses the basic IMAP
>   plaintext `LOGIN` command.
> +
> +imap.markAsRead::
> +    Choose whether to mark the sent message as read or not.
> +    Default is `true`.
> diff --git a/Documentation/git-imap-send.adoc b/Documentation/git-imap-send.adoc
> index 17147f93c3..3976c128c7 100644
> --- a/Documentation/git-imap-send.adoc
> +++ b/Documentation/git-imap-send.adoc
> @@ -9,7 +9,7 @@ git-imap-send - Send a collection of patches from stdin to an IMAP folder
> SYNOPSIS
> --------
> [verse]
> -'git imap-send' [-v] [-q] [--[no-]curl] [(--folder|-f) <folder>]
> +'git imap-send' [-v] [-q] [--[no-]curl] [--[no-]mark-as-read] [(--folder|-f) <folder>]
> 'git imap-send' --list
> 
> 
> @@ -44,6 +44,8 @@ OPTIONS
> --folder=<folder>::
>   Specify the folder in which the emails have to saved.
>   For example: `--folder=[Gmail]/Drafts` or `-f INBOX/Drafts`.
> +    If not specified, the folder assigned using `imap.folder`
> +    will be used.
> 
> --curl::
>   Use libcurl to communicate with the IMAP server, unless tunneling
> @@ -58,6 +60,12 @@ OPTIONS
> --list::
>   Run the IMAP LIST command to output a list of all the folders present.
> 
> +--[no-]mark-as-read::
> +    Choose whether to mark the sent message as read or not.
> +    `--mark-as-read` will mark the message as read, and `--no-mark-as-read`
> +    will mark it as unread. If not specified, the default behaviour will
> +    be decided by the value of `imap.markAsRead`.
> +
> CONFIGURATION
> -------------
> 
> diff --git a/imap-send.c b/imap-send.c
> index 44de0c5a77..a242119164 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -47,11 +47,12 @@
> 
> static int verbosity;
> static int list_folders;
> +static int mark_seen = 1;
> static int use_curl = USE_CURL_DEFAULT;
> static char *opt_folder;
> 
> static char const * const imap_send_usage[] = {
> -    N_("git imap-send [-v] [-q] [--[no-]curl] [(--folder|-f) <folder>] < <mbox>"),
> +    N_("git imap-send [-v] [-q] [--[no-]curl] [--[no-]mark-as-read] [(--folder|-f) <folder>] < <mbox>"),
>   "git imap-send --list",
>   NULL
> };
> @@ -61,6 +62,7 @@ static struct option imap_send_options[] = {
>   OPT_BOOL(0, "curl", &use_curl, "use libcurl to communicate with the IMAP server"),
>   OPT_STRING('f', "folder", &opt_folder, "folder", "specify the IMAP folder"),
>   OPT_BOOL(0, "list", &list_folders, "list all folders on the IMAP server"),
> +    OPT_BOOL(0, "mark-as-read", &mark_seen, "mark messages as read after sending"),
>   OPT_END()
> };
> 
> @@ -1402,7 +1404,11 @@ static int imap_store_msg(struct imap_store *ctx, struct strbuf *msg)
> 
>   box = ctx->name;
>   prefix = !strcmp(box, "INBOX") ? "" : ctx->prefix;
> -    ret = imap_exec_m(ctx, &cb, "APPEND \"%s%s\" ", prefix, box);
> +    if (mark_seen) {
> +        ret = imap_exec_m(ctx, &cb, "APPEND \"%s%s\" (\\Seen) ", prefix, box);
> +    } else {
> +        ret = imap_exec_m(ctx, &cb, "APPEND \"%s%s\" ", prefix, box);
> +    }
>   imap->caps = imap->rcaps;
>   if (ret != DRV_OK)
>       return ret;
> @@ -1513,6 +1519,8 @@ static int git_imap_config(const char *var, const char *val,
>       cfg->ssl_verify = git_config_bool(var, val);
>   } else if (!strcmp("imap.preformattedhtml", var)) {
>       cfg->use_html = git_config_bool(var, val);
> +    } else if (!strcmp("imap.markasread", var)) {
> +        mark_seen = git_config_bool(var, val);
>   } else if (!strcmp("imap.folder", var)) {
>       FREE_AND_NULL(cfg->folder);
>       return git_config_string(&cfg->folder, var, val);
> @@ -1702,6 +1710,12 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server,
>   curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer);
>   curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
> 
> +    if (mark_seen) {
> +        curl_easy_setopt(curl, CURLOPT_UPLOAD_FLAGS, CURLULFLAG_SEEN);
> +    } else {
> +        curl_easy_setopt(curl, CURLOPT_UPLOAD_FLAGS, 0L);
> +    }
> +

The GitHub actions workflows are failing because CURLOPT_UPLOAD_FLAGS were introduced in v8.13.0 of libcurl, which is just 3 months old, and the CI has an older version.

Not sure if version checks are needed here or not.
```

## Junio C Hamano, 2025-07-23 17:46

Subject: Re: [PATCH] imap-send: add option to mark sent messages as read or unread
Message-ID: <xmqq7bzyol5w.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq7bzyol5w.fsf%40gitster.g
In-Reply-To: <PN0PR01MB95888028E0BD985DA07B9C60B85FA@PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM>

```
Aditya Garg <gargaditya08@live.com> writes:

> The GitHub actions workflows are failing because CURLOPT_UPLOAD_FLAGS were introduced in v8.13.0 of libcurl, which is just 3 months old, and the CI has an older version.
>
> Not sure if version checks are needed here or not.

Hold onto the patch, without sending it to me or to the list, until
we raise the requirement for libcURL again perhaps in a few years,
at which time we may consider adpoting this feature.

I do not think we want more conditional compilation.

Thanks.

```

## Aditya Garg, 2025-07-23 17:49

Subject: Re: [PATCH] imap-send: add option to mark sent messages as read or unread
Message-ID: <PN3PR01MB9597A554CAC46F584AFCEA36B85FA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
URL: https://gitlist.dev/e/PN3PR01MB9597A554CAC46F584AFCEA36B85FA%40PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM
In-Reply-To: <xmqq7bzyol5w.fsf@gitster.g>

```


> On 23 Jul 2025, at 11:16 PM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> ﻿Aditya Garg <gargaditya08@live.com> writes:
> 
>> The GitHub actions workflows are failing because CURLOPT_UPLOAD_FLAGS were introduced in v8.13.0 of libcurl, which is just 3 months old, and the CI has an older version.
>> 
>> Not sure if version checks are needed here or not.
> 
> Hold onto the patch, without sending it to me or to the list, until
> we raise the requirement for libcURL again perhaps in a few years,
> at which time we may consider adpoting this feature.
> 
> I do not think we want more conditional compilation.

Ok
```
