zimbraweb package¶
Module contents¶
- class zimbraweb.Response(success: bool = False, message: str = '')¶
Bases:
object
Helper class to return a success bool and a status message.
- class zimbraweb.SessionData(token: Optional[str] = None, expires: Optional[int] = None, jsessionid: Optional[str] = None, username: Optional[str] = None, from_address: Optional[str] = None, crumb: Optional[str] = None)¶
Bases:
object
Holds all authentication session data for a single Zimbra web user.
- token¶
A ZM_AUTH_TOKEN cookie, if authenticated.
- Type
Optional[str]
- expires¶
The unixtime expiration date of the auth token.
- Type
Optional[int]
- jsessionid¶
A JSESSIONID cookie, if a session has been opened.
- Type
Optional[str]
- username¶
The username of the authenticated user, if authenticated.
- Type
Optional[str]
- from_address¶
The default sender address used by the Zimbra web interface, if authenticated.
- Type
Optional[str]
- crumb¶
The validation crumb needed to generate payloads, if authenticated.
- Type
Optional[str]
- as_cookies() Dict[str, str] ¶
Returns a dictionary containting ZM_TEST, ZM_AUTH_TOKEN, JSESSIONID.
- is_valid() bool ¶
Returns True if no attributes are None and auth token is still valid.
- class zimbraweb.WebkitAttachment(filename: str, mimetype: str, content: bytes)¶
Bases:
object
Represents a single attachment for WebkitFormBoundary data.
- filename¶
The name of the attachment
- Type
str
- mimetype¶
The Mimetype, e.g. image/jpeg.
- Type
str
- content¶
The raw bytes of the attachment.
- Type
bytes
- class zimbraweb.ZimbraUser(url: str)¶
Bases:
object
This class represent a single user instance on the Zimbra Web Interface.
- property authenticated: bool¶
Is the user authenticated with the web client?
- generate_webkit_payload(to: str, subject: str, body: str, attachments: List[zimbraweb.WebkitAttachment] = [], **kwargs) Tuple[bytes, str] ¶
Generate a WebkitFormBoundary payload
- Parameters
to (str) – Recipient.
subject (str) – Email Subject Header.
body (str) – plain/text email body.
attachments (List[zimbraweb.WebkitAttachment]) – List of attachments to add to the payload.
**kwargs – Extended Mail Parameters (cc, bcc, replyto, inreplyto, messageid) can be set via kwargs.
- Returns
A Tuple (payload [bytes], boundary [str])
- get_mail_info() Optional[Dict[str, str]] ¶
Gets a valid crumb and from header to send an email
- Returns:
Optional[Dict[str, str]]: {‘crumb’: ‘xxx’, ‘from_header’: ‘s00000@domain.com’} or None
- get_session_id() Optional[str] ¶
Gets a new session id for the current user.
- Returns
A new JESSIONID or None if an error occurred.
- login(username: str, password: str) bool ¶
Gets an authentication token from the Zimbra Web Client using username and password as authentication.
- Parameters
username (str) – username to use for web authentication, without domain
password (str) – password to use for web authentication
- Returns
True if authentication was successful
- logout() bool ¶
Logs the user out of the web client and invalidates any session data.
- Returns
True if logout was successful
- send_eml(eml: str) zimbraweb.Response ¶
Tries to send an email from a .eml file.
- Parameters
eml (str) – The EML string to send
- Returns
A zimbraweb.Response object with response.success == True if payload was sent successfully and the resposne message from the web client.
- send_mail(to: str, subject: str, body: str, attachments: List[zimbraweb.WebkitAttachment] = [], **kwargs) zimbraweb.Response ¶
Sends an email as the current user.
- Parameters
to (str) – Recipient.
subject (str) – Email Subject Header.
body (str) – plain/text email body.
attachments (List[zimbraweb.WebkitAttachment]) – List of attachments to send with the email.
**kwargs – Extended Mail Parameters (cc, bcc, replyto, inreplyto, messageid) can be set via kwargs.
- Returns
A zimbraweb.Response object containing the status message of the server and response.success = True if the email was sent successfully.
- send_raw_payload(payload: bytes, boundary: str) zimbraweb.Response ¶
Sends a raw payload to the Web interface.
Examples
>>> from zimbraweb import ZimbraUser >>> user = ZimbraUser("https://my-zimbra.server") >>> user.login("xxx", "xxx") >>> payload, boundary = user.generate_webkit_payload(to="hello@example.com", subject="test mail", body="hello, world!") >>> user.send_raw_payload(payload, boundary) Response(success=True, status="Ihre Mail wurde gesendet.")
- Parameters
payload (bytes) – The payload to send in the body of the request
boundary (str) – The boundary that is used in the WebkitFormBoundary payload
- Returns
A zimbraweb.Response object with response.success == True if payload was sent successfully and the resposne message from the web client.
Submodules¶
zimbraweb.emlparsing module¶
- exception zimbraweb.emlparsing.ContentTypeNotSupportedError¶
Bases:
zimbraweb.emlparsing.UnsupportedEMLError
Exception for unsupported content types
- exception zimbraweb.emlparsing.MissingHeadersError¶
Bases:
zimbraweb.emlparsing.UnsupportedEMLError
Exception for missing headers
- exception zimbraweb.emlparsing.UnsupportedEMLError¶
Bases:
Exception
Exception for unsupported EML
- zimbraweb.emlparsing.is_parsable(eml: str) bool ¶
Check eml string for parsability
- Parameters
eml (str) – The EML string to parse.
- Returns
bool if parse_eml() will throw an error.
- zimbraweb.emlparsing.parse_eml(eml: str) Dict[str, Union[str, List[Any]]] ¶
Generate a dictionary for generate_payload() from an EML file.
- Parameters
eml (str) – The EML string to parse.
- Returns
A dictionary of the parsed EML file.
- Return type
Dict[str, Union[str, List[WebkitAttachment]]]