All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH b4 v2 0/2] review: add support for b4.send-me-too
@ 2026-11-16 21:22 Brian Masney
  2026-11-16 21:22 ` [PATCH b4 v2 1/2] review / ty: " Brian Masney
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Brian Masney @ 2026-11-16 21:22 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Jerome Brunet, Brian Masney

The contributor side of b4 already has support for the configuration
option b4.send-me-too to make sure to include your email address on any
outbound emails. Let's go ahead and extend this to also work with the
review and ty sides of b4.

Signed-off-by: Brian Masney <masneyb@kernel.org>
---
Changes in v2:
- Add send-me-too support to the ty code as well
- Link to v1: https://patch.msgid.link/20261103-review-send-me-too-v1-0-0d23443820b7@kernel.org

---
Brian Masney (2):
      review / ty: add support for b4.send-me-too
      add tests for b4.send-me-too

 docs/config.rst                    |  4 +++-
 docs/releases.rst                  |  3 ++-
 src/b4/__init__.py                 | 40 +++++++++++++++++++++++++++++++++++++
 src/b4/ez.py                       |  3 +--
 src/b4/review/_review.py           |  1 +
 src/b4/review_tui/_lite_app.py     |  1 +
 src/b4/review_tui/_modals.py       |  1 +
 src/b4/review_tui/_review_app.py   |  1 +
 src/b4/review_tui/_tracking_app.py |  2 +-
 src/b4/ty.py                       |  8 +++++++-
 src/tests/test___init__.py         | 37 ++++++++++++++++++++++++++++++++++
 src/tests/test_review.py           | 20 +++++++++++++++++++
 src/tests/test_ty.py               | 41 ++++++++++++++++++++++++++++++++++++++
 13 files changed, 156 insertions(+), 6 deletions(-)
---
base-commit: ce4c1158edb292caca0ce4a6087e5edecc1b0371
change-id: 20261103-review-send-me-too-0f521902d8c4

Best regards,
--  
Brian Masney <masneyb@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH b4 v2 1/2] review / ty: add support for b4.send-me-too
  2026-11-16 21:22 [PATCH b4 v2 0/2] review: add support for b4.send-me-too Brian Masney
@ 2026-11-16 21:22 ` Brian Masney
  2026-11-16 21:22 ` [PATCH b4 v2 2/2] add tests " Brian Masney
  2026-11-17 22:12 ` [PATCH b4 v2 0/2] review: add support " Konstantin Ryabitsev
  2 siblings, 0 replies; 5+ messages in thread
From: Brian Masney @ 2026-11-16 21:22 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Jerome Brunet, Brian Masney

The contributor side of b4 already has support for the configuration
option b4.send-me-too to make sure to include your email address on any
outbound emails. Let's go ahead and extend this to also work with the
review and ty sides of b4.

Signed-off-by: Brian Masney <masneyb@kernel.org>
---
 docs/config.rst                    |  4 +++-
 docs/releases.rst                  |  3 ++-
 src/b4/__init__.py                 | 40 ++++++++++++++++++++++++++++++++++++++
 src/b4/ez.py                       |  3 +--
 src/b4/review/_review.py           |  1 +
 src/b4/review_tui/_lite_app.py     |  1 +
 src/b4/review_tui/_modals.py       |  1 +
 src/b4/review_tui/_review_app.py   |  1 +
 src/b4/review_tui/_tracking_app.py |  2 +-
 src/b4/ty.py                       |  8 +++++++-
 10 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/docs/config.rst b/docs/config.rst
index 593129e8ae70..182ca9353c01 100644
--- a/docs/config.rst
+++ b/docs/config.rst
@@ -1150,7 +1150,9 @@ Contributor-oriented settings
 
    :term:`b4.send-me-too`
      Instructs b4 to include your own address when sending. Set by default,
-     use ``no`` to suppress sending to yourself.
+     use ``no`` to suppress sending to yourself. This applies to patches
+     sent with ``b4 send``, to thank-you notes sent with ``b4 ty``, and to
+     replies from ``b4 review``.
 
      Default: ``yes``
 
diff --git a/docs/releases.rst b/docs/releases.rst
index 2b16efb72d7a..14606804d1ea 100644
--- a/docs/releases.rst
+++ b/docs/releases.rst
@@ -350,7 +350,8 @@ New configuration options
 
 ``b4.send-me-too``
   Set to ``no`` to suppress including your own address in the ``Cc``
-  when sending patches with ``b4 send``. Defaults to ``yes`` (include
+  when sending patches with ``b4 send``, thank-you notes with ``b4 ty``,
+  and to replies from ``b4 review``.  Defaults to ``yes`` (include
   yourself).
 
 **In-tree ``.b4-config`` changes**
diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index 704ddec9b5c6..2a2247eb6ad0 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -6684,6 +6684,46 @@ def get_excluded_addrs() -> Set[str]:
     return excludes
 
 
+def get_send_me_too() -> bool:
+    """Whether b4.send-me-too asks us to include ourselves as a recipient."""
+    config = get_main_config()
+    conf_me_too = str(config.get('send-me-too', 'yes')).lower()
+    return conf_me_too not in {'no', 'n', 'false', '0'}
+
+
+def add_me_too(
+    msg: EmailMessage,
+    enabled: Optional[bool] = None,
+    me: Optional[Tuple[str, str]] = None,
+) -> None:
+    """Cc ourselves on *msg* when b4.send-me-too is enabled.
+
+    *enabled* overrides the b4.send-me-too setting when not None, e.g. for
+    an explicit command-line flag. *me* is the (name, email) to Cc, and
+    defaults to the user's configured identity. Nothing is added if we are
+    already among the To or Cc recipients.
+    """
+    if enabled is None:
+        enabled = get_send_me_too()
+    if not enabled:
+        return
+    if me is None:
+        usercfg = get_user_config()
+        me = (str(usercfg.get('name', '')), str(usercfg.get('email', '')))
+    myname, myemail = me
+    if not myemail:
+        return
+    recipients = email.utils.getaddresses(
+        [str(x) for x in msg.get_all('to', []) + msg.get_all('cc', [])]
+    )
+    if myemail.lower() in {x[1].lower() for x in recipients}:
+        return
+    ccs = [str(x) for x in msg.get_all('cc', []) if str(x).strip()]
+    ccs.append(format_addrs([(myname, myemail)], clean=False))
+    del msg['Cc']
+    msg['Cc'] = ', '.join(ccs)
+
+
 def cleanup_email_addrs(
     addresses: List[Tuple[str, str]], excludes: Set[str], gitdir: Optional[str]
 ) -> List[Tuple[str, str]]:
diff --git a/src/b4/ez.py b/src/b4/ez.py
index 2441badbb288..71d5e1cc5516 100644
--- a/src/b4/ez.py
+++ b/src/b4/ez.py
@@ -3334,8 +3334,7 @@ def cmd_send(cmdargs: argparse.Namespace) -> None:
                 ccdests.append(btr.addr)
 
         excludes = b4.get_excluded_addrs()
-        conf_me_too = str(config.get('send-me-too', 'yes')).lower()
-        if cmdargs.not_me_too or conf_me_too in {'no', 'n', 'false', '0'}:
+        if cmdargs.not_me_too or not b4.get_send_me_too():
             excludes.add(myemail)
 
     tos: Set[str] = set()
diff --git a/src/b4/review/_review.py b/src/b4/review/_review.py
index b69a7f094bc7..55a042d8d1be 100644
--- a/src/b4/review/_review.py
+++ b/src/b4/review/_review.py
@@ -3891,6 +3891,7 @@ def _build_review_email(
         msg['To'] = b4.format_addrs(deduped_to, clean=False)
         if deduped_cc:
             msg['Cc'] = b4.format_addrs(deduped_cc, clean=False)
+        b4.add_me_too(msg)
     if header_info.get('bcc'):
         msg['Bcc'] = header_info['bcc']
     msg['In-Reply-To'] = f'<{header_info["msgid"]}>'
diff --git a/src/b4/review_tui/_lite_app.py b/src/b4/review_tui/_lite_app.py
index 0926cbd471d1..b3132d7f3c43 100644
--- a/src/b4/review_tui/_lite_app.py
+++ b/src/b4/review_tui/_lite_app.py
@@ -958,6 +958,7 @@ class LiteThreadScreen(ModalScreen[None]):
         lmsg = node.lmsg
         text = prepare_followup_reply_body(text)
         msg = lmsg.make_reply(text)
+        b4.add_me_too(msg)
         try:
             with self.app.suspend():
                 smtp, fromaddr = b4.get_smtp(dryrun=self._email_dryrun)
diff --git a/src/b4/review_tui/_modals.py b/src/b4/review_tui/_modals.py
index 0abf9b61a6f2..787d28b679a2 100644
--- a/src/b4/review_tui/_modals.py
+++ b/src/b4/review_tui/_modals.py
@@ -633,6 +633,7 @@ class FollowupReplyPreviewScreen(ModalScreen[Optional[str]]):
     def on_mount(self) -> None:
         body = prepare_followup_reply_body(self._reply_text)
         msg = self._entry['lmsg'].make_reply(body)
+        b4.add_me_too(msg)
         viewer = self.query_one('#followup-preview-viewer', RichLog)
         _render_email_to_viewer(viewer, msg, ts=resolve_styles(self.app))
 
diff --git a/src/b4/review_tui/_review_app.py b/src/b4/review_tui/_review_app.py
index 1e70bc609778..fcb168d49208 100644
--- a/src/b4/review_tui/_review_app.py
+++ b/src/b4/review_tui/_review_app.py
@@ -1897,6 +1897,7 @@ class ReviewApp(LoreNodeShutdownMixin, CheckRunnerMixin, App[None]):
         """Build and immediately send a quick reply to a follow-up message."""
         reply_text = prepare_followup_reply_body(text)
         msg = entry['lmsg'].make_reply(reply_text)
+        b4.add_me_too(msg)
         try:
             with self.suspend():
                 smtp, fromaddr = b4.get_smtp(dryrun=self._email_dryrun)
diff --git a/src/b4/review_tui/_tracking_app.py b/src/b4/review_tui/_tracking_app.py
index 714f215fc475..df20225f8fe2 100644
--- a/src/b4/review_tui/_tracking_app.py
+++ b/src/b4/review_tui/_tracking_app.py
@@ -5183,7 +5183,7 @@ class TrackingApp(LoreNodeShutdownMixin, CheckRunnerMixin, App[Optional[str]]):
 
         # Build a minimal cmdargs for ty.generate_am_thanks / make_reply
         cmdargs = argparse.Namespace()
-        cmdargs.metoo = False
+        cmdargs.metoo = b4.get_send_me_too()
         cmdargs.since = None
 
         try:
diff --git a/src/b4/ty.py b/src/b4/ty.py
index ec5b226b494f..4da074f00c84 100644
--- a/src/b4/ty.py
+++ b/src/b4/ty.py
@@ -105,7 +105,8 @@ def make_reply(
     )
 
     # Exclude ourselves and original sender from allto or allcc
-    if not cmdargs.metoo:
+    metoo = cmdargs.metoo or b4.get_send_me_too()
+    if not metoo:
         excludes.add(jsondata['myemail'])
     excludes.add(jsondata['fromemail'])
     allto = b4.cleanup_email_addrs(
@@ -121,6 +122,11 @@ def make_reply(
     msg.add_header('To', b4.format_addrs(allto))
     if allcc:
         msg.add_header('Cc', b4.format_addrs(allcc))
+    b4.add_me_too(
+        msg,
+        enabled=metoo,
+        me=(str(jsondata['myname']), jsondata['myemail']),
+    )
     msg['In-Reply-To'] = '<%s>' % jsondata['msgid']
     if isinstance(jsondata['references'], list) and len(jsondata['references']):
         msg['References'] = '%s <%s>' % (jsondata['references'], jsondata['msgid'])

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH b4 v2 2/2] add tests for b4.send-me-too
  2026-11-16 21:22 [PATCH b4 v2 0/2] review: add support for b4.send-me-too Brian Masney
  2026-11-16 21:22 ` [PATCH b4 v2 1/2] review / ty: " Brian Masney
@ 2026-11-16 21:22 ` Brian Masney
  2026-11-17 22:12 ` [PATCH b4 v2 0/2] review: add support " Konstantin Ryabitsev
  2 siblings, 0 replies; 5+ messages in thread
From: Brian Masney @ 2026-11-16 21:22 UTC (permalink / raw)
  To: Kernel.org Tools; +Cc: Konstantin Ryabitsev, Jerome Brunet, Brian Masney

Add tests for the b4.send-me-too configuration option for the review and
ty parts of b4.

Signed-off-by: Brian Masney <masneyb@kernel.org>
---
 src/tests/test___init__.py | 37 +++++++++++++++++++++++++++++++++++++
 src/tests/test_review.py   | 20 ++++++++++++++++++++
 src/tests/test_ty.py       | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+)

diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
index 764829d7e756..ac900220c457 100644
--- a/src/tests/test___init__.py
+++ b/src/tests/test___init__.py
@@ -2618,6 +2618,43 @@ def test_git_head_restore_args_round_trip(gitdir: str) -> None:
     assert b4.git_head_restore_args(gitdir) == restore
 
 
+class TestAddMeToo:
+    """b4.send-me-too Ccs the user unless they are already a recipient."""
+
+    @staticmethod
+    def _msg(cc: Optional[str] = None) -> email.message.EmailMessage:
+        msg = email.message.EmailMessage()
+        msg['From'] = 'Alice <alice@example.org>'
+        msg['To'] = 'bob@example.org'
+        if cc:
+            msg['Cc'] = cc
+        return msg
+
+    def test_adds_sender_to_cc(self) -> None:
+        msg = self._msg()
+        b4.add_me_too(msg)
+        assert msg['Cc'] == 'Test Override <test-override@example.com>'
+
+    def test_appends_to_existing_cc(self) -> None:
+        msg = self._msg(cc='carol@example.org')
+        b4.add_me_too(msg)
+        assert msg['Cc'] == (
+            'carol@example.org, Test Override <test-override@example.com>'
+        )
+
+    def test_skips_existing_recipient(self) -> None:
+        msg = self._msg(cc='TEST-OVERRIDE@example.com')
+        b4.add_me_too(msg)
+        assert msg['Cc'] == 'TEST-OVERRIDE@example.com'
+
+    @pytest.mark.parametrize('value', ['no', 'False', '0'])
+    def test_disabled(self, monkeypatch: pytest.MonkeyPatch, value: str) -> None:
+        monkeypatch.setitem(b4.MAIN_CONFIG, 'send-me-too', value)
+        msg = self._msg()
+        b4.add_me_too(msg)
+        assert msg['Cc'] is None
+
+
 class TestUnicodeControlChars:
     """The Cf-character guard in get_am_message() must raise BadCharsError
     instead of calling sys.exit(), so that interactive front-ends (the
diff --git a/src/tests/test_review.py b/src/tests/test_review.py
index e40dd35def9e..a19397671c35 100644
--- a/src/tests/test_review.py
+++ b/src/tests/test_review.py
@@ -2132,6 +2132,26 @@ class TestBuildReviewEmail:
         assert msg['To'] == 'custom@example.com'
         assert msg['Cc'] == 'other@example.com'
 
+    def test_send_me_too_ccs_reviewer(self) -> None:
+        msg = self._build(self._make_series(cc='other@example.com'))
+        assert msg is not None
+        assert msg['Cc'] == (
+            'maintainer@example.com, other@example.com, Reviewer <reviewer@example.com>'
+        )
+
+    def test_send_me_too_disabled(self, monkeypatch: pytest.MonkeyPatch) -> None:
+        monkeypatch.setitem(b4.MAIN_CONFIG, 'send-me-too', 'no')
+        msg = self._build()
+        assert msg is not None
+        assert msg['Cc'] == 'maintainer@example.com'
+
+    def test_send_me_too_skipped_for_edited_recipients(self) -> None:
+        series = self._make_series(to='custom@example.com', cc='')
+        series['header-info']['tocc-edited'] = True
+        msg = self._build(series)
+        assert msg is not None
+        assert msg['Cc'] is None
+
 
 # -- Tests for get_reference_message() ---------------------------------------
 
diff --git a/src/tests/test_ty.py b/src/tests/test_ty.py
index 269ce021306f..6a5fbed92ae1 100644
--- a/src/tests/test_ty.py
+++ b/src/tests/test_ty.py
@@ -1,3 +1,4 @@
+import email.utils
 import os
 import pathlib
 from email.message import EmailMessage
@@ -767,6 +768,46 @@ def test_generate_am_thanks_does_not_leak_between_branches(
     assert b4.MAIN_CONFIG['thanks-commit-url-mask'] is None
 
 
+def _make_ty_reply(metoo: Optional[bool], cc: str = '') -> EmailMessage:
+    jsondata = _am_jsondata('0123456789abcdef0123456789abcdef01234567')
+    jsondata['cc'] = cc
+    cmdargs = mock.Mock(metoo=metoo, since=None)
+    return b4.ty.make_reply('Thanks!', jsondata, None, cmdargs)
+
+
+@pytest.mark.parametrize(
+    'conf,metoo,expected',
+    [
+        ('yes', None, True),
+        ('no', None, False),
+        ('no', True, True),
+    ],
+)
+def test_make_reply_me_too(
+    monkeypatch: pytest.MonkeyPatch,
+    conf: str,
+    metoo: Optional[bool],
+    expected: bool,
+) -> None:
+    """--me-too wins; otherwise b4.send-me-too decides."""
+    monkeypatch.setitem(b4.MAIN_CONFIG, 'send-me-too', conf)
+    msg = _make_ty_reply(metoo)
+    if expected:
+        assert msg['Cc'] == 'Test <test@example.com>'
+    else:
+        assert msg['Cc'] is None
+
+
+def test_make_reply_me_too_keeps_existing_cc(
+    monkeypatch: pytest.MonkeyPatch,
+) -> None:
+    """Already being Cc'd on the original is enough; no duplicate added."""
+    monkeypatch.setitem(b4.MAIN_CONFIG, 'send-me-too', 'yes')
+    msg = _make_ty_reply(None, cc='Test <test@example.com>, other@example.com')
+    ccs = [x[1] for x in email.utils.getaddresses([str(msg['Cc'])])]
+    assert ccs == ['test@example.com', 'other@example.com']
+
+
 def test_queue_message_check_headers(
     monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path
 ) -> None:

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH b4 v2 0/2] review: add support for b4.send-me-too
  2026-11-16 21:22 [PATCH b4 v2 0/2] review: add support for b4.send-me-too Brian Masney
  2026-11-16 21:22 ` [PATCH b4 v2 1/2] review / ty: " Brian Masney
  2026-11-16 21:22 ` [PATCH b4 v2 2/2] add tests " Brian Masney
@ 2026-11-17 22:12 ` Konstantin Ryabitsev
  2026-11-17 22:24   ` Brian Masney
  2 siblings, 1 reply; 5+ messages in thread
From: Konstantin Ryabitsev @ 2026-11-17 22:12 UTC (permalink / raw)
  To: Brian Masney; +Cc: Kernel.org Tools, Konstantin Ryabitsev, Jerome Brunet

> The contributor side of b4 already has support for the configuration
> option b4.send-me-too to make sure to include your email address on any
> outbound emails. Let's go ahead and extend this to also work with the
> review and ty sides of b4.

I didn't end up taking this directly because I wanted to disambiguate
"ty" from "send", but the latest master should have the functionality
you're looking for.

Thanks,

-- 
Konstantin Ryabitsev <konstantin@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH b4 v2 0/2] review: add support for b4.send-me-too
  2026-11-17 22:12 ` [PATCH b4 v2 0/2] review: add support " Konstantin Ryabitsev
@ 2026-11-17 22:24   ` Brian Masney
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Masney @ 2026-11-17 22:24 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: Kernel.org Tools, Jerome Brunet

On Tue, Nov 17, 2026 at 10:12:34PM +0000, Konstantin Ryabitsev wrote:
> > The contributor side of b4 already has support for the configuration
> > option b4.send-me-too to make sure to include your email address on any
> > outbound emails. Let's go ahead and extend this to also work with the
> > review and ty sides of b4.

Thanks, Konstantin. What you have looks nicer than what I posted.

Brian

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-17 22:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 21:22 [PATCH b4 v2 0/2] review: add support for b4.send-me-too Brian Masney
2026-11-16 21:22 ` [PATCH b4 v2 1/2] review / ty: " Brian Masney
2026-11-16 21:22 ` [PATCH b4 v2 2/2] add tests " Brian Masney
2026-11-17 22:12 ` [PATCH b4 v2 0/2] review: add support " Konstantin Ryabitsev
2026-11-17 22:24   ` Brian Masney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.