a
    ¡˜ëjŒ`  ã                   @  sâ  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
d�edd�edd�edd�gZdd„ Zdd„ Zdd„ Z dd„ Z!dd„ Z"dd„ Z#dd„ Z$dd„ Z%dd „ Z&d!d"„ Z'd#d$„ Z(d%d&„ Z)d'd(„ Z*d)d*„ Z+d+d,„ Z,d-d.„ Z-d/d0„ Z.d1d2„ Z/d3d4„ Z0d5d6„ Z1d7d8„ Z2d9d:„ Z3d;d<„ Z4d=d>„ Z5d?d@„ Z6dAdB„ Z7dCdD„ Z8dEdF„ Z9dGdH„ Z:dIdJ„ Z;dKdL„ Z<dMdN„ Z=dOdP„ Z>dQdR„ Z?G dSdT„ dTƒZ@dS )Uz5Test 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                   C  s*   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.z¬The 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   © r   r   úe/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/test_unstructured/partition/test_email.pyÚAtest_partition_email_from_filename_can_partition_an_RFC_822_email'   s    
ÿÿ÷r   c                  C  sD   t tdƒdƒ�"} t| d�tks"J ‚W d   ƒ n1 s60    Y  d S )Núeml/fake-email.emlÚrb©Úfile)Úopenr   r   ÚEXPECTED_OUTPUT)Úfr   r   r   Ú5test_partition_email_from_file_can_partition_an_email9   s    r"   c               	   C  s„   t  ¡ �h} ttdƒdƒ�}|  | ¡ ¡ W d   ƒ n1 s<0    Y  |  d¡ t| d�tksbJ ‚W d   ƒ n1 sv0    Y  d S )Nr   r   r   r   )	ÚtempfileÚSpooledTemporaryFiler   r   ÚwriteÚreadÚseekr   r    )r   r!   r   r   r   ÚBtest_partition_email_from_spooled_temp_file_can_partition_an_email>   s
    
,
r(   c                   C  s*   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.z€Gmail 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   r   ÚTtest_partition_email_can_partition_an_HTML_only_email_with_Base64_ISO_8859_1_charsetG   s    
ÿÿúr)   c                  C  sh   t dƒ} t| dd�}t| dd�}tdd„ t|tƒD ƒƒs<J ‚|tksHJ ‚tdd„ t||ƒD ƒƒsdJ ‚d S )Nr   ú
text/plain©Úcontent_sourceú	text/htmlc                 s  s   | ]\}}|j |j kV  qd S ©Nr   )Ú.0ÚeÚeor   r   r   Ú	<genexpr>[   ó    z_test_extract_email_from_text_plain_matches_elements_extracted_from_text_html.<locals>.<genexpr>c                 s  s   | ]\}}|j |j kV  qd S r.   r   )r/   ÚehÚetr   r   r   r2   ]   r3   )r   r   ÚallÚzipr    )Ú	file_pathZelements_from_textZelements_from_htmlr   r   r   ÚLtest_extract_email_from_text_plain_matches_elements_extracted_from_text_htmlU   s    r9   c                  C  s   t tdƒƒ} t| ƒ d S )Nr   )r   r   r   ©Úelementsr   r   r   Ú)test_partition_email_round_trips_via_json`   s    r<   c                   C  s   t tdƒƒtksJ ‚d S )Nzeml/fake-email-b64.eml©r   r   r    r   r   r   r   ÚNtest_partition_email_partitions_an_HTML_part_with_Base64_encoded_UTF_8_charseth   s    r>   c                  C  s8   t tdƒdd�} t| ƒdks J ‚| d j d¡s4J ‚d S )Nz'eml/email-no-utf8-2008-07-16.062410.emlr*   r+   é   é   u\   ×�× ×™ ×—×•×©×‘ ×©×–×” ×œ×� ×™×”×™×” ×ž×§×¦×•×¢×™ ×•×”×•×’×Ÿ ×©×�× ×™ ×�×¨×�×” ×œ×š ×”×™×›×Ÿ)r   r   Úlenr   Ú
startswithr:   r   r   r   ÚZtest_partition_email_partitions_a_text_plain_part_with_Base64_encoded_windows_1255_charsetl   s    þrC   c                  C  sL   t tdƒddd�} t| ƒdks"J ‚t| d tƒs4J ‚| d j d¡sHJ ‚d S )Nz'eml/email-no-utf8-2014-03-17.111517.emlr-   F)r,   Úprocess_attachmentsr@   r   z4Slava Gxyzxyz Hi Slava, The password for your Google)r   r   rA   Ú
isinstancer   r   rB   r:   r   r   r   Ú]test_partition_email_partitions_an_html_part_with_quoted_printable_encoded_ISO_8859_1_charsetv   s    ýrF   c                   C  s   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   r   Ú3test_partition_email_accepts_a_whitespace_only_file…   s    rH   c                   C  s   t tdƒdd�g ksJ ‚d S )Núeml/mime-no-body.emlF©rD   rG   r   r   r   r   Ú1test_partition_email_can_partition_an_empty_emailŠ   s    ÿrK   c                   C  s   t tdƒdd�g ksJ ‚d S )Nzeml/fake-encrypted.emlFrJ   rG   r   r   r   r   Ú;test_partition_email_does_not_break_on_an_encrypted_message�   s    ÿrL   c                  C  sH   t tdƒdd�} t| ƒdks J ‚| d }t|tƒs6J ‚|jdksDJ ‚d S )Nz(eml/email-inline-content-disposition.emlFrJ   r@   r   zThis is a test of inline)r   r   rA   rE   r   r   )r;   r0   r   r   r   ÚTtest_partition_email_finds_content_when_it_is_marked_with_content_disposition_inline–   s    ÿrM   c                  C  s   t tdƒd�} | tksJ ‚d S )Nz%eml/fake-email-malformed-encoding.eml)Úfilenamer=   r:   r   r   r   Ú5test_partition_email_from_filename_malformed_encoding¡   s    rO   c                   C  s8   t jtdd�� tƒ  W d   ƒ n1 s*0    Y  d S )Nz4no document specified; either a `filename` or `file`©Úmatch)ÚpytestÚraisesÚ
ValueErrorr   r   r   r   r   Ú?test_partition_email_raises_when_no_message_source_is_specified©   s    rU   c                   C  sB   t jtdd��  ttdƒdd� W d   ƒ n1 s40    Y  d S )Nz5'application/json' is not a valid value for content_srP   r   úapplication/jsonr+   )rR   rS   rT   r   r   r   r   r   r   Ú5test_partition_email_raises_with_invalid_content_type®   s    rW   c                  C  s”   t tdƒƒ} tdd„ | D ƒƒs"J ‚tdd„ | D ƒƒs8J ‚tdd„ | D ƒƒsNJ ‚tdd„ | D ƒƒsdJ ‚tdd„ | D ƒƒszJ ‚tdd„ | D ƒƒs�J ‚d S )	Núeml/mime-multi-to-cc-bcc.emlc                 s  s   | ]}|j jd dgkV  qdS )úJohn <john@example.com>úMary <mary@example.com>N)ÚmetadataZbcc_recipient©r/   r0   r   r   r   r2   ¹   s   ÿzZtest_partition_email_augments_message_body_elements_with_email_metadata.<locals>.<genexpr>c                 s  s   | ]}|j jd dgkV  qdS )úTom <tom@example.com>úAlice <alice@example.com>N)r[   Zcc_recipientr\   r   r   r   r2   ½   s   ÿc                 s  s   | ]}|j jd kV  qdS )z2143658709@example.comN)r[   Zemail_message_idr\   r   r   r   r2   Á   r3   c                 s  s   | ]}|j jd gkV  qdS )úsender@example.comN)r[   Z	sent_fromr\   r   r   r   r2   Â   r3   c                 s  s   | ]}|j jd dgkV  qdS )úBob <bob@example.com>úSue <sue@example.com>N)r[   Zsent_tor\   r   r   r   r2   Ã   s   c                 s  s   | ]}|j jd kV  qdS )zExample Plain-Text MIME MessageN)r[   Úsubjectr\   r   r   r   r2   Æ   r3   ©r   r   r6   r:   r   r   r   ÚGtest_partition_email_augments_message_body_elements_with_email_metadata¶   s    þþÿrd   c                  C  s<   t tdƒƒ} tdd„ | D ƒƒs"J ‚tdd„ | D ƒƒs8J ‚d S )Nr   c                 s  s   | ]}|j jd kV  qdS )zfake-email.emlN©r[   rN   r\   r   r   r   r2   Ï   r3   z[test_partition_email_from_filename_gets_filename_metadata_from_file_path.<locals>.<genexpr>c                 s  s   | ]}|j jtd ƒkV  qdS )ZemlN)r[   Úfile_directoryr   r\   r   r   r   r2   Ð   r3   rc   r:   r   r   r   ÚHtest_partition_email_from_filename_gets_filename_metadata_from_file_pathÌ   s    rg   c                  C  sh   t tdƒdƒ�} t| d�}W d   ƒ n1 s.0    Y  tdd„ |D ƒƒsNJ ‚tdd„ |D ƒƒsdJ ‚d S )Nr   r   r   c                 s  s   | ]}|j jd u V  qd S r.   re   r\   r   r   r   r2   ×   r3   zMtest_partition_email_from_file_gets_filename_metadata_None.<locals>.<genexpr>c                 s  s   | ]}|j jd u V  qd S r.   ©r[   rf   r\   r   r   r   r2   Ø   r3   ©r   r   r   r6   ©r!   r;   r   r   r   Ú:test_partition_email_from_file_gets_filename_metadata_NoneÓ   s    (rk   c                  C  s@   t tdƒdd�} tdd„ | D ƒƒs&J ‚tdd„ | D ƒƒs<J ‚d S )Nr   ú	a/b/c.eml)Úmetadata_filenamec                 s  s   | ]}|j jd kV  qdS )zc.emlNre   r\   r   r   r   r2   à   r3   zOtest_partition_email_from_filename_prefers_metadata_filename.<locals>.<genexpr>c                 s  s   | ]}|j jd kV  qdS )za/bNrh   r\   r   r   r   r2   á   r3   rc   r:   r   r   r   Ú<test_partition_email_from_filename_prefers_metadata_filenameÛ   s
    ÿrn   c                  C  sj   t tdƒdƒ�} t| dd�}W d   ƒ n1 s00    Y  tdd„ |D ƒƒsPJ ‚tdd„ |D ƒƒsfJ ‚d S )Nr   r   z	d/e/f.eml)r   rm   c                 s  s   | ]}|j jd kV  qdS )zf.emlNre   r\   r   r   r   r2   è   r3   zKtest_partition_email_from_file_prefers_metadata_filename.<locals>.<genexpr>c                 s  s   | ]}|j jd kV  qdS )zd/eNrh   r\   r   r   r   r2   é   r3   ri   rj   r   r   r   Ú8test_partition_email_from_file_prefers_metadata_filenameä   s    *ro   c                    sJ   d‰ t tdƒƒ} t‡ fdd„| D ƒƒsFJ dˆ › dt| d jjƒ› �ƒ‚d S )Nzmessage/rfc822r   c                 3  s   | ]}|j jˆ kV  qd S r.   )r[   Úfiletyper\   ©ZEML_MIME_TYPEr   r   r2   ò   r3   zmtest_partition_email_gets_the_EML_MIME_type_in_metadata_filetype_for_message_body_elements.<locals>.<genexpr>zExpected all elements to have 'z' as their filetype, but got: r   )r   r   r6   Úreprr[   rp   r:   r   rq   r   ÚZtest_partition_email_gets_the_EML_MIME_type_in_metadata_filetype_for_message_body_elementsï   s    ÿÿrs   c                  C  s&   t tdƒƒ} tdd„ | D ƒƒs"J ‚d S )Nr   c                 s  s   | ]}|j jd gkV  qdS )ÚengN©r[   Ú	languagesr\   r   r   r   r2   ý   r3   zFtest_partition_email_element_metadata_has_languages.<locals>.<genexpr>rc   r:   r   r   r   Ú3test_partition_email_element_metadata_has_languagesû   s    rw   c                  C  s,   t tdƒdgd�} tdd„ | D ƒƒs(J ‚d S )Nr   Údeu)rv   c                 s  s   | ]}|j jd gkV  qdS )rx   Nru   )r/   Úelementr   r   r   r2     r3   z>test_partition_email_respects_languages_arg.<locals>.<genexpr>rc   r:   r   r   r   Ú+test_partition_email_respects_languages_arg   s    rz   c                  C  s:   t tdƒdd�} dd„ | D ƒ}d|v s*J ‚d|v s6J ‚d S )Nzlanguage-docs/eng_spa_mult.emlT)Zdetect_language_per_elementc                 S  s$   h | ]}|j jd ur|j jd ’qS )Nr   ru   r\   r   r   r   Ú	<setcomp>  r3   zJtest_partition_eml_respects_detect_language_per_element.<locals>.<setcomp>rt   ZsparG   )r;   Zlangsr   r   r   Ú7test_partition_eml_respects_detect_language_per_element  s    þr|   c                  C  s&   t tdƒƒ} tdd„ | D ƒƒs"J ‚d S )Nr   c                 s  s   | ]}|j jd kV  qdS ©z2022-12-16T22:04:16+00:00N©r[   Zlast_modifiedr\   r   r   r   r2     r3   zZtest_partition_email_from_file_path_gets_last_modified_from_Date_header.<locals>.<genexpr>rc   r:   r   r   r   ÚGtest_partition_email_from_file_path_gets_last_modified_from_Date_header  s    r   c                  C  sR   t tdƒdƒ�} t| d�}W d   ƒ n1 s.0    Y  tdd„ |D ƒƒsNJ ‚d S )Nr   r   r   c                 s  s   | ]}|j jd kV  qdS r}   r~   r\   r   r   r   r2     r3   zUtest_partition_email_from_file_gets_last_modified_from_Date_header.<locals>.<genexpr>ri   rj   r   r   r   ÚBtest_partition_email_from_file_gets_last_modified_from_Date_header  s    (r€   c                    s2   d‰ t tdƒˆ d�} t‡ fdd„| D ƒƒs.J ‚d S )Nú2020-07-05T09:24:28r   ©Úmetadata_last_modifiedc                 3  s   | ]}|j jˆ kV  qd S r.   r~   r\   r‚   r   r   r2   (  r3   zUtest_partition_email_from_file_path_prefers_metadata_last_modified.<locals>.<genexpr>rc   r:   r   r‚   r   ÚBtest_partition_email_from_file_path_prefers_metadata_last_modified!  s
    ÿr„   c                    s\   d‰ t tdƒdƒ�} t| ˆ d�}W d   ƒ n1 s40    Y  t‡ fdd„|D ƒƒsXJ ‚d S )Nr�   r   r   )r   rƒ   c                 3  s   | ]}|j jˆ kV  qd S r.   r~   r\   r‚   r   r   r2   0  r3   zPtest_partition_email_from_file_prefers_metadata_last_modified.<locals>.<genexpr>ri   rj   r   r‚   r   Ú=test_partition_email_from_file_prefers_metadata_last_modified+  s    *r…   c                  C  sV   t tdƒƒ} t tdƒdd�}t| ƒ}tdd„ |D ƒƒs:J ‚|| ksFJ ‚||ksRJ ‚dS )zBNote it's actually the delegate partitioners that do the chunking.zeml/fake-email.txtÚby_title)Úchunking_strategyc                 s  s   | ]}t |tttfƒV  qd S r.   )rE   r   r   r   ©r/   Úcr   r   r   r2   <  r3   zAtest_partition_email_chunks_when_so_instructed.<locals>.<genexpr>N)r   r   r
   r6   )r;   ÚchunksZseparately_chunked_chunksr   r   r   Ú.test_partition_email_chunks_when_so_instructed6  s    r‹   c                  C  sˆ   t tdƒddd�} t| ƒdks"J ‚tdd„ | D ƒƒs8J ‚| d }|jd	ksNJ ‚|jjd
ks^J ‚|jjdksnJ ‚tdd„ | D ƒƒs„J ‚d S )Núeml/fake-email-attachment.emlr†   T)r‡   rD   é   c                 s  s   | ]}t |tƒV  qd S r.   )rE   r   rˆ   r   r   r   r2   I  r3   z>test_partition_email_chunks_attachments_too.<locals>.<genexpr>éÿÿÿÿúHey this is a fake attachment!úfake-attachment.txtúfake-email-attachment.emlc                 s  s   | ]}|j jd kV  qdS ©z2022-12-23T18:08:48+00:00Nr~   rˆ   r   r   r   r2   N  r3   )r   r   rA   r6   r   r[   rN   Úattached_to_filename)rŠ   Zattachment_chunkr   r   r   Ú+test_partition_email_chunks_attachments_tooA  s    ýr”   c                  C  s,   t tdƒdd�} | tdƒtdƒgks(J ‚d S )Nz(eml/email-equals-attachment-filename.emlTrJ   z&Below is an example of an odd filenamezOdd filename)r   r   r   r   r:   r   r   r   ÚCtest_partition_email_also_partitions_attachments_when_so_instructedT  s    ÿþr•   c                  C  s¢   t tdƒdd�} | tdƒtdƒtdƒtdƒtdƒtd	ƒtd
ƒtdƒtdƒg	ksRJ ‚tdd„ | D ƒƒshJ ‚| d }|jdks~J ‚|jjdksŽJ ‚|jj	dksžJ ‚d S )NrŒ   TrJ   zHello!zHere's the attachments!zIt includes:zLots of whitespacezLittle to no contentzand is a quick readzBest,ZMallorir�   c                 s  s   | ]}|j jd kV  qdS r’   r~   r\   r   r   r   r2   o  r3   z?test_partition_email_can_process_attachments.<locals>.<genexpr>rŽ   r�   r‘   )
r   r   r   r   r   r6   r   r[   rN   r“   )r;   Zattachment_elementr   r   r   Ú,test_partition_email_can_process_attachments_  s&    ÿ÷
r–   c                  C  s&   t tdƒdd�} | tdƒgks"J ‚d S )Nzeml/mime-attach-mp3.emlTrJ   z(This is an email with an MP3 attachment.r   r:   r   r   r   ÚCtest_partition_email_silently_skips_attachments_it_cannot_partitionv  s    ÿþr—   c                   @  sŽ  e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zej dddg¡dddœdd „ƒZd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4œd5d6„Zd7d8„ Zd9d:„ Zd;d<„ Zd=d>„ Z ej d?d@dAg¡dBdCœdDdE„ƒZ!dFdG„ Z"dHdI„ Z#dJdK„ Z$dLdM„ Z%dNdO„ Z&e '¡ ddPœdQdR„ƒZ(e '¡ dSd3dTœdUdV„ƒZ)dWS )XÚDescribeEmailPartitionerOptionszTUnit-test suite for `unstructured.partition.email.EmailPartitioningContext` objects.zdict[str, Any])Úctx_argsc                 C  s.   t dƒ|d< tjf i |¤Ž}t|tƒs*J ‚d S )Nr   r8   )r   r   ÚloadrE   )Úselfr™   Úctxr   r   r   Ú$it_provides_a_validating_constructor�  s    zDDescribeEmailPartitionerOptions.it_provides_a_validating_constructorc                 C  sB   t jtdd��  tjf i |¤Ž W d   ƒ n1 s40    Y  d S )Nz1no document specified; either a `filename` or `firP   )rR   rS   rT   r   rš   ©r›   r™   r   r   r   Ú3but_it_raises_when_no_source_document_was_specified”  s    zSDescribeEmailPartitionerOptions.but_it_raises_when_no_source_document_was_specifiedc                 C  sP   t  d¡|d< tjtdd��  tjf i |¤Ž W d   ƒ n1 sB0    Y  d S )NZabcdefgr   z)file object must be opened in binary moderP   )ÚioÚStringIOrR   rS   rT   r   rš   rž   r   r   r   Ú6and_it_raises_when_a_file_open_for_reading_str_is_used˜  s    zVDescribeEmailPartitionerOptions.and_it_raises_when_a_file_open_for_reading_str_is_usedc                 C  sV   t dƒ|d< d|d< tjtdd��  tjf i |¤Ž W d   ƒ n1 sH0    Y  d S )Nr   r8   rV   r,   z1'application/json' is not a valid value for conterP   )r   rR   rS   rT   r   rš   rž   r   r   r   Ú9and_it_raises_when_an_invalid_content_source_is_specified�  s    zYDescribeEmailPartitionerOptions.and_it_raises_when_an_invalid_content_source_is_specifiedc                 C  s"   t tdƒƒ}|jddgksJ ‚d S )NrX   rY   rZ   ©r   r   Zbcc_addresses©r›   rœ   r   r   r   Ú4it_provides_access_to_the_Bcc_addresses_when_present¦  s    zTDescribeEmailPartitionerOptions.it_provides_access_to_the_Bcc_addresses_when_presentc                 C  s   t tdƒƒ}|jd u sJ ‚d S ©Nr   r¤   r¥   r   r   r   Ú3but_it_returns_None_when_there_are_no_Bcc_addressesª  s    zSDescribeEmailPartitionerOptions.but_it_returns_None_when_there_are_no_Bcc_addressesc                 C  sH   t tdƒƒ}|j}t|tƒs J ‚| ¡ }t|tƒs6J ‚| d¡sDJ ‚d S )Nú!eml/mime-different-plain-html.emlz<!DOCTYPE html>©r   r   Ú	body_partrE   r   Úget_contentÚstrrB   ©r›   rœ   r«   Úcontentr   r   r   Ú:it_returns_the_html_body_part_when_there_is_one_by_default°  s    zZDescribeEmailPartitionerOptions.it_returns_the_html_body_part_when_there_is_one_by_defaultc                 C  sL   t tdƒdd�}|j}t|tƒs$J ‚| ¡ }t|tƒs:J ‚| d¡sHJ ‚d S )Nr©   r*   r+   zThis is the text/plain part.rª   r®   r   r   r   ÚKbut_it_returns_the_plain_text_body_part_when_there_is_one_when_so_requestedº  s    ÿzkDescribeEmailPartitionerOptions.but_it_returns_the_plain_text_body_part_when_there_is_one_when_so_requestedc                 C  s   t tdƒƒ}|jd u sJ ‚d S )NrI   )r   r   r«   r¥   r   r   r   Ú.and_it_returns_None_when_the_email_has_no_bodyÆ  s    zNDescribeEmailPartitionerOptions.and_it_returns_None_when_the_email_has_no_bodyc                 C  s"   t tdƒƒ}|jddgksJ ‚d S )NrX   r]   r^   ©r   r   Zcc_addressesr¥   r   r   r   Ú3it_provides_access_to_the_Cc_addresses_when_presentÌ  s    zSDescribeEmailPartitionerOptions.it_provides_access_to_the_Cc_addresses_when_presentc                 C  s   t tdƒƒ}|jd u sJ ‚d S r§   r³   r¥   r   r   r   Ú2but_it_returns_None_when_there_are_no_Cc_addressesÐ  s    zRDescribeEmailPartitionerOptions.but_it_returns_None_when_there_are_no_Cc_addresses)r,   Úexpected_value)r-   ©ÚhtmlÚplain)r*   )r¹   r¸   r­   ztuple[str, ...]c                 C  s   t |d�}|j|ksJ ‚d S )Nr+   ©r   Zcontent_type_preference)r›   r,   r¶   rœ   r   r   r   Ú?it_knows_whether_the_caller_prefers_the_HTML_or_plain_text_bodyÖ  s    

z_DescribeEmailPartitionerOptions.it_knows_whether_the_caller_prefers_the_HTML_or_plain_text_bodyc                 C  s   t ƒ }|jdksJ ‚d S )Nr·   rº   r¥   r   r   r   Ú+and_it_defaults_to_preferring_the_HTML_bodyã  s    zKDescribeEmailPartitionerOptions.and_it_defaults_to_preferring_the_HTML_bodyc                 C  s   t tdƒƒ}|jdksJ ‚d S )Núeml/mime-simple.emlr_   )r   r   Úfrom_addressr¥   r   r   r   Ú&it_knows_the_From_address_of_the_emailé  s    zFDescribeEmailPartitionerOptions.it_knows_the_From_address_of_the_emailc                 C  s   t tdƒƒ}|jdksJ ‚d S )Nr½   z1234567890@example.com©r   r   Z
message_idr¥   r   r   r   Ú1it_provides_access_to_the_Message_ID_when_presentï  s    zQDescribeEmailPartitionerOptions.it_provides_access_to_the_Message_ID_when_presentc                 C  s   t tdƒƒ}|jd u sJ ‚d S r§   rÀ   r¥   r   r   r   Ú6but_it_returns_None_when_there_is_no_Message_ID_headeró  s    zVDescribeEmailPartitionerOptions.but_it_returns_None_when_there_is_no_Message_ID_headerc                 C  s   t dd�}|jdksJ ‚d S )Nrl   )Úmetadata_file_path©r   rÃ   r¥   r   r   r   Ú>it_uses_the_metadata_file_path_arg_value_when_one_was_providedù  s    
z^DescribeEmailPartitionerOptions.it_uses_the_metadata_file_path_arg_value_when_one_was_providedc                 C  s   t dd�}|jdksJ ‚d S )Nz	x/y/z.eml©r8   rÄ   r¥   r   r   r   ÚLand_it_uses_the_file_path_arg_value_when_metadata_file_path_was_not_providedý  s    
zlDescribeEmailPartitionerOptions.and_it_uses_the_file_path_arg_value_when_metadata_file_path_was_not_providedc                 C  s   t ƒ }|jd u sJ ‚d S r.   rÄ   r¥   r   r   r   Ú7and_it_returns_None_when_neither_file_path_was_provided  s    zWDescribeEmailPartitionerOptions.and_it_returns_None_when_neither_file_path_was_providedc                 C  s    d}t |d�}|j|ksJ ‚d S )Nz2023-04-08T12:18:07r‚   )r   rƒ   )r›   rƒ   rœ   r   r   r   ÚBit_uses_the_metadata_last_modified_arg_value_when_one_was_provided  s    
zbDescribeEmailPartitionerOptions.it_uses_the_metadata_last_modified_arg_value_when_one_was_providedc                 C  s   t tdƒƒ}|jdksJ ‚d S )Nr   z2024-10-01T17:34:56+00:00)r   r   rƒ   r¥   r   r   r   ÚQand_it_uses_the_msg_Date_header_date_when_metadata_last_modified_was_not_provided  s    zqDescribeEmailPartitionerOptions.and_it_uses_the_msg_Date_header_date_when_metadata_last_modified_was_not_providedr   )Úget_last_modified_date_c                 C  s(   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)Zreturn_valuer   r   rƒ   )r›   rË   Zfilesystem_last_modifiedrœ   r   r   r   ÚLand_it_falls_back_to_filesystem_last_modified_when_no_Date_header_is_present  s    zlDescribeEmailPartitionerOptions.and_it_falls_back_to_filesystem_last_modified_when_no_Date_header_is_presentc                 C  sJ   t tdƒdƒ�(}t|d�}|jd u s(J ‚W d   ƒ n1 s<0    Y  d S )NrÌ   r   r   )r   r   r   rƒ   ©r›   r!   rœ   r   r   r   Ú6and_it_returns_None_when_no_last_modified_is_available  s    
zVDescribeEmailPartitionerOptions.and_it_returns_None_when_no_last_modified_is_availablec                 C  s"   t tdƒd�}t|jtƒsJ ‚d S )Nr   rÆ   )r   r   rE   Úmsgr   r¥   r   r   r   ÚFit_loads_the_email_message_from_the_filesystem_when_a_path_is_provided"  s    zfDescribeEmailPartitionerOptions.it_loads_the_email_message_from_the_filesystem_when_a_path_is_providedc                 C  sL   t tdƒdƒ�*}t|d�}t|jtƒs*J ‚W d   ƒ n1 s>0    Y  d S )Nr   r   r   )r   r   r   rE   rÐ   r   rÎ   r   r   r   ÚKand_it_loads_the_email_message_from_a_file_like_object_when_one_is_provided&  s    
zkDescribeEmailPartitionerOptions.and_it_loads_the_email_message_from_a_file_like_object_when_one_is_providedc                 C  s&   dddœ}t |d�}|j|ks"J ‚d S )NÚbarZqux)ZfooZbaz)Úkwargs)r   Zpartitioning_kwargs)r›   rÔ   rœ   r   r   r   Ú6it_passes_along_the_kwargs_it_received_on_construction-  s    

zVDescribeEmailPartitionerOptions.it_passes_along_the_kwargs_it_received_on_constructionrD   TFÚboolrJ   c                 C  s   t |d�}|j|ksJ ‚d S )NrJ   ©r   rD   )r›   rD   rœ   r   r   r   Ú?it_knows_whether_the_caller_wants_to_also_partition_attachments5  s    
z_DescribeEmailPartitionerOptions.it_knows_whether_the_caller_wants_to_also_partition_attachmentsc                 C  s   t ƒ }|jdu sJ ‚d S )NFr×   r¥   r   r   r   Ú%but_by_default_it_ignores_attachments<  s    zEDescribeEmailPartitionerOptions.but_by_default_it_ignores_attachmentsc                 C  s   t tdƒƒ}|jdksJ ‚d S )Nz!eml/mime-word-encoded-subject.emlu(   Simple email with â˜¸â˜¿ Unicode subject©r   r   rb   r¥   r   r   r   Ú3it_provides_access_to_the_email_Subject_as_a_stringB  s    zSDescribeEmailPartitionerOptions.it_provides_access_to_the_email_Subject_as_a_stringc                 C  s   t tdƒƒ}|jd u sJ ‚d S )Nzeml/mime-no-subject.emlrÚ   r¥   r   r   r   Ú3but_it_returns_None_when_there_is_no_Subject_headerF  s    zSDescribeEmailPartitionerOptions.but_it_returns_None_when_there_is_no_Subject_headerc                 C  s"   t tdƒƒ}|jddgksJ ‚d S )NrX   r`   ra   ©r   r   Zto_addressesr¥   r   r   r   Ú3it_provides_access_to_the_To_addresses_when_presentL  s    zSDescribeEmailPartitionerOptions.it_provides_access_to_the_To_addresses_when_presentc                 C  s   t tdƒƒ}|jd u sJ ‚d S )Nzeml/mime-no-to.emlrÝ   r¥   r   r   r   Ú2but_it_returns_None_when_there_are_no_To_addressesP  s    zRDescribeEmailPartitionerOptions.but_it_returns_None_when_there_are_no_To_addresses)Úreturnc                 C  s   d d dd d di dœS )Nr-   F)r8   r   r,   rÃ   rƒ   rD   rÔ   r   )r›   r   r   r   r™   V  s    ùz(DescribeEmailPartitionerOptions.ctx_argsr   )Úrequestrà   c                 C  s
   t |dƒS )Nz3unstructured.partition.email.get_last_modified_date)r	   )r›   rá   r   r   r   rË   b  s    z7DescribeEmailPartitionerOptions.get_last_modified_date_N)*Ú__name__Ú
__module__Ú__qualname__Ú__doc__r�   rŸ   r¢   r£   r¦   r¨   r°   r±   r²   r´   rµ   rR   ÚmarkZparametrizer»   r¼   r¿   rÁ   rÂ   rÅ   rÇ   rÈ   rÉ   rÊ   rÍ   rÏ   rÑ   rÒ   rÕ   rØ   rÙ   rÛ   rÜ   rÞ   rß   Zfixturer™   rË   r   r   r   r   r˜   ˆ  sX   	
þþr˜   )Arå   Ú
__future__r   r    r#   Úemail.messager   Útypingr   rR   Ztest_unstructured.unit_utilsr   r   r   r   r	   Zunstructured.chunking.titler
   Zunstructured.documents.elementsr   r   r   r   r   r   r   Zunstructured.partition.emailr   r   r    r   r"   r(   r)   r9   r<   r>   rC   rF   rH   rK   rL   rM   rO   rU   rW   rd   rg   rk   rn   ro   rs   rw   rz   r|   r   r€   r„   r…   r‹   r”   r•   r–   r—   r˜   r   r   r   r   Ú<module>   sd   $	ü	
	
