Skip to content

Attachment

email_profile.parser.Attachment

Bases: BaseModel

One attachment from an email.

Source code in email_profile/parser.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class Attachment(BaseModel):
    """One attachment from an email."""

    model_config = ConfigDict(arbitrary_types_allowed=True)

    file_name: str
    content_type: str
    content: bytes

    def save(self, path: Union[str, Path] = ".") -> Path:
        """Write to path/<file_name>."""

        target = Path(path)
        target.mkdir(parents=True, exist_ok=True)

        out = target / self.file_name
        out.write_bytes(self.content)

        return out

content instance-attribute

content_type instance-attribute

file_name instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True) class-attribute instance-attribute

save(path='.')

Write to path/.

Source code in email_profile/parser.py
47
48
49
50
51
52
53
54
55
56
def save(self, path: Union[str, Path] = ".") -> Path:
    """Write to path/<file_name>."""

    target = Path(path)
    target.mkdir(parents=True, exist_ok=True)

    out = target / self.file_name
    out.write_bytes(self.content)

    return out