python / python/cpython

smtplib: missing case in handling 421 response in sendmail

Aberta
#132,796 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

3.13 3.14 stdlib type-bug
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

Bug report

Bug description:

The sendmail function in smtplib does a good job of handling 421 responses from SMTP servers but is missing one case. This may lead to SMTP client connections not being closed properly.

Background

SMTP servers can send 421 responses whenever they need to shut down the connection (RF 5321 3.8). Clients should take care of closing the connection when receiving a 421.

Details

The sendmail function combines the low-level SMTP commands into a full session for sending some text content via SMTP. The function needs to handle 421 responses, as any single command may return a 421 response. The function already handles almost all cases but is missing one for the call of the data function, which does its own response code checking and may raise an exception.

Test to reproduce

The test was derived from the corresponding rosetta-test SMTP test suite and adapted to the smtplib test infrastructure.

def test_421_during_data_cmd(self):
    smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
                          timeout=support.LOOPBACK_TIMEOUT)
    smtp.noop()
    self.serv._SMTPchannel.data_response = '421 closing'
    with self.assertRaises(smtplib.SMTPDataError):
        smtp.sendmail('John@foo.org', ['Sally@foo.org'], 'test message')
    self.assertIsNone(smtp.sock)
    self.assertEqual(self.serv._SMTPchannel.rcpt_count, 0)
CPython versions tested on:

CPython main branch, 3.10, 3.12

Operating systems tested on:

Linux

Linked PRs
  • gh-132797

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Inspecione Lib/smtplib.py ao redor da chamada de dados de sendmail e da verificação da resposta de dados descrita na issue. Execute ou adapte test_421_during_data_cmd na infraestrutura de testes de smtplib; considera-se concluído quando o caso 421 gera SMTPDataError, fecha o socket e deixa rcpt_count em zero.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
networking
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
30/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.