【问题标题】:How do you map an email address onto a SOA RNAME field?如何将电子邮件地址映射到 SURNAME 字段?
【发布时间】:2012-08-20 20:45:49
【问题描述】:

是否存在将电子邮件地址映射到 SOA 记录的 RNAME 字段(及其逆向)的现有/标准算法?我正在使用 dnspython 包,但我在他们的源代码树中看不到任何东西来处理这个问题。我遇到了有句号“。”的边缘情况。在需要转义的用户名中,并想知道是否还有其他我遗漏的边缘情况。 RFC 1035 简单地说:

指定负责此区域的人员的邮箱。

除了RFC 1183 中的简短提及之外,没有任何更新 1035 的 RFC 扩展 RNAME 字段。

【问题讨论】:

    标签: python dns dnspython


    【解决方案1】:

    这是我使用dnspython 得出的结论:

    from dns.name import from_text
    
    
    def email_to_rname(email):
        """Convert standard email address into RNAME field for SOA record.
    
        >>> email_to_rname('johndoe@example.com')
        <DNS name johndoe.example.com.>
        >>> email_to_rname('john.doe@example.com')
        <DNS name john\.doe.example.com.>
        >>> print email_to_rname('johndoe@example.com')
        johndoe.example.com.
        >>> print email_to_rname('john.doe@example.com')
        john\.doe.example.com.
    
        """
        username, domain = email.split('@', 1)
        username = username.replace('.', '\\.')  # escape . in username
        return from_text('.'.join((username, domain)))
    
    
    def rname_to_email(rname):
        """Convert SOA record RNAME field into standard email address.
    
        >>> rname_to_email(from_text('johndoe.example.com.'))
        'johndoe@example.com'
        >>> rname_to_email(from_text('john\\.doe.example.com.'))
        'john.doe@example.com'
        >>> rname_to_email(email_to_rname('johndoe@example.com'))
        'johndoe@example.com'
        >>> rname_to_email(email_to_rname('john.doe@example.com'))
        'john.doe@example.com'
    
        """
        labels = list(rname)
        username, domain = labels[0], '.'.join(labels[1:]).rstrip('.')
        username = username.replace('\\.', '.')  # unescape . in username
        return '@'.join((username, domain))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      相关资源
      最近更新 更多