a
    ¡˜ëjr
  ã                   @  sZ   d Z ddlmZ ddlZddlmZ ddlmZ	 ddl
mZ ddlmZ G dd	„ d	ƒZdS )
aÐ  Provides access to the properties of an attachment in an Outlook MSG file.

These properies include the attached file's original file-name, its last-modified date, size, and
content-type (MIME-type).

```python
>>> from oxmsg import Message

>>> msg = Message.load("message.msg")
>>> msg.attachment_count
1
>>> attachment = msg.attachments[0]
>>> attachment.file_name
'financial-forecast.xlsx'
>>> with open(attachment.file_name, "wb") as f:
...     f.write()
```
é    )ÚannotationsN)Ú	constants)Úmodel)Ú
Properties)Úlazypropertyc                   @  sœ   e Zd ZdZddœdd„Zeddœdd	„ƒZed
dœdd„ƒZeddœdd„ƒZeddœdd„ƒZ	eddœdd„ƒZ
eddœdd„ƒZeddœdd„ƒZdS )Ú
Attachmentz,A file attached to an Outlook email message.z
m.StorageT)Ústoragec                 C  s
   || _ d S )N)Ú_storage)Úselfr   © r   úO/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/oxmsg/attachment.pyÚ__init__!   s    zAttachment.__init__Úbool)Úreturnc                 C  s(   | j  tj¡}|dusJ ‚t|tj@ ƒS )z¨True when the `PidTagAttachDataBinary` property contains the attachment data.

        This is as opposed to "by-reference" where only a path or URL is stored.
        N)Ú
propertiesZint_prop_valueÚcZPID_ATTACH_METHODr   ÚmZAF_BY_VALUE)r
   Zattach_methodr   r   r   Úattached_by_value$   s    zAttachment.attached_by_valuezbytes | Nonec                 C  s   | j  tj¡S )zDThe attachment binary, suitable for saving to a file when detaching.)r   Zbinary_prop_valuer   ZPID_ATTACH_DATA_BINARY©r
   r   r   r   Ú
file_bytes.   s    zAttachment.file_bytesz
str | Nonec                 C  s   | j  tj¡S )zŒThe full name of this file as it was originally attached.

        Like "FY24-quarterly-projections.xlsx". Does not include a path.
        )r   Ústr_prop_valuer   ZPID_ATTACH_LONG_FILENAMEr   r   r   r   Ú	file_name3   s    zAttachment.file_namezdt.datetime | Nonec                 C  s   | j  tj¡S )z�Timezone-aware UTC datetime when this attachment was last modified.

        `None` if this property is not present on the attachment.
        )r   Zdate_prop_valuer   ZPID_LAST_MODIFICATION_TIMEr   r   r   r   Úlast_modified;   s    zAttachment.last_modifiedc                 C  s   | j  tj¡pdS )zFISO 8601 str representation of time this attachment was last modified.zapplication/octet-stream)r   r   r   ZPID_ATTACH_MIME_TAGr   r   r   r   Ú	mime_typeC   s    zAttachment.mime_typer   c                 C  s   t | jtjd�S )z7Provides access to the properties of this OXMSG object.)Zproperties_header_offset)r   r	   r   ZATTACH_HDR_OFFSETr   r   r   r   r   H   s    zAttachment.propertiesÚintc                 C  s   | j rt| j ƒS dS )z#Length in bytes of this attachment.r   )r   Úlenr   r   r   r   ÚsizeM   s    zAttachment.sizeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r      s    	r   )r    Ú
__future__r   ÚdatetimeÚdtZoxmsg.domainr   r   r   r   Zoxmsg.propertiesr   Z
oxmsg.utilr   r   r   r   r   r   Ú<module>   s   