
    Mi                        S r SSKJr  SSKrSSKrSSKrSSKrSSK	r	SSK
JrJr  SSKJrJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr   " S S5      rg)a  The `Message` object is the primary interface object in `python-oxmsg`.

This object is returned by the `Message.load()` classmethod:

```python
>>> from oxmsg import Message

>>> msg = Message.load("message.msg")
>>> msg.subject
'Agenda for the Acme meeting'
```
    )annotationsN)IOIterator)	OleFileIO	isOleFile
Attachment)	constants)model)
Properties	Recipient)Storage)lazypropertyc                  l   \ rS rSrSrSS jr\SS j5       r\SS j5       r	\SS j5       r
\SS j5       r\SS j5       r\SS	 j5       r\SS
 j5       r\SS j5       r\S S j5       r\SS j5       r\S!S j5       r\SS j5       r\S"S j5       rS#S jrS$S jr\S%S j5       r\SS j5       rS&S jrSrg)'Message"   zAAn Outlook email message loaded from an OXMSG format (.msg) file.c                    Xl         g N_storage)selfstorages     g/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/oxmsg/message.py__init__Message.__init__%   s        c                   [        U[        5      (       a	  [        US9O
[        U5      nU(       dD  [        U[        5      (       a  [        R
                  R                  U5      OSn[        U S35      e[        U5       n[        R                  " U5      nSSS5        U " W5      nUR                  5         U$ ! , (       d  f       N(= f)ztLoad an instance from `msg_file`.

`msg_file` can be a file-path, a file-like object, or the bytes of the MSG file.
)datamsg_filez is not an Outlook MSG fileN)
isinstancebytesr   strospathbasename
ValueErrorr   r   from_ole	_validate)clsr    
is_olefilefilenameoleroot_storager   s          r   loadMessage.load(   s     )38U(C(CI8$S[I\ 	 5?#5N5Nrww''1T^Hz)DEFFx C"++C0L ! <  ! s    B99
Cc                     U R                   S   $ )z&Number of attachments on this message.   )_header_prop_valuesr   s    r   attachment_countMessage.attachment_count=   s     ''**r   c                4    [        U R                  5       5      $ )z6Attachment object for each attachment in this message.)tuple_iter_attachmentsr4   s    r   attachmentsMessage.attachmentsB   s     T++-..r   c                T    U R                   R                  [        R                  5      $ )z;The plain-text body of this message; `None` if not present.)
propertiesstr_prop_valuecPID_BODYr4   s    r   bodyMessage.bodyG   s     --ajj99r   c                   U R                   R                  [        R                  5      =n(       a%  UR	                  U R                   R
                  5      $ U R                   R                  [        R                  5      =n(       a  U$ g)z;The HTML body of this message if present, `None` otherwise.N)r=   binary_prop_valuer?   PID_HTMLdecodebody_encodingr>   PID_BODY_HTML)r   
html_byteshtml_strs      r   	html_bodyMessage.html_bodyL   sc     ::1::FF:F$$T__%B%BCC55aooFF8FOr   c                ,    [        U R                  5      $ )zOFrom, To, Content-Type, etc. headers for this message as {name: value} mapping.)dict_message_headersr4   s    r   message_headersMessage.message_headersW   s     D))**r   c                f    U R                   R                  [        R                  5      =(       d    S$ )zBOutlook Message Class identifier like "IPM.Note" for this message. )r=   r>   r?   PID_MESSAGE_CLASSr4   s    r   message_classMessage.message_class\   s$     --a.A.ABHbHr   c                    U R                   $ )z7Provides access to the properties of this OXMSG object.)_propertiesr4   s    r   r=   Message.propertiesa   s     r   c                4    [        U R                  5       5      $ )z6`Recipient` object for each recipient of this message.)r8   _iter_recipientsr4   s    r   
recipientsMessage.recipientsf   s     T**,--r   c                   U R                   S   =n(       a  U$ U R                  nUR                  [        R                  5      =(       d    SR                  5       nU(       a  SU S3OSnUR                  [        R                  5      =(       d    UR                  [        R                  5      nU(       a  U SU S3$ UR                  [        R                  5      $ )ao  Name and email address of the message sender.

Like '"John Doe" <john@bigisp.com>'.

None if it is not recorded in the message. This may occur when the message is a draft or
system-generated or perhaps in other cases.

Note that the value of the From: message header is returned when present (usually I expect)
and may contain multiple addresses separated by commas.
fromrS   "z" <>)	rO   r=   r>   r?   PID_SENDER_NAMEstripPID_SENDER_EMAIL_ADDRESSPID_SENDER_SMTP_ADDRESSPID_SENT_REPRESENTING_NAME)r   from_header_valuepropsraw_namenameemails         r   senderMessage.senderk   s     !% 5 5f ===$$(():):;ArHHJ#+8*B$$Q%?%?@ 
EDXDX%%E
 &+$qq!b0D0DQEaEa0bbr   c                T    U R                   R                  [        R                  5      $ )zWhen this message was submitted by the sender.

This value will be `None` if the message has not been sent and possibly in other cases.
)r=   date_prop_valuer?   PID_CLIENT_SUBMIT_TIMEr4   s    r   	sent_dateMessage.sent_date   s     ..q/G/GHHr   c                f    U R                   R                  [        R                  5      =(       d    S$ )zSubject line of this message.rS   )r=   r>   r?   PID_SUBJECTr4   s    r   subjectMessage.subject   s"     --amm<BBr   c                ^    [         R                  " SU R                  R                  SS 5      $ )zThe property values in the MSG-root properties header.

It is a tuple of the four int values:
 - next_recipient_id
 - next_attachment_id
 - recipient_count
 - attachment_count
z<8x4IN   )structunpackr   properties_stream_bytesr4   s    r   r3   Message._header_prop_values   s&     }}Wdmm&K&KCR&PQQr   c                D    S U R                   R                  5        5       $ )zjGenerate `Attachment` object for each attachment in this message.

Should need to be called at most once.
c              3  8   #    U  H  n[        U5      v   M     g 7fr   r   .0r   s     r   	<genexpr>,Message._iter_attachments.<locals>.<genexpr>   s     \3[
7##3[   )r   iter_attachment_storagesr4   s    r   r9   Message._iter_attachments   s    
 ]4==3Y3Y3[\\r   c                D    S U R                   R                  5        5       $ )zhGenerate `Recipient` object for each recipient in this message.

Should need to be called at most once.
c              3  8   #    U  H  n[        U5      v   M     g 7fr   r   r   s     r   r   +Message._iter_recipients.<locals>.<genexpr>   s     Z2Yw	'""2Yr   )r   iter_recipient_storagesr4   s    r   r[   Message._iter_recipients   s    
 [$--2W2W2YZZr   c                    U R                   R                  [        R                  5      =(       d    Sn[        R
                  R                  5       R                  U5      $ )zFrom, To, Content-Type, etc. headers for this message as Message object.

This provides case-insensitive access along with some other convenient behaviors not
available from a `dict`.
rS   )r=   r>   r?   PID_TRANSPORT_MESSAGE_HEADERSrl   parserHeaderParserparsestr)r   headerss     r   rO   Message._message_headers   sB     //001P1PQWUW||((*33G<<r   c                F    [        U R                  [        R                  S9$ )N)properties_header_offset)r   r   mMSG_HDR_OFFSETr4   s    r   rX   Message._properties   s    $--!BRBRSSr   c                    g)zJRaise if this message is invalid for one of a variety of possible reasons.N r4   s    r   r)   Message._validate   s    r   r   N)r   z
m.StorageT)r    zstr | IO[bytes] | bytesreturnr   )r   int)r   ztuple[Attachment, ...])r   z
str | None)r   zdict[str, str])r   r#   )r   r   )r   ztuple[Recipient, ...])r   zdt.datetime | None)r   ztuple[int, int, int, int])r   zIterator[Attachment])r   zIterator[Recipient])r   zemail.message.Message)r   None)__name__
__module____qualname____firstlineno____doc__r   classmethodr/   propertyr5   r:   rA   rK   rP   rU   r=   r\   rm   rr   rv   r   r3   r9   r[   rO   rX   r)   __static_attributes__r   r   r   r   r   "   sT   K   ( + + / / : :   + + I I     . . c c. I I C C 	R 	R][ = = T TYr   r   ) r   
__future__r   datetimedtemail.messagerl   email.parserr$   rz   typingr   r   olefiler   r   oxmsg.attachmentr	   oxmsg.domainr
   r?   r   r   oxmsg.propertiesr   oxmsg.recipientr   oxmsg.storager   
oxmsg.utilr   r   r   r   r   <module>r      sG    #    	   ( ' ' # ' % ! #WY WYr   