Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smtplib SMTP instances missing a default sock attribute #76861

Closed
romuald mannequin opened this issue Jan 26, 2018 · 7 comments
Closed

smtplib SMTP instances missing a default sock attribute #76861

romuald mannequin opened this issue Jan 26, 2018 · 7 comments
Labels
3.8 only security fixes

Comments

@romuald
Copy link
Mannequin

romuald mannequin commented Jan 26, 2018

BPO 32680
Nosy @giampaolo, @matrixise, @romuald
PRs
  • bpo-32680 add default "sock" on SMTP objects #5345
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-10-09.14:35:41.687>
    created_at = <Date 2018-01-26.15:26:15.614>
    labels = ['3.8']
    title = 'smtplib SMTP instances missing a default sock attribute'
    updated_at = <Date 2018-10-09.14:35:41.685>
    user = 'https://github.com/romuald'

    bugs.python.org fields:

    activity = <Date 2018-10-09.14:35:41.685>
    actor = 'giampaolo.rodola'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-10-09.14:35:41.687>
    closer = 'giampaolo.rodola'
    components = []
    creation = <Date 2018-01-26.15:26:15.614>
    creator = 'Romuald'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32680
    keywords = ['patch']
    message_count = 7.0
    messages = ['310764', '310766', '310774', '311553', '311554', '327409', '327410']
    nosy_count = 4.0
    nosy_names = ['giampaolo.rodola', 'matrixise', 'Romuald', 'amirjn']
    pr_nums = ['5345']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32680'
    versions = ['Python 3.8']

    @romuald
    Copy link
    Mannequin Author

    romuald mannequin commented Jan 26, 2018

    SMTP instances from the smtplib module are not creating their sock attribute consistently after __init__

    When host is sent as parameter a sock object is created (and hopefully, connected)

    When the host is not sent, the sock attribute doesn't exist at all

    @romuald
    Copy link
    Mannequin Author

    romuald mannequin commented Jan 26, 2018

    My use case:

    try:
    s = SMTP('myhost')
    s.do_some_sending()
    finaly:
    if s is not None and s.sock is not None:
    s.quit()

    But I realize just now that in that case, if s was initialized correctly, its sock was inevitably set

    @matrixise
    Copy link
    Member

    You are right, but...

    if there is an exception in the connect method before the init of
    self.sock, the sock attribute will not exist and in this case, and only
    in this case, there will be an exception in the close method.

    your code will work fine if you use a try/finally but not in the case
    where we use the with statement, for example.

    with SMTP('myhost') as smtp:
       smtp.do_something()

    If there is an exception in the __init__ of SMTP and self.sock is not
    initialized -> traceback.

    @amirjn
    Copy link
    Mannequin

    amirjn mannequin commented Feb 3, 2018

    same problem at apple.com

    @amirjn
    Copy link
    Mannequin

    amirjn mannequin commented Feb 3, 2018

    <a href="apple.com">apple.com</a>

    @giampaolo
    Copy link
    Contributor

    New changeset 7b31397 by Giampaolo Rodola (Romuald Brunet) in branch 'master':
    bpo-32680 add default "sock" on SMTP objects (bpo-5345)
    7b31397

    @giampaolo
    Copy link
    Contributor

    PR merged for 3.8 branch. I don't think such a simple change deserves a backport for previous Python versions. Closing this out as resolved.

    @giampaolo giampaolo added the 3.8 only security fixes label Oct 9, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants