Coverage for functions \ flipdare \ mailer \ email_image.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12 

13 

14import io 

15import uuid 

16 

17 

18class EmailImage: 

19 __slots__ = ("_buffer", "_cid", "_max_height", "_max_width", "_notes") 

20 

21 def __init__( 

22 self, 

23 buf: io.BytesIO, 

24 notes: list[str], 

25 max_width: int = 600, 

26 max_height: int = 400, 

27 ) -> None: 

28 self._buffer = buf 

29 self._cid = uuid.uuid4().hex 

30 self._max_width = max_width 

31 self._max_height = max_height 

32 self._notes = notes 

33 

34 @property 

35 def cid(self) -> str: 

36 """Unique Content-ID for CID embedding in MIME messages.""" 

37 return self._cid 

38 

39 @property 

40 def notes(self) -> list[str]: 

41 return self._notes 

42 

43 @property 

44 def buffer(self) -> io.BytesIO: 

45 return self._buffer 

46 

47 @property 

48 def buffer_bytes(self) -> bytes: 

49 """Raw image bytes for attaching as a MIME part.""" 

50 buf = self._buffer 

51 buf.seek(0) 

52 return buf.read() 

53 

54 @property 

55 def cid_url(self) -> str: 

56 max_width = self._max_width 

57 max_height = self._max_height 

58 return f'<img src="cid:{self._cid}" width="{max_width}" height="{max_height}" />'