Message ID | 20240823-fix-multiple-smtpserveroption-v1-1-0c4879fcb133@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [b4] sendemail.smtpServerOption can be specified multiple times | expand |
On 2024-08-23 02:02, Celeste Liu wrote: > In git-send-email(1): > > The --smtp-server-option option must be repeated for each option you > want to pass to the server. Likewise, different lines in > the configuration files must be used for each option. > > So this config option must be specified in multivars parameter of > get_config_from_git() and be treated as a list. > > Fixes: 37811c93f5 ("Forward the smtpserveroption to the local command") > Cc: Joel Granados <j.granados@samsung.com> > Signed-off-by: Celeste Liu <CoelacanthusHex@gmail.com> > --- > src/b4/__init__.py | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/src/b4/__init__.py b/src/b4/__init__.py > index 2b1a058..1d0f520 100644 > --- a/src/b4/__init__.py > +++ b/src/b4/__init__.py > @@ -3728,10 +3728,10 @@ def _setup_sendemail_config(cmdargs: argparse.Namespace) -> None: > # Get the default settings first > config = get_main_config() > identity = config.get('sendemail-identity') > - _basecfg = get_config_from_git(r'sendemail\.[^.]+$') > + _basecfg = get_config_from_git(r'sendemail\.[^.]+$', multivals=['smtpserveroption']) > if identity: > # Use this identity to override what we got from the default one > - sconfig = get_config_from_git(rf'sendemail\.{identity}\..*', defaults=_basecfg) > + sconfig = get_config_from_git(rf'sendemail\.{identity}\..*', multivals=['smtpserveroption'], defaults=_basecfg) > sectname = f'sendemail.{identity}' > if not len(sconfig): > raise smtplib.SMTPException('Unable to find %s settings in any applicable git config' % sectname) > @@ -3785,7 +3785,7 @@ def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL > smtp += ['-f', envpair[1]] > server_option = sconfig.get('smtpserveroption', '') Oh. This default value is completely useless: firstly, get() will return None when mismatched, and None is false in truth testing in Python[1]; secondly, if a multivars option is not in gitconfig, it will be set to empty list in sconfig, so default value is an unreachable code. I will send v2 later. [1]: https://docs.python.org/3/library/stdtypes.html#truth-value-testing > if server_option: > - smtp += [server_option] > + smtp += server_option > logger.debug('sendmail command: %s', ' '.join(smtp)) > return smtp, fromaddr > > > --- > base-commit: 37811c93f50e70f325e45107a9a20ffc69f2f6dc > change-id: 20240823-fix-multiple-smtpserveroption-83731eb8b4e7 > > Best regards,
On 2024-08-23 02:24, Celeste Liu wrote: > > On 2024-08-23 02:02, Celeste Liu wrote: >> In git-send-email(1): >> >> The --smtp-server-option option must be repeated for each option you >> want to pass to the server. Likewise, different lines in >> the configuration files must be used for each option. >> >> So this config option must be specified in multivars parameter of >> get_config_from_git() and be treated as a list. >> >> Fixes: 37811c93f5 ("Forward the smtpserveroption to the local command") >> Cc: Joel Granados <j.granados@samsung.com> >> Signed-off-by: Celeste Liu <CoelacanthusHex@gmail.com> >> --- >> src/b4/__init__.py | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/src/b4/__init__.py b/src/b4/__init__.py >> index 2b1a058..1d0f520 100644 >> --- a/src/b4/__init__.py >> +++ b/src/b4/__init__.py >> @@ -3728,10 +3728,10 @@ def _setup_sendemail_config(cmdargs: argparse.Namespace) -> None: >> # Get the default settings first >> config = get_main_config() >> identity = config.get('sendemail-identity') >> - _basecfg = get_config_from_git(r'sendemail\.[^.]+$') >> + _basecfg = get_config_from_git(r'sendemail\.[^.]+$', multivals=['smtpserveroption']) >> if identity: >> # Use this identity to override what we got from the default one >> - sconfig = get_config_from_git(rf'sendemail\.{identity}\..*', defaults=_basecfg) >> + sconfig = get_config_from_git(rf'sendemail\.{identity}\..*', multivals=['smtpserveroption'], defaults=_basecfg) >> sectname = f'sendemail.{identity}' >> if not len(sconfig): >> raise smtplib.SMTPException('Unable to find %s settings in any applicable git config' % sectname) >> @@ -3785,7 +3785,7 @@ def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL >> smtp += ['-f', envpair[1]] >> server_option = sconfig.get('smtpserveroption', '') > > Oh. This default value is completely useless: firstly, get() will return None when mismatched, and None is false in truth testing in Python[1]; secondly, if a multivars option is not in gitconfig, it will be set to empty list in sconfig, so default value is an unreachable code. I will send v2 later. > > [1]: https://docs.python.org/3/library/stdtypes.html#truth-value-testing > I'm sorry for forgetting to wrap line to 80 column before sent... >> if server_option: >> - smtp += [server_option] >> + smtp += server_option >> logger.debug('sendmail command: %s', ' '.join(smtp)) >> return smtp, fromaddr >> >> >> --- >> base-commit: 37811c93f50e70f325e45107a9a20ffc69f2f6dc >> change-id: 20240823-fix-multiple-smtpserveroption-83731eb8b4e7 >> >> Best regards, >
On 2024-08-23 02:24, Celeste Liu wrote: > > On 2024-08-23 02:02, Celeste Liu wrote: >> In git-send-email(1): >> >> The --smtp-server-option option must be repeated for each option you >> want to pass to the server. Likewise, different lines in >> the configuration files must be used for each option. >> >> So this config option must be specified in multivars parameter of >> get_config_from_git() and be treated as a list. >> >> Fixes: 37811c93f5 ("Forward the smtpserveroption to the local command") >> Cc: Joel Granados <j.granados@samsung.com> >> Signed-off-by: Celeste Liu <CoelacanthusHex@gmail.com> >> --- >> src/b4/__init__.py | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/src/b4/__init__.py b/src/b4/__init__.py >> index 2b1a058..1d0f520 100644 >> --- a/src/b4/__init__.py >> +++ b/src/b4/__init__.py >> @@ -3728,10 +3728,10 @@ def _setup_sendemail_config(cmdargs: argparse.Namespace) -> None: >> # Get the default settings first >> config = get_main_config() >> identity = config.get('sendemail-identity') >> - _basecfg = get_config_from_git(r'sendemail\.[^.]+$') >> + _basecfg = get_config_from_git(r'sendemail\.[^.]+$', multivals=['smtpserveroption']) >> if identity: >> # Use this identity to override what we got from the default one >> - sconfig = get_config_from_git(rf'sendemail\.{identity}\..*', defaults=_basecfg) >> + sconfig = get_config_from_git(rf'sendemail\.{identity}\..*', multivals=['smtpserveroption'], defaults=_basecfg) >> sectname = f'sendemail.{identity}' >> if not len(sconfig): >> raise smtplib.SMTPException('Unable to find %s settings in any applicable git config' % sectname) >> @@ -3785,7 +3785,7 @@ def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL >> smtp += ['-f', envpair[1]] >> server_option = sconfig.get('smtpserveroption', '') > > Oh. This default value is completely useless: firstly, get() will return None when mismatched, and None is false in truth testing in Python[1]; secondly, if a multivars option is not in gitconfig, it will be set to empty list in sconfig, so default value is an unreachable code. I will send v2 later. v2 has been sent. > > [1]: https://docs.python.org/3/library/stdtypes.html#truth-value-testing > >> if server_option: >> - smtp += [server_option] >> + smtp += server_option >> logger.debug('sendmail command: %s', ' '.join(smtp)) >> return smtp, fromaddr >> >> >> --- >> base-commit: 37811c93f50e70f325e45107a9a20ffc69f2f6dc >> change-id: 20240823-fix-multiple-smtpserveroption-83731eb8b4e7 >> >> Best regards, >
diff --git a/src/b4/__init__.py b/src/b4/__init__.py index 2b1a058..1d0f520 100644 --- a/src/b4/__init__.py +++ b/src/b4/__init__.py @@ -3728,10 +3728,10 @@ def _setup_sendemail_config(cmdargs: argparse.Namespace) -> None: # Get the default settings first config = get_main_config() identity = config.get('sendemail-identity') - _basecfg = get_config_from_git(r'sendemail\.[^.]+$') + _basecfg = get_config_from_git(r'sendemail\.[^.]+$', multivals=['smtpserveroption']) if identity: # Use this identity to override what we got from the default one - sconfig = get_config_from_git(rf'sendemail\.{identity}\..*', defaults=_basecfg) + sconfig = get_config_from_git(rf'sendemail\.{identity}\..*', multivals=['smtpserveroption'], defaults=_basecfg) sectname = f'sendemail.{identity}' if not len(sconfig): raise smtplib.SMTPException('Unable to find %s settings in any applicable git config' % sectname) @@ -3785,7 +3785,7 @@ def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL smtp += ['-f', envpair[1]] server_option = sconfig.get('smtpserveroption', '') if server_option: - smtp += [server_option] + smtp += server_option logger.debug('sendmail command: %s', ' '.join(smtp)) return smtp, fromaddr
In git-send-email(1): The --smtp-server-option option must be repeated for each option you want to pass to the server. Likewise, different lines in the configuration files must be used for each option. So this config option must be specified in multivars parameter of get_config_from_git() and be treated as a list. Fixes: 37811c93f5 ("Forward the smtpserveroption to the local command") Cc: Joel Granados <j.granados@samsung.com> Signed-off-by: Celeste Liu <CoelacanthusHex@gmail.com> --- src/b4/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- base-commit: 37811c93f50e70f325e45107a9a20ffc69f2f6dc change-id: 20240823-fix-multiple-smtpserveroption-83731eb8b4e7 Best regards,