ó
rÁìVc           @  s  d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z y d  d
 l m Z Wn! e k
 rÍ d  d l m Z n Xd  d l m Z m Z d  d l m Z d  d l m Z d d l m Z d d l  m  Z  d d l m! Z! m" Z" d d l# m$ Z$ m% Z% e d d ƒ j& e' d ƒ ƒ Z( e d d ƒ j& e' d ƒ ƒ Z) e d e j* f d „  ƒ  Yƒ Z+ e d e j* f d „  ƒ  Yƒ Z, e d e j* f d „  ƒ  Yƒ Z- d  „  Z. e d! e j* f d" „  ƒ  Yƒ Z/ d# S($   iÿÿÿÿ(   t   unicode_literals(   t   uuid4(   t
   namedtuple(   t   settings(   t   EmailMessaget   EmailMultiAlternatives(   t   models(   t   ugettext_lazy(   t   python_2_unicode_compatible(   t   CommaSeparatedEmailField(   t
   smart_text(   t   smart_unicode(   t   Contextt   Template(   t	   JSONField(   t   cachei   (   t	   text_type(   t   connections(   t   context_field_classt   get_log_level(   t   validate_email_with_namet   validate_template_syntaxu   PRIORITYu   low medium high nowi   u   STATUSu   sent failed queuedi   t   Emailc        	   B  sv  e  Z d  Z e j e d ƒ f e j e d ƒ f e j e d ƒ f e j e d ƒ f g Z	 e
 j e d ƒ f e
 j e d ƒ f e
 j e d ƒ f g Z e j e d ƒ d	 d
 d e g ƒZ e e d ƒ ƒ Z e e d ƒ ƒ Z e d ƒ Z e j e d ƒ d	 d d e ƒZ e j e d ƒ d e ƒZ e j e d ƒ d e ƒZ e j d e d e d e d e ƒ Z e j d e	 d e d e ƒ Z e j d e d e ƒ Z  e j d e d e ƒ Z! e j d e d e d e ƒ Z" e# d e d e ƒ Z$ e j% d d e d e ƒZ& e' d e d e ƒ Z( e j d e d d d	 d ƒ Z) d d# d „  ƒ  YZ* d „  Z+ d$ d  „ Z- d$ e d! „ Z. d" „  Z/ RS(%   u,   
    A model to hold email information.
    u   lowu   mediumu   highu   nowu   sentu   failedu   queuedu
   Email Fromt
   max_lengthiþ   t
   validatorsu   Email Tou   Ccu   Bccu   SubjectiÝ  t   blanku   Messageu   HTML Messaget   choicest   db_indext   nullt   auto_now_addt   auto_nowu   post_office.EmailTemplatet   defaultu    i@   t   Metac           B  s   e  Z d  Z RS(   u   post_office(   t   __name__t
   __module__t	   app_label(    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR    E   s   c         C  s   d |  j  S(   Nu   %s(   t   to(   t   self(    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyt   __str__H   s    c         C  s  t  |  j ƒ } |  j d
 k	 r t |  j ƒ } t |  j j ƒ j | ƒ } t |  j j ƒ j | ƒ } t |  j j	 ƒ j | ƒ } n |  j } |  j
 } |  j } | rý t d | d | d |  j d |  j d |  j d |  j d | d |  j ƒ } | j | d	 ƒ nH t d | d | d |  j d |  j d |  j d |  j d | d |  j ƒ } x3 |  j j ƒ  D]" } | j | j | j j ƒ  ƒ qUW| S(   u   
        Returns a django ``EmailMessage`` or ``EmailMultiAlternatives`` object,
        depending on whether html_message is empty.
        t   subjectt   bodyt
   from_emailR$   t   bcct   cct
   connectiont   headersu	   text/htmlN(   R
   R'   t   templatet   NoneR   t   contextR   t   rendert   contentt   html_contentt   messaget   html_messageR   R)   R$   R*   R+   R-   t   attach_alternativeR   t   attachmentst   allt   attacht   namet   filet   read(   R%   R,   R'   t   _contextR4   R5   t   msgt
   attachment(    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyt   email_messageK   s,    			 c      	   C  s8  | d	 k r t ƒ  } n  d	 } yB t |  j p0 d } |  j d | ƒ j ƒ  t j } d } d } Wn7 t k
 r™ } t j	 } t
 | ƒ } t | ƒ j } n X| r³ | r³ | j ƒ  n  | |  _ |  j ƒ  | d k r| t j	 k r4|  j j d | d | d | ƒ q4n. | d k r4|  j j d | d | d | ƒ n  | S(
   u@   
        Actually send out the email and log the result
        u   defaultR,   u    i   t   statusR4   t   exception_typei   N(   R/   R   R   t   backend_aliasR@   t   sendt   STATUSt   sentt	   Exceptiont   failedt   strt   typeR!   t   closeRA   t   savet   logst   create(   R%   t	   log_levelt   disconnect_after_deliveryR,   RA   R4   RB   t   e(    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyt   dispatchn   s2    	
		

c         O  s#   |  j  ƒ  t t |  ƒ j | | Ž  S(   N(   t
   full_cleant   superR   RL   (   R%   t   argst   kwargs(    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyRL   ”   s    
(    N(0   R!   R"   t   __doc__t   PRIORITYt   lowt   _t   mediumt   hight   nowt   PRIORITY_CHOICESRE   RF   RH   t   queuedt   STATUS_CHOICESR   t	   CharFieldR   R)   R	   R$   R+   R*   t   TrueR'   t	   TextFieldR4   R5   t   PositiveSmallIntegerFieldRA   t   priorityt   DateTimeFieldt   createdt   last_updatedt   scheduled_timeR   R-   t
   ForeignKeyR.   R   R0   RC   R    R&   R/   R@   RR   RL   (    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR   !   s:   $*$!	#&t   Logc           B  s·   e  Z d  Z e j e d ƒ f e j e d ƒ f g Z e j	 e
 d e d d ƒZ e j d e ƒ Z e j d e ƒ Z e j d d	 d
 e ƒ Z e j ƒ  Z d d d „  ƒ  YZ d „  Z RS(   u=   
    A model to record sending email sending activities.
    u   sentu   failedt   editablet   related_nameu   logsR   R   R   iÿ   R   R    c           B  s   e  Z d  Z RS(   u   post_office(   R!   R"   R#   (    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR    §   s   c         C  s   t  |  j ƒ S(   N(   R   t   date(   R%   (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR&   ª   s    (    (   R!   R"   RW   RE   RF   RZ   RH   R`   R   Rj   R   t   Falset   emailRf   Rb   Rn   Rd   RA   Ra   RB   Rc   R4   R    R&   (    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyRk   ™   s   *t   EmailTemplatec           B  sb  e  Z d  Z e j d d d e d ƒ ƒ Z e j d e d e d ƒ ƒ Z	 e j
 d e ƒ Z e j
 d e ƒ Z e j d d d e d	 e d
 ƒ d e g ƒ Z e j d e d	 e d ƒ d e g ƒ Z e j d e d	 e d ƒ d e g ƒ Z e j d d d e j d e d ƒ d d d e ƒ Z e j d d d d e d d ƒZ d d d „  ƒ  YZ d „  Z d „  Z RS(   u4   
    Model to hold template information from db
    R   iÿ   t	   help_textu   e.g: 'welcome_email'R   u   Description of this template.R   R   t   verbose_nameu   SubjectR   u   Contentu   HTML contenti   R   u'   Render template in alternative languageR   u    u   selfRm   u   translated_templatesR   R    c           B  s,   e  Z d  Z d Z e d ƒ Z e d ƒ Z RS(   u   post_officeu   languageu   default_templateu   Email Templateu   Email Templates(   u   languageu   default_template(   R!   R"   R#   t   unique_togetherRZ   Rs   t   verbose_name_plural(    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR    Ä   s   c         C  s   d |  j  |  j f S(   Nu   %s %s(   R:   t   language(   R%   (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR&   Ê   s    c         O  sT   |  j  r% |  j r% |  j  j |  _ n  t t |  ƒ j | | Ž  } t j |  j ƒ | S(   N(   t   default_templateR:   RT   Rq   RL   R   t   delete(   R%   RU   RV   R.   (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyRL   Í   s
    N(    (   R!   R"   RW   R   Ra   RZ   R:   Rc   Rb   t   descriptionRf   Rg   Rh   R   R'   R2   R3   R   t	   LANGUAGESRv   Rj   R/   Rw   R    R&   RL   (    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyRq   ®   s(   	c         C  sH   |  j  s | |  _  n  d j d t ƒ  j d | j d ƒ d ƒ } d | S(   u)   Overriding to store the original filenameu   {name}.{ext}R:   t   extu   .iÿÿÿÿu   post_office_attachments/(   R:   t   formatR   t   hext   split(   t   instancet   filename(    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyt   get_upload_path×   s
    	t
   Attachmentc           B  so   e  Z d  Z e j d e ƒ Z e j d d d e d ƒ ƒ Z	 e j
 e d d ƒZ d d d	 „  ƒ  YZ d
 „  Z RS(   u1   
    A model describing an email attachment.
    t	   upload_toR   iÿ   Rr   u   The original filenameRm   u   attachmentsR    c           B  s   e  Z d  Z RS(   u   post_office(   R!   R"   R#   (    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR    ë   s   c         C  s   |  j  S(   N(   R:   (   R%   (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR&   î   s    (    (   R!   R"   RW   R   t	   FileFieldR   R;   Ra   RZ   R:   t   ManyToManyFieldR   t   emailsR    R&   (    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyR‚   â   s   N(0   t
   __future__R    t   uuidR   t   collectionsR   t   django.confR   t   django.core.mailR   R   t	   django.dbR   t   django.utils.translationR   RZ   t   django.utils.encodingR   t   post_office.fieldsR	   R
   t   ImportErrorR   t   django.templateR   R   t	   jsonfieldR   t   post_officeR   t   compatR   R   R   R   R   R   R   t   _maket   rangeRX   RE   t   ModelR   Rk   Rq   R   R‚   (    (    (    sk   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_post_office-2.0.6-py2.7.egg/post_office/models.pyt   <module>   s<   w(	