File: //lib/python3/dist-packages/twisted/mail/scripts/__pycache__/mailmail.cpython-38.pyc
U
��W[U) � @ sB d Z ddlmZ ddlZddlZddlZddlZzddlm Z W n e
k
r` ddl m Z Y nX ddlmZ ddl
mZ ddlmZmZ ddlmZ dd lmZ d
Zej�d�ZdZd
Zeej�Zeed�ZG dd� d�Zdd� Z e!d�Z"dd� Z#G dd� d�Z$dd� Z%dd� Z&da'dd� Z(dd� Z)d d!� Z*d"d#� Z+d$d%� Z,dS )&z4
Implementation module for the I{mailmail} command.
� )�print_functionN)�ConfigParser)�version)�reactor)�Logger�textFileLogObserver)�smtp)�NativeStringIOz
/etc/mailmailz~/.twisted/mailmailz 127.0.0.1z�Subject: Failed Message Delivery
Message delivery failed. The following occurred:
%s
--
The Twisted sendmail application.
)Zobserverc @ s e Zd ZdZdS )�Optionsat
Store the values of the parsed command-line options to the I{mailmail}
script.
@type to: L{list} of L{str}
@ivar to: The addresses to which to deliver this message.
@type sender: L{str}
@ivar sender: The address from which this message is being sent.
@type body: C{file}
@ivar body: The object from which the message is to be read.
N)�__name__�
__module__�__qualname__�__doc__� r r �?/usr/lib/python3/dist-packages/twisted/mail/scripts/mailmail.pyr
/ s r
c C s$ z
t �� W S t�� Y S X d S �N)�os�getlogin�getpassZgetuserr r r r r @ s
r zUnsupported option.c C s� t � }dd� | D �|_t� |_d| kr6tdt� t� �d| krBt�d| krNt�d| krx| | �d�d |_|j� |j� d | ks�d
| kr�t�d| kr�d|_
nd
|_
d| kr�d
|_
nd|_
d| ks�d| kr�d|_nd
|_d| kr�t�d| k�rd|_|j|_
g |_nd
|_g |_g g g g g d�}t� }d}tj�� }|�� �s@�q�|�dd�}|d �� }|j�r�|dk�r�|j�tj�|d �d g� |dk�r�d}n |dk�r�tj�|d �d |_||k�r�|| �|d � |�r$|�|� �q$|d �s|�d�|j�� |d �s6|j�std��|�d�d�|j��� |d �sT|�d�t�� �� |�|� |j�r�|j
D ]$}z|j� |� W n Y nX �ql|� dd� t|�!� tj�"� �|_#|S ) Nc S s g | ]}|� d �s|�qS )�-)�
startswith)�.0�er r r �
<listcomp>M s
z parseOptions.<locals>.<listcomp>z --versionzmailmail version:z-bpz-bsz-F� z-iz-oiz-odbTFz-odfz-oepz-epz-omz-t)�from�to�cc�bcc�datez: r )r r r r r z
From: {}
r zNo recipients specified.zTo: {}
z, r z
Date: {}
)$r
r r �sender�printr �
SystemExit�_unsupportedOption�index�removeZ
background�printErrorsZrecipientsFromHeadersZexcludeAddressesZexludeAddressesr �sys�stdin�readline�strip�split�lower�extend�emailZutilsZ parseaddr�append�write�format�joinr Z
rfc822date�seek�getvalue�read�body) �argv�oZrequiredHeaders�bufferr0 �lineZhdrsZhdr�ar r r �parseOptionsK s�
�
�
r<