
    Ng?`                       d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	Z	ddl
mZmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZ dd	lmZmZ  ed
           ed           ed           ed          gZd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.d  Z/d! Z0d" Z1d# Z2d$ Z3d% Z4d& Z5d' Z6d( Z7d) Z8d* Z9d+ Z:d, Z;d- Z<d. Z=d/ Z>d0 Z? G d1 d2          Z@dS )3z5Test suite for `unstructured.partition.email` module.    )annotationsN)EmailMessage)Any)FixtureRequestMockassert_round_trips_through_JSONexample_doc_pathfunction_mock)chunk_by_title)CompositeElementListItemNarrativeTextTable
TableChunkTextTitle)EmailPartitioningContextpartition_emailz+This is a test email to use for unit tests.)textzImportant points:zRoses are redzViolets are bluec                     t          t          d                    t          d          t          d          t          d          gk    sJ d S )Neml/simple-rfc-822.emlz!This is an RFC 822 email message.a\  An RFC 822 message is characterized by its simple, text-based format, which includes a header and a body. The header contains structured fields such as "From", "To", "Date", and "Subject", each followed by a colon and the corresponding information. The body follows the header, separated by a blank line, and contains the main content of the email.zThe structure ensures compatibility and readability across different email systems and clients, adhering to the standards set by the Internet Engineering Task Force (IETF).r   r	   r        b/var/www/html/ai-engine/env/lib/python3.11/site-packages/test_unstructured/partition/test_email.pyAtest_partition_email_from_filename_can_partition_an_RFC_822_emailr   '   sm    +,DEEFF9::%	
 	
 		
 	
K      r   c                     t          t          d          d          5 } t          |           t          k    sJ 	 d d d            d S # 1 swxY w Y   d S )Neml/fake-email.emlrbfile)openr	   r   EXPECTED_OUTPUT)fs    r   5test_partition_email_from_file_can_partition_an_emailr%   9   s    	344d	;	; :qA&&&/99999: : : : : : : : : : : : : : : : : :s   AAAc                 x   t          j                    5 } t          t          d          d          5 }|                     |                                           d d d            n# 1 swxY w Y   |                     d           t          |           t          k    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r   r   r    )	tempfileSpooledTemporaryFiler"   r	   writereadseekr   r#   )r!   r$   s     r   Btest_partition_email_from_spooled_temp_file_can_partition_an_emailr,   >   s&   		&	(	( =D"#788$?? 	!1JJqvvxx   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!		!D)))_<<<<<= = = = = = = = = = = = = = = = = =s4   B/(A&B/&A*	*B/-A*	.3B//B36B3c                     t          t          d                    t          d          t          d          t          d          gk    sJ d S )Nzeml/mime-html-only.emlzThis is a text/html part.zjThe first emoticon, :) , was proposed by Scott Fahlman in 1982 to indicate just or sarcasm in text emails.zGmail was launched by Google in 2004 with 1 GB of free storage, significantly more than what other services offered at the time.r   r   r   r   Ttest_partition_email_can_partition_an_HTML_only_email_with_Base64_ISO_8859_1_charsetr.   G   sm    +,DEEFF122'	
 	
 	=	
 	

K 
 
 
 
 
 
r   c                     t          d          } t          | d          }t          | d          }|t          k    sJ |t          k    sJ ||k    sJ d S )Nr   
text/plaincontent_source	text/html)r	   r   r#   )	file_pathelements_from_textelements_from_htmls      r   Ltest_extract_email_from_text_plain_matches_elements_extracted_from_text_htmlr7   U   sp     !566I(<PPP(;OOO00000000!3333333r   c                 \    t          t          d                    } t          |            d S )Nr   )r   r	   r   elementss    r   )test_partition_email_round_trips_via_jsonr;   `   s-    /0DEEFFH#H-----r   c                 T    t          t          d                    t          k    sJ d S )Nzeml/fake-email-b64.emlr   r	   r#   r   r   r   Ntest_partition_email_partitions_an_HTML_part_with_Base64_encoded_UTF_8_charsetr>   h   s+    +,DEEFF/YYYYYYr   c                     t          t          d          d          } t          |           dk    sJ | d         j                            d          sJ d S )Nz'eml/email-no-utf8-2008-07-16.062410.emlr0   r1         u\   אני חושב שזה לא יהיה מקצועי והוגן שאני אראה לך היכן)r   r	   lenr   
startswithr9   s    r   Ztest_partition_email_partitions_a_text_plain_part_with_Base64_encoded_windows_1255_charsetrD   l   s~    BCC#  H
 x==BA;&&  (F  G  G  G  G  G  G  Gr   c                     t          t          d          dd          } t          |           dk    sJ t          | d         t                    sJ | d         j                            d          sJ d S )Nz'eml/email-no-utf8-2014-03-17.111517.emlr3   F)r2   process_attachmentsrA   r   z4Slava Gxyzxyz Hi Slava, The password for your Google)r   r	   rB   
isinstancer   r   rC   r9   s    r   ]test_partition_email_partitions_an_html_part_with_quoted_printable_encoded_ISO_8859_1_charsetrH   v   s    BCC"!  H x==Ahqk5)))))A;&&']^^^^^^^r   c                 J    t          t          d                    g k    sJ dS )z=Should produce no elements but should not raise an exception.zeml/empty.emlNr   r	   r   r   r   3test_partition_email_accepts_a_whitespace_only_filerK      s*    +O<<==CCCCCCr   c                 N    t          t          d          d          g k    sJ d S )Neml/mime-no-body.emlFrF   rJ   r   r   r   1test_partition_email_can_partition_an_empty_emailrO      s2    ()?@@V[\\\`bbbbbbbr   c                 N    t          t          d          d          g k    sJ d S )Nzeml/fake-encrypted.emlFrN   rJ   r   r   r   ;test_partition_email_does_not_break_on_an_encrypted_messagerQ      s2    ()ABBX]^^^bdddddddr   c                     t          t          d          d          } t          |           dk    sJ | d         }t          |t                    sJ |j        dk    sJ d S )Nz(eml/email-inline-content-disposition.emlFrN   rA   r   zThis is a test of inline)r   r	   rB   rG   r   r   )r:   es     r   Ttest_partition_email_finds_content_when_it_is_marked_with_content_disposition_inlinerT      sw    CDDZ_  H x==AAa6///////r   c                 Z    t          t          d                    } | t          k    sJ d S )Nz%eml/fake-email-malformed-encoding.eml)filenamer=   r9   s    r   5test_partition_email_from_filename_malformed_encodingrW      s3    (89`(a(abbbH&&&&&&r   c                     t          j        t          d          5  t                       d d d            d S # 1 swxY w Y   d S )Nz4no document specified; either a `filename` or `file`match)pytestraises
ValueErrorr   r   r   r   ?test_partition_email_raises_when_no_message_source_is_specifiedr^      s    	z)_	`	`	`                   s   8<<c                     t          j        t          d          5  t          t	          d          d           d d d            d S # 1 swxY w Y   d S )Nz5'application/json' is not a valid value for content_srY   r   application/jsonr1   )r[   r\   r]   r   r	   r   r   r   5test_partition_email_raises_with_invalid_content_typera      s    	z)`	a	a	a c c()=>>Oabbbbc c c c c c c c c c c c c c c c c cs   AAAc                    t          t          d                    } t          d | D                       sJ t          d | D                       sJ t          d | D                       sJ t          d | D                       sJ t          d | D                       sJ t          d | D                       sJ d S )Neml/mime-multi-to-cc-bcc.emlc              3  :   K   | ]}|j         j        d dgk    V  dS )John <john@example.com>Mary <mary@example.com>N)metadatabcc_recipient.0rS   s     r   	<genexpr>zZtest_partition_email_augments_message_body_elements_with_email_metadata.<locals>.<genexpr>   sG         	

 %>@Y$ZZ     r   c              3  :   K   | ]}|j         j        d dgk    V  dS )Tom <tom@example.com>Alice <alice@example.com>N)rg   cc_recipientri   s     r   rk   zZtest_partition_email_augments_message_body_elements_with_email_metadata.<locals>.<genexpr>   sG         	

$;=X#YY     r   c              3  6   K   | ]}|j         j        d k    V  dS )z2143658709@example.comN)rg   email_message_idri   s     r   rk   zZtest_partition_email_augments_message_body_elements_with_email_metadata.<locals>.<genexpr>   s-      YY1qz*.FFYYYYYYr   c              3  8   K   | ]}|j         j        d gk    V  dS )sender@example.comN)rg   	sent_fromri   s     r   rk   zZtest_partition_email_augments_message_body_elements_with_email_metadata.<locals>.<genexpr>   s0      PP!qz#(<'==PPPPPPr   c              3  :   K   | ]}|j         j        d dgk    V  dS )Bob <bob@example.com>Sue <sue@example.com>N)rg   sent_tori   s     r   rk   zZtest_partition_email_augments_message_body_elements_with_email_metadata.<locals>.<genexpr>   sD        UV
68OPP     r   c              3  6   K   | ]}|j         j        d k    V  dS )zExample Plain-Text MIME MessageN)rg   subjectri   s     r   rk   zZtest_partition_email_augments_message_body_elements_with_email_metadata.<locals>.<genexpr>   s-      YY1qz!%FFYYYYYYr   r   r	   allr9   s    r   Gtest_partition_email_augments_message_body_elements_with_email_metadatar}      s8   /0NOOPPH                    YYPXYYYYYYYYPPxPPPPPPPP  Zb        YYPXYYYYYYYYYYr   c                     t          t          d                    } t          d | D                       sJ t          d | D                       sJ d S )Nr   c              3  6   K   | ]}|j         j        d k    V  dS )zfake-email.emlNrg   rV   ri   s     r   rk   z[test_partition_email_from_filename_gets_filename_metadata_from_file_path.<locals>.<genexpr>   s-      II1qz"&66IIIIIIr   c              3  P   K   | ]!}|j         j        t          d           k    V  "dS )emlN)rg   file_directoryr	   ri   s     r   rk   z[test_partition_email_from_filename_gets_filename_metadata_from_file_path.<locals>.<genexpr>   s5      VVqz(,<U,C,CCVVVVVVr   r{   r9   s    r   Htest_partition_email_from_filename_gets_filename_metadata_from_file_pathr      se    /0DEEFFHIIIIIIIIIIVVXVVVVVVVVVVr   c                     t          t          d          d          5 } t          |           }d d d            n# 1 swxY w Y   t          d |D                       sJ t          d |D                       sJ d S )Nr   r   r    c              3  2   K   | ]}|j         j        d u V  d S Nr   ri   s     r   rk   zMtest_partition_email_from_file_gets_filename_metadata_None.<locals>.<genexpr>   s,      ==qqz"d*======r   c              3  2   K   | ]}|j         j        d u V  d S r   rg   r   ri   s     r   rk   zMtest_partition_email_from_file_gets_filename_metadata_None.<locals>.<genexpr>   s,      CCQqz(D0CCCCCCr   r"   r	   r   r|   r$   r:   s     r   :test_partition_email_from_file_gets_filename_metadata_Noner      s    	344d	;	; +q"***+ + + + + + + + + + + + + + + ==H========CC(CCCCCCCCCC   ;??c                     t          t          d          d          } t          d | D                       sJ t          d | D                       sJ d S )Nr   	a/b/c.eml)metadata_filenamec              3  6   K   | ]}|j         j        d k    V  dS )zc.emlNr   ri   s     r   rk   zOtest_partition_email_from_filename_prefers_metadata_filename.<locals>.<genexpr>   ,      @@!qz"g-@@@@@@r   c              3  6   K   | ]}|j         j        d k    V  dS )za/bNr   ri   s     r   rk   zOtest_partition_email_from_filename_prefers_metadata_filename.<locals>.<genexpr>   ,      DDaqz(E1DDDDDDr   r{   r9   s    r   <test_partition_email_from_filename_prefers_metadata_filenamer      sr    -..+  H @@x@@@@@@@@DD8DDDDDDDDDDr   c                     t          t          d          d          5 } t          | d          }d d d            n# 1 swxY w Y   t          d |D                       sJ t          d |D                       sJ d S )Nr   r   z	d/e/f.eml)r!   r   c              3  6   K   | ]}|j         j        d k    V  dS )zf.emlNr   ri   s     r   rk   zKtest_partition_email_from_file_prefers_metadata_filename.<locals>.<genexpr>   r   r   c              3  6   K   | ]}|j         j        d k    V  dS )zd/eNr   ri   s     r   rk   zKtest_partition_email_from_file_prefers_metadata_filename.<locals>.<genexpr>   r   r   r   r   s     r   8test_partition_email_from_file_prefers_metadata_filenamer      s    	344d	;	; Jq"[IIIJ J J J J J J J J J J J J J J @@x@@@@@@@@DD8DDDDDDDDDDs   <A A c                     dt          t          d                    } t          fd| D                       s-J d dt          | d         j        j                               d S )Nzmessage/rfc822r   c              3  8   K   | ]}|j         j        k    V  d S r   )rg   filetype)rj   rS   EML_MIME_TYPEs     r   rk   zmtest_partition_email_gets_the_EML_MIME_type_in_metadata_filetype_for_message_body_elements.<locals>.<genexpr>   s-      FFqz"m3FFFFFFr   zExpected all elements to have 'z' as their filetype, but got: r   )r   r	   r|   reprrg   r   )r:   r   s    @r   Ztest_partition_email_gets_the_EML_MIME_type_in_metadata_filetype_for_message_body_elementsr      s    $M/0DEEFFHFFFFXFFFFF  	2- 	2 	2!%.//	2 	2    r   c                 t    t          t          d                    } t          d | D                       sJ d S )Nr   c              3  8   K   | ]}|j         j        d gk    V  dS )engNrg   	languagesri   s     r   rk   zFtest_partition_email_element_metadata_has_languages.<locals>.<genexpr>   s.      AA1qz#w.AAAAAAr   r{   r9   s    r   3test_partition_email_element_metadata_has_languagesr      sB    /0DEEFFHAAAAAAAAAAAAr   c                 z    t          t          d          dg          } t          d | D                       sJ d S )Nr   deu)r   c              3  8   K   | ]}|j         j        d gk    V  dS )r   Nr   )rj   elements     r   rk   z>test_partition_email_respects_languages_arg.<locals>.<genexpr>  s/      MMw)eW4MMMMMMr   r{   r9   s    r   +test_partition_email_respects_languages_argr      sK    /0DEERWQXYYYHMMHMMMMMMMMMMr   c                 r    t          t          d          d          } d | D             }d|v sJ d|v sJ d S )Nzlanguage-docs/eng_spa_mult.emlT)detect_language_per_elementc                J    h | ] }|j         j        |j         j        d         !S )Nr   r   ri   s     r   	<setcomp>zJtest_partition_eml_respects_detect_language_per_element.<locals>.<setcomp>  s,    [[[!*:N:ZQZ!!$:Z:Z:Zr   r   sparJ   )r:   langss     r   7test_partition_eml_respects_detect_language_per_elementr     sY    9::$(  H \[h[[[EE>>>>E>>>>>>r   c                 t    t          t          d                    } t          d | D                       sJ d S )Nr   c              3  6   K   | ]}|j         j        d k    V  dS z2022-12-16T22:04:16+00:00Nrg   last_modifiedri   s     r   rk   zZtest_partition_email_from_file_path_gets_last_modified_from_Date_header.<locals>.<genexpr>  -      YY1qz'+FFYYYYYYr   r{   r9   s    r   Gtest_partition_email_from_file_path_gets_last_modified_from_Date_headerr     sC    /0DEEFFHYYPXYYYYYYYYYYr   c                     t          t          d          d          5 } t          |           }d d d            n# 1 swxY w Y   t          d |D                       sJ d S )Nr   r   r    c              3  6   K   | ]}|j         j        d k    V  dS r   r   ri   s     r   rk   zUtest_partition_email_from_file_gets_last_modified_from_Date_header.<locals>.<genexpr>  r   r   r   r   s     r   Btest_partition_email_from_file_gets_last_modified_from_Date_headerr     s    	344d	;	; +q"***+ + + + + + + + + + + + + + + YYPXYYYYYYYYYYr   c                     dt          t          d                    } t          fd| D                       sJ d S )N2020-07-05T09:24:28r   metadata_last_modifiedc              3  8   K   | ]}|j         j        k    V  d S r   r   rj   rS   r   s     r   rk   zUtest_partition_email_from_file_path_prefers_metadata_last_modified.<locals>.<genexpr>(  .      TTaqz'+AATTTTTTr   r{   )r:   r   s    @r   Btest_partition_email_from_file_path_prefers_metadata_last_modifiedr   !  s]    2-..G]  H TTTT8TTTTTTTTTTr   c                     dt          t          d          d          5 } t          |           }d d d            n# 1 swxY w Y   t          fd|D                       sJ d S )Nr   r   r   )r!   r   c              3  8   K   | ]}|j         j        k    V  d S r   r   r   s     r   rk   zPtest_partition_email_from_file_prefers_metadata_last_modified.<locals>.<genexpr>0  r   r   r   )r$   r:   r   s     @r   =test_partition_email_from_file_prefers_metadata_last_modifiedr   +  s    2	344d	;	; Zq"BXYYYZ Z Z Z Z Z Z Z Z Z Z Z Z Z Z TTTT8TTTTTTTTTTs   ?AAc                     t          t          d                    } t          t          d          d          }t          |           }t          d |D                       sJ || k    sJ ||k    sJ dS )zBNote it's actually the delegate partitioners that do the chunking.zeml/fake-email.txtby_title)chunking_strategyc              3  Z   K   | ]&}t          |t          t          t          f          V  'd S r   )rG   r   r   r   rj   cs     r   rk   zAtest_partition_email_chunks_when_so_instructed.<locals>.<genexpr><  s4      TTz!.zBCCTTTTTTr   N)r   r	   r   r|   )r:   chunksseparately_chunked_chunkss      r   .test_partition_email_chunks_when_so_instructedr   6  s    /0DEEFFH-.BCCWabbbF .x 8 8TTVTTTTTTTTX.......r   c                 L   t          t          d          dd          } t          |           dk    sJ t          d | D                       sJ | d         }|j        dk    sJ |j        j        d	k    sJ |j        j        d
k    sJ t          d | D                       sJ d S )Neml/fake-email-attachment.emlr   T)r   rF      c              3  @   K   | ]}t          |t                    V  d S r   )rG   r   r   s     r   rk   z>test_partition_email_chunks_attachments_too.<locals>.<genexpr>I  s-      ??1z!-..??????r   Hey this is a fake attachment!fake-attachment.txtfake-email-attachment.emlc              3  6   K   | ]}|j         j        d k    V  dS z2022-12-23T18:08:48+00:00Nr   r   s     r   rk   z>test_partition_email_chunks_attachments_too.<locals>.<genexpr>N  s-      WW1qz'+FFWWWWWWr   )r   r	   rB   r|   r   rg   rV   attached_to_filename)r   attachment_chunks     r   +test_partition_email_chunks_attachments_toor   A  s    899$   F v;;!??????????bz $DDDDD$-1FFFFF$9=XXXXXWWPVWWWWWWWWWWr   c                     t          t          d          d          } | t          d          t          d          gk    sJ d S )Nz(eml/email-equals-attachment-filename.emlTrN   z&Below is an example of an odd filenamezOdd filename)r   r	   r   r   r9   s    r   Ctest_partition_email_also_partitions_attachments_when_so_instructedr   T  sd    CDDZ^  H >??n      r   c                    t          t          d          d          } | t          d          t          d          t          d          t	          d          t	          d          t	          d	          t          d
          t          d          t          d          g	k    sJ t          d | D                       sJ | d         }|j        dk    sJ |j        j	        dk    sJ |j        j
        dk    sJ d S )Nr   TrN   zHello!zHere's the attachments!zIt includes:zLots of whitespacezLittle to no contentzand is a quick readzBest,Mallorir   c              3  6   K   | ]}|j         j        d k    V  dS r   r   ri   s     r   rk   z?test_partition_email_can_process_attachments.<locals>.<genexpr>o  r   r   r   r   r   )r   r	   r   r   r   r   r|   r   rg   rV   r   )r:   attachment_elements     r   ,test_partition_email_can_process_attachmentsr   _  s!   899t  H h/00n%%%&&'((&''Wi677
 
 
 
 
 YYPXYYYYYYYY!""&FFFFF&/3HHHHH&;?ZZZZZZZr   c                 n    t          t          d          d          } | t          d          gk    sJ d S )Nzeml/mime-attach-mp3.emlTrN   z(This is an email with an MP3 attachment.r   r9   s    r   Ctest_partition_email_silently_skips_attachments_it_cannot_partitionr   v  sX    233  H
 @AA      r   c                     e Zd ZdZd7dZd7dZd7dZd7dZd Zd	 Z	d
 Z
d Zd Zd Zd Zej                            dddg          d8d            Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd9d"Zd# Zd$ Zd% Zd& Z ej                            d'd(d)g          d:d+            Z!d, Z"d- Z#d. Z$d/ Z%d0 Z& ej'                    d;d2            Z( ej'                    d<d5            Z)d6S )=DescribeEmailPartitionerOptionszTUnit-test suite for `unstructured.partition.email.EmailPartitioningContext` objects.ctx_argsdict[str, Any]c                z    t          d          |d<   t          j        di |}t          |t                    sJ d S )Nr   r4   r   )r	   r   loadrG   )selfr   ctxs      r   $it_provides_a_validating_constructorzDDescribeEmailPartitionerOptions.it_provides_a_validating_constructor  sH     01E F F&+77h77#78888888r   c                    t          j        t          d          5  t          j        di | d d d            d S # 1 swxY w Y   d S )Nz1no document specified; either a `filename` or `firY   r   )r[   r\   r]   r   r   r   r   s     r   3but_it_raises_when_no_source_document_was_specifiedzSDescribeEmailPartitionerOptions.but_it_raises_when_no_source_document_was_specified  s    ]:-`aaa 	6 	6$)55H555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   ;??c                    t          j        d          |d<   t          j        t          d          5  t          j        di | d d d            d S # 1 swxY w Y   d S )Nabcdefgr!   z)file object must be opened in binary moderY   r   )ioStringIOr[   r\   r]   r   r   r   s     r   6and_it_raises_when_a_file_open_for_reading_str_is_usedzVDescribeEmailPartitionerOptions.and_it_raises_when_a_file_open_for_reading_str_is_used  s    ;y11]:-XYYY 	6 	6$)55H555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6   AAAc                    t          d          |d<   d|d<   t          j        t          d          5  t	          j        di | d d d            d S # 1 swxY w Y   d S )Nr   r4   r`   r2   z1'application/json' is not a valid value for conterY   r   )r	   r[   r\   r]   r   r   r   s     r   9and_it_raises_when_an_invalid_content_source_is_specifiedzYDescribeEmailPartitionerOptions.and_it_raises_when_an_invalid_content_source_is_specified  s     01E F F%7!"]:-`aaa 	6 	6$)55H555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6r   c                \    t          t          d                    }|j        ddgk    sJ d S )Nrc   re   rf   r   r	   bcc_addressesr   r   s     r   4it_provides_access_to_the_Bcc_addresses_when_presentzTDescribeEmailPartitionerOptions.it_provides_access_to_the_Bcc_addresses_when_present  s:    &'78V'W'WXX %>@Y$ZZZZZZZr   c                P    t          t          d                    }|j        J d S Nr   r   r   s     r   3but_it_returns_None_when_there_are_no_Bcc_addresseszSDescribeEmailPartitionerOptions.but_it_returns_None_when_there_are_no_Bcc_addresses  s.    &'78P'Q'QRR (((((r   c                    t          t          d                    }|j        }t          |t                    sJ |                                }t          |t                    sJ |                    d          sJ d S )N!eml/mime-different-plain-html.emlz<!DOCTYPE html>r   r	   	body_partrG   r   get_contentstrrC   r   r   r  contents       r   :it_returns_the_html_body_part_when_there_is_one_by_defaultzZDescribeEmailPartitionerOptions.it_returns_the_html_body_part_when_there_is_one_by_default  s~    &'78['\'\]]M	)\22222''))'3'''''!!"34444444r   c                   t          t          d          d          }|j        }t          |t                    sJ |                                }t          |t                    sJ |                    d          sJ d S )Nr  r0   r1   zThis is the text/plain part.r  r  s       r   Kbut_it_returns_the_plain_text_body_part_when_there_is_one_when_so_requestedzkDescribeEmailPartitionerOptions.but_it_returns_the_plain_text_body_part_when_there_is_one_when_so_requested  s    &@AAR^
 
 
 M	)\22222''))'3'''''!!"@AAAAAAAr   c                P    t          t          d                    }|j        J d S )NrM   )r   r	   r  r   s     r   .and_it_returns_None_when_the_email_has_no_bodyzNDescribeEmailPartitionerOptions.and_it_returns_None_when_the_email_has_no_body  s-    &'78N'O'OPP}$$$$$r   c                \    t          t          d                    }|j        ddgk    sJ d S )Nrc   rm   rn   r   r	   cc_addressesr   s     r   3it_provides_access_to_the_Cc_addresses_when_presentzSDescribeEmailPartitionerOptions.it_provides_access_to_the_Cc_addresses_when_present  s:    &'78V'W'WXX$;=X#YYYYYYYr   c                P    t          t          d                    }|j        J d S r   r  r   s     r   2but_it_returns_None_when_there_are_no_Cc_addresseszRDescribeEmailPartitionerOptions.but_it_returns_None_when_there_are_no_Cc_addresses  s.    &'78P'Q'QRR'''''r   )r2   expected_value)r3   htmlplain)r0   )r  r  r2   r  r  tuple[str, ...]c                @    t          |          }|j        |k    sJ d S )Nr1   r   content_type_preference)r   r2   r  r   s       r   ?it_knows_whether_the_caller_prefers_the_HTML_or_plain_text_bodyz_DescribeEmailPartitionerOptions.it_knows_whether_the_caller_prefers_the_HTML_or_plain_text_body  s.     'nEEE*n<<<<<<r   c                <    t                      }|j        dk    sJ d S )Nr  r  r   s     r   +and_it_defaults_to_preferring_the_HTML_bodyzKDescribeEmailPartitionerOptions.and_it_defaults_to_preferring_the_HTML_body  s(    &((*.???????r   c                X    t          t          d                    }|j        dk    sJ d S )Neml/mime-simple.emlrs   )r   r	   from_addressr   s     r   &it_knows_the_From_address_of_the_emailzFDescribeEmailPartitionerOptions.it_knows_the_From_address_of_the_email  s4    &'78M'N'NOO#7777777r   c                X    t          t          d                    }|j        dk    sJ d S )Nr!  z1234567890@example.comr   r	   
message_idr   s     r   1it_provides_access_to_the_Message_ID_when_presentzQDescribeEmailPartitionerOptions.it_provides_access_to_the_Message_ID_when_present  s3    &'78M'N'NOO~!9999999r   c                P    t          t          d                    }|j        J d S r   r%  r   s     r   6but_it_returns_None_when_there_is_no_Message_ID_headerzVDescribeEmailPartitionerOptions.but_it_returns_None_when_there_is_no_Message_ID_header  s-    &'78P'Q'QRR~%%%%%r   c                @    t          d          }|j        dk    sJ d S )Nr   )metadata_file_pathr   r+  r   s     r   >it_uses_the_metadata_file_path_arg_value_when_one_was_providedz^DescribeEmailPartitionerOptions.it_uses_the_metadata_file_path_arg_value_when_one_was_provided  s,    &+FFF%444444r   c                @    t          d          }|j        dk    sJ d S )Nz	x/y/z.emlr4   r,  r   s     r   Land_it_uses_the_file_path_arg_value_when_metadata_file_path_was_not_providedzlDescribeEmailPartitionerOptions.and_it_uses_the_file_path_arg_value_when_metadata_file_path_was_not_provided  s,    &===%444444r   c                4    t                      }|j        J d S r   r,  r   s     r   7and_it_returns_None_when_neither_file_path_was_providedzWDescribeEmailPartitionerOptions.and_it_returns_None_when_neither_file_path_was_provided  s"    &((%-----r   c                D    d}t          |          }|j        |k    sJ d S )Nz2023-04-08T12:18:07r   )r   r   )r   r   r   s      r   Bit_uses_the_metadata_last_modified_arg_value_when_one_was_providedzbDescribeEmailPartitionerOptions.it_uses_the_metadata_last_modified_arg_value_when_one_was_provided  s4    !6&>TUUU)-CCCCCCCr   c                X    t          t          d                    }|j        dk    sJ d S )Nr   z2024-10-01T17:34:56+00:00)r   r	   r   r   s     r   Qand_it_uses_the_msg_Date_header_date_when_metadata_last_modified_was_not_providedzqDescribeEmailPartitionerOptions.and_it_uses_the_msg_Date_header_date_when_metadata_last_modified_was_not_provided  s4    &'78P'Q'QRR)-HHHHHHHr   get_last_modified_date_r   c                j    d}||_         t          t          d                    }|j        |k    sJ dS )zKNot an expected case as according to RFC 5322, the Date header is required.z2024-07-09T14:08:17eml/rfc822-no-date.emlN)return_valuer   r	   r   )r   r7  filesystem_last_modifiedr   s       r   Land_it_falls_back_to_filesystem_last_modified_when_no_Date_header_is_presentzlDescribeEmailPartitionerOptions.and_it_falls_back_to_filesystem_last_modified_when_no_Date_header_is_present  sE     $9 /G,&'78P'Q'QRR)-EEEEEEEr   c                    t          t          d          d          5 }t          |          }|j        J 	 d d d            d S # 1 swxY w Y   d S )Nr9  r   r    )r"   r	   r   r   r   r$   r   s      r   6and_it_returns_None_when_no_last_modified_is_availablezVDescribeEmailPartitionerOptions.and_it_returns_None_when_no_last_modified_is_available  s    "#;<<dCC 	6q*222C-5555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   AA
A
c                x    t          t          d                    }t          |j        t                    sJ d S )Nr   r/  )r   r	   rG   msgr   r   s     r   Fit_loads_the_email_message_from_the_filesystem_when_a_path_is_providedzfDescribeEmailPartitionerOptions.it_loads_the_email_message_from_the_filesystem_when_a_path_is_provided"  s:    &1ABZ1[1[\\\#'<0000000r   c                    t          t          d          d          5 }t          |          }t          |j        t
                    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r   r    )r"   r	   r   rG   rA  r   r>  s      r   Kand_it_loads_the_email_message_from_a_file_like_object_when_one_is_providedzkDescribeEmailPartitionerOptions.and_it_loads_the_email_message_from_a_file_like_object_when_one_is_provided&  s    "#;<<dCC 	5q*222Ccg|444444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   -AA Ac                J    ddd}t          |          }|j        |k    sJ d S )Nbarqux)foobaz)kwargs)r   partitioning_kwargs)r   rJ  r   s      r   6it_passes_along_the_kwargs_it_received_on_constructionzVDescribeEmailPartitionerOptions.it_passes_along_the_kwargs_it_received_on_construction-  s9    u--&f555&&000000r   rF   TFboolc                @    t          |          }|j        |k    sJ d S )NrN   r   rF   )r   rF   r   s      r   ?it_knows_whether_the_caller_wants_to_also_partition_attachmentsz_DescribeEmailPartitionerOptions.it_knows_whether_the_caller_wants_to_also_partition_attachments5  s0     ';NOOO&*=======r   c                8    t                      }|j        du sJ d S )NFrO  r   s     r   %but_by_default_it_ignores_attachmentszEDescribeEmailPartitionerOptions.but_by_default_it_ignores_attachments<  s'    &((&%//////r   c                X    t          t          d                    }|j        dk    sJ d S )Nz!eml/mime-word-encoded-subject.emlu(   Simple email with ☸☿ Unicode subjectr   r	   rz   r   s     r   3it_provides_access_to_the_email_Subject_as_a_stringzSDescribeEmailPartitionerOptions.it_provides_access_to_the_email_Subject_as_a_stringB  s3    &'78['\'\]]{HHHHHHHr   c                P    t          t          d                    }|j        J d S )Nzeml/mime-no-subject.emlrT  r   s     r   3but_it_returns_None_when_there_is_no_Subject_headerzSDescribeEmailPartitionerOptions.but_it_returns_None_when_there_is_no_Subject_headerF  s-    &'78Q'R'RSS{"""""r   c                \    t          t          d                    }|j        ddgk    sJ d S )Nrc   rv   rw   r   r	   to_addressesr   s     r   3it_provides_access_to_the_To_addresses_when_presentzSDescribeEmailPartitionerOptions.it_provides_access_to_the_To_addresses_when_presentL  s:    &'78V'W'WXX$;=T#UUUUUUUr   c                P    t          t          d                    }|j        J d S )Nzeml/mime-no-to.emlrY  r   s     r   2but_it_returns_None_when_there_are_no_To_addresseszRDescribeEmailPartitionerOptions.but_it_returns_None_when_there_are_no_To_addressesP  s.    &'78L'M'MNN'''''r   returnc                    d d dd d di dS )Nr3   F)r4   r!   r2   r+  r   rF   rJ  r   )r   s    r   r   z(DescribeEmailPartitionerOptions.ctx_argsV  s(     )"&&*#(
 
 	
r   requestr   c                "    t          |d          S )Nz3unstructured.partition.email.get_last_modified_date)r
   )r   r`  s     r   r7  z7DescribeEmailPartitionerOptions.get_last_modified_date_b  s    W&[\\\r   N)r   r   )r2   r  r  r  )r7  r   )rF   rM  )r^  r   )r`  r   r^  r   )*__name__
__module____qualname____doc__r   r   r   r   r   r  r
  r  r  r  r  r[   markparametrizer  r  r#  r'  r)  r-  r0  r2  r4  r6  r<  r?  rB  rD  rL  rP  rR  rU  rW  r[  r]  fixturer   r7  r   r   r   r   r     s       ^^9 9 9 96 6 6 66 6 6 6
6 6 6 6[ [ [) ) )5 5 5
B 
B 
B% % %Z Z Z( ( ( [,,-	
 = = = =@ @ @8 8 8: : :& & &5 5 55 5 5. . .D D D
I I I	F 	F 	F 	F6 6 61 1 15 5 51 1 1 [2T5MBB> > > CB>0 0 0I I I# # #V V V( ( ( V^	
 	
 	
 	
 V^] ] ] ] ] ]r   r   )Are  
__future__r   r   r'   email.messager   typingr   r[   test_unstructured.unit_utilsr   r   r   r	   r
   unstructured.chunking.titler   unstructured.documents.elementsr   r   r   r   r   r   r   unstructured.partition.emailr   r   r#   r   r%   r,   r.   r7   r;   r>   rD   rH   rK   rO   rQ   rT   rW   r^   ra   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>rp     s   ; ; " " " " " " 				  & & & & & &                     7 6 6 6 6 6                  S R R R R R R R MDEEE	E"###H/"""H$%%%	  $: : :
= = =  4 4 4. . .Z Z ZG G G	_ 	_ 	_D D D
    0 0 0' ' '  
c c cZ Z Z,W W WD D DE E EE E E  B B B
N N N

 
 
 Z Z Z
Z Z ZU U UU U U/ / /X X X&  [ [ [.
 
 
$\] \] \] \] \] \] \] \] \] \]r   