3 گa? � @ s� d Z ddlZddlmZ ddlmZ ddlZddlmZ ddlm Z ddl mZ ddl mZ dd l mZ eje�Zejedd �dd�Zejee dd �d d�Zed�dd�Zedd�dd�Zejdd�dd�Zdee dd�dd�ZdS )z'Subscribes users to the EFF newsletter.� N)�cast)�Optional)� configuration)� constants)�Account)�AccountFileStorage)�util)�config�acc�returnc C s� | j dkrdS | j dkrH| jdkr,td� qnttj|jj| jd��|_n&| jrnt� rnttj|jj| jd��|_|jj r�t | �}|j|� dS )a� High level function to store potential EFF newsletter subscriptions. The user may be asked if they want to sign up for the newsletter if they have not given their explicit approval or refusal using --eff-mail or --no-eff-mail flag. Decision about EFF subscription will be stored in the account metadata. :param configuration.NamespaceConfig config: Client configuration. :param Account acc: Current client account. FNTz$you didn't provide an e-mail address)�register_to_eff)Z eff_email�email�_report_failurer r �Meta�meta�update�_want_subscriptionr r �update_meta)r r �storage� r �/usr/lib/python3.6/eff.py�prepare_subscription s r c C sX | j s| rdS |jjrTttt|jj�� ttj|jjdd��|_t | �}|j |� dS )a High level function to take care of EFF newsletter subscriptions. Once subscription is handled, it will not be handled again. :param configuration.NamespaceConfig config: Client configuration. :param Account acc: Current client account. N)r )Zdry_runr r � subscriber �strr r r r r )r r r r r r �handle_subscription/ s r )r c C s d} t j| dd�S )z�Does the user want to be subscribed to the EFF newsletter? :returns: True if we should subscribe the user, otherwise, False :rtype: bool ao Would you be willing, once your first certificate is successfully issued, to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. F)�default)�display_utilZyesno)�promptr r r r D s r )r r c C sB t j}d| dd�}tjd| � tjd||� ttj||d�� dS )zhSubscribe the user to the EFF mailing list. :param str email: the e-mail address to subscribe �jsonZ%eff_supporters_library_subscribe_form)Z data_typer Zform_idz.Subscribe to the EFF mailing list (email: %s).zSending POST request to %s: %s)�dataN)r ZEFF_SUBSCRIBE_URI�logger�info�debug�_check_response�requestsZpost)r Zurlr r r r r T s r )�responser c C sp t jd| j� y | j� | j� d s,td� W n< tjjk rL t� Y n t t fk rj td� Y nX dS )z�Check for errors in the server's response. If an error occurred, it will be reported to the user. :param requests.Response response: the server's response to the subscription request zReceived response: %sZstatusz)your e-mail address appears to be invalidz,there was a problem with the server responseN)r r"