mailbox-org-api 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mailbox_org_api-0.0.1/LICENSE +21 -0
- mailbox_org_api-0.0.1/PKG-INFO +68 -0
- mailbox_org_api-0.0.1/README.md +53 -0
- mailbox_org_api-0.0.1/mailbox_org_api/APIClient.py +378 -0
- mailbox_org_api-0.0.1/mailbox_org_api/__init__.py +0 -0
- mailbox_org_api-0.0.1/mailbox_org_api.egg-info/PKG-INFO +68 -0
- mailbox_org_api-0.0.1/mailbox_org_api.egg-info/SOURCES.txt +12 -0
- mailbox_org_api-0.0.1/mailbox_org_api.egg-info/dependency_links.txt +1 -0
- mailbox_org_api-0.0.1/mailbox_org_api.egg-info/top_level.txt +2 -0
- mailbox_org_api-0.0.1/pyproject.toml +22 -0
- mailbox_org_api-0.0.1/setup.cfg +4 -0
- mailbox_org_api-0.0.1/setup.py +12 -0
- mailbox_org_api-0.0.1/tests/__init__.py +0 -0
- mailbox_org_api-0.0.1/tests/tests.py +14 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Hendrik Schlange
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mailbox-org-api
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A library to access the mailbox.org Business API.
|
|
5
|
+
Author: Hendrik Schlange
|
|
6
|
+
Author-email: Hendrik Schlange <mail@heshsum.de>
|
|
7
|
+
Project-URL: Homepage, https://github.com/heshsum/mailbox-org-api
|
|
8
|
+
Project-URL: Issues, https://github.com/heshsum/mailbox-org-api/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
|
|
16
|
+
# mailbox-org-api
|
|
17
|
+
A library to access the mailbox.org Business API.
|
|
18
|
+
|
|
19
|
+
## Motivation and purpose
|
|
20
|
+
The goal is to provide a comprehensive library that can easily be used to integrate the business features at mailbox.org.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
### Using pip:
|
|
24
|
+
```bash
|
|
25
|
+
pip install mailbox-org-api
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Directly from source:
|
|
29
|
+
```bash
|
|
30
|
+
pip install git+https://github.com/heshsum/mailbox-org-api
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
Basic usage is fairly straightforward:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from mailbox_org_api import APIClient
|
|
38
|
+
|
|
39
|
+
username = 'foo'
|
|
40
|
+
password = 'bar'
|
|
41
|
+
|
|
42
|
+
# Initializing
|
|
43
|
+
api_connection = APIClient.APIClient()
|
|
44
|
+
|
|
45
|
+
# Testing with hello.world
|
|
46
|
+
api_connection.hello_world()
|
|
47
|
+
|
|
48
|
+
# Creating a new API session
|
|
49
|
+
api_connection.auth(username, password)
|
|
50
|
+
|
|
51
|
+
# Testing the session with hello.innerworld
|
|
52
|
+
api_connection.hello_innerworld()
|
|
53
|
+
|
|
54
|
+
# Closing the session
|
|
55
|
+
api_connection.deauth()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The implemented functions follow the naming scheme of the API, but with underscores instead of points (e.g. `mail_add()` for of `mail.add`).
|
|
59
|
+
|
|
60
|
+
## Here be dragons
|
|
61
|
+
1. I'm not a programmer. I'm not very good at this. Be aware of my incompetence.
|
|
62
|
+
2. Implementation is not complete. Not all functions of the API have been implemented
|
|
63
|
+
3. Type hinting is available for most functions, but not all of them.
|
|
64
|
+
E.g. `mail_add()` accepts kwargs due to the number of available attributes.
|
|
65
|
+
In that case type errors will be returned if wrong types are provided.
|
|
66
|
+
|
|
67
|
+
## API documentation
|
|
68
|
+
mailbox.org provides API documentation here: [https://api.mailbox.org](https://api.mailbox.org)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# mailbox-org-api
|
|
2
|
+
A library to access the mailbox.org Business API.
|
|
3
|
+
|
|
4
|
+
## Motivation and purpose
|
|
5
|
+
The goal is to provide a comprehensive library that can easily be used to integrate the business features at mailbox.org.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
### Using pip:
|
|
9
|
+
```bash
|
|
10
|
+
pip install mailbox-org-api
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Directly from source:
|
|
14
|
+
```bash
|
|
15
|
+
pip install git+https://github.com/heshsum/mailbox-org-api
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
Basic usage is fairly straightforward:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from mailbox_org_api import APIClient
|
|
23
|
+
|
|
24
|
+
username = 'foo'
|
|
25
|
+
password = 'bar'
|
|
26
|
+
|
|
27
|
+
# Initializing
|
|
28
|
+
api_connection = APIClient.APIClient()
|
|
29
|
+
|
|
30
|
+
# Testing with hello.world
|
|
31
|
+
api_connection.hello_world()
|
|
32
|
+
|
|
33
|
+
# Creating a new API session
|
|
34
|
+
api_connection.auth(username, password)
|
|
35
|
+
|
|
36
|
+
# Testing the session with hello.innerworld
|
|
37
|
+
api_connection.hello_innerworld()
|
|
38
|
+
|
|
39
|
+
# Closing the session
|
|
40
|
+
api_connection.deauth()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The implemented functions follow the naming scheme of the API, but with underscores instead of points (e.g. `mail_add()` for of `mail.add`).
|
|
44
|
+
|
|
45
|
+
## Here be dragons
|
|
46
|
+
1. I'm not a programmer. I'm not very good at this. Be aware of my incompetence.
|
|
47
|
+
2. Implementation is not complete. Not all functions of the API have been implemented
|
|
48
|
+
3. Type hinting is available for most functions, but not all of them.
|
|
49
|
+
E.g. `mail_add()` accepts kwargs due to the number of available attributes.
|
|
50
|
+
In that case type errors will be returned if wrong types are provided.
|
|
51
|
+
|
|
52
|
+
## API documentation
|
|
53
|
+
mailbox.org provides API documentation here: [https://api.mailbox.org](https://api.mailbox.org)
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module for the BMBO API client
|
|
3
|
+
"""
|
|
4
|
+
import json
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
headers = {'content-type': 'application/json'}
|
|
8
|
+
domain_capabilities = ['MAIL_SPAMPROTECTION', 'MAIL_BLACKLIST', 'MAIL_BACKUPRECOVER', 'MAIL_PASSWORDRESET_SMS']
|
|
9
|
+
mail_capabilities = ['MAIL_SPAMPROTECTION', 'MAIL_BLACKLIST', 'MAIL_BACKUPRECOVER', 'MAIL_OTP', 'MAIL_PASSWORDRESET_SMS']
|
|
10
|
+
mail_set_arguments = {'password': str, 'password_hash': str, 'same_password_allowed': bool,
|
|
11
|
+
'require_password_reset': bool, 'plan': str, 'additional_mail_quota': str,
|
|
12
|
+
'additional_cloud_quota': str, 'first_name': str, 'last_name': str, 'inboxsave': bool,
|
|
13
|
+
'forwards': list, 'aliases': list, 'alternate_mail': str, 'memo': str, 'allow_nets': str,
|
|
14
|
+
'active': bool, 'title': str, 'birthday': str, 'position': str, 'department': str, 'company': str,
|
|
15
|
+
'street': str, 'postal_code': str, 'city': str, 'phone': str, 'fax': str, 'cell_phone': str,
|
|
16
|
+
'uid_extern': str, 'language': str}
|
|
17
|
+
account_set_arguments = {'password': str, 'plan': str, 'memo': str, 'address_payment_first_name': str,
|
|
18
|
+
'address_payment_last_name': str, 'address_payment_street': str,
|
|
19
|
+
'address_payment_zipcode': str, 'address_payment_town': str, 'company': str, 'bank_iban': str,
|
|
20
|
+
'bank_bic': str, 'bank_account_owner': str, 'av_contract_accept_name': str,
|
|
21
|
+
'tarifflimits': list, 'av_contract_professional_secrecy': bool}
|
|
22
|
+
|
|
23
|
+
class APIClient:
|
|
24
|
+
"""
|
|
25
|
+
Object for API Client
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self):
|
|
29
|
+
# URL of the API
|
|
30
|
+
self.url = "https://api.mailbox.org/v1/"
|
|
31
|
+
|
|
32
|
+
# JSON RPC ID - a unique ID is required for each request during a session
|
|
33
|
+
self.jsonrpc_id = 0
|
|
34
|
+
self.level = None
|
|
35
|
+
self.auth_id = None
|
|
36
|
+
|
|
37
|
+
# Increment the request ID
|
|
38
|
+
def get_jsonrpc_id(self):
|
|
39
|
+
"""Method to create the JSON RPC request ID. """
|
|
40
|
+
self.jsonrpc_id += 1
|
|
41
|
+
return str(self.jsonrpc_id)
|
|
42
|
+
|
|
43
|
+
def api_request(self, method: str, params: dict) -> dict:
|
|
44
|
+
"""
|
|
45
|
+
Function to send API calls
|
|
46
|
+
:param method: the method to call
|
|
47
|
+
:param params: the parameters to send
|
|
48
|
+
:return: the response from the mailbox.org Business API
|
|
49
|
+
"""
|
|
50
|
+
request = {
|
|
51
|
+
"method": method,
|
|
52
|
+
"params": params,
|
|
53
|
+
"jsonrpc": "2.0",
|
|
54
|
+
"id": self.get_jsonrpc_id()
|
|
55
|
+
}
|
|
56
|
+
print('API request:\t', request)
|
|
57
|
+
|
|
58
|
+
api_response = requests.post(
|
|
59
|
+
self.url, data=json.dumps(request), headers=headers).json()
|
|
60
|
+
print('API full response:\t', api_response)
|
|
61
|
+
|
|
62
|
+
# Depending on the type of response the return changes.
|
|
63
|
+
# If a successful result, only the result is returned
|
|
64
|
+
if 'result' in api_response:
|
|
65
|
+
print('API result:\t', api_response['result'])
|
|
66
|
+
return api_response['result']
|
|
67
|
+
|
|
68
|
+
# In case of an error, the error is returned
|
|
69
|
+
elif 'error' in api_response:
|
|
70
|
+
print(api_response['error'])
|
|
71
|
+
return api_response['error']
|
|
72
|
+
|
|
73
|
+
# If neither a success nor an error, the full response if returned
|
|
74
|
+
else:
|
|
75
|
+
return api_response
|
|
76
|
+
|
|
77
|
+
def auth(self, username, password) -> dict:
|
|
78
|
+
"""
|
|
79
|
+
Function to authenticate and create a new API session
|
|
80
|
+
:param username: the username
|
|
81
|
+
:param password: the password
|
|
82
|
+
"""
|
|
83
|
+
api_response = self.api_request('auth', {'user':username, 'pass':password})
|
|
84
|
+
if api_response['session']:
|
|
85
|
+
# Level gives information about the calls available
|
|
86
|
+
self.level = api_response["level"]
|
|
87
|
+
print('Level:', self.level)
|
|
88
|
+
|
|
89
|
+
# The session id
|
|
90
|
+
self.auth_id = str(api_response["session"])
|
|
91
|
+
print('Auth ID:', self.auth_id)
|
|
92
|
+
# The auth-header is added to the list of headers, as it has to be provided with each call
|
|
93
|
+
headers.update({"HPLS-AUTH": self.auth_id})
|
|
94
|
+
return api_response
|
|
95
|
+
|
|
96
|
+
def deauth(self) -> dict:
|
|
97
|
+
"""
|
|
98
|
+
Function to close the current API session
|
|
99
|
+
:return: True if the API session is closed, False otherwise
|
|
100
|
+
"""
|
|
101
|
+
api_response = self.api_request('deauth',{})
|
|
102
|
+
if api_response:
|
|
103
|
+
# The auth header is stripped
|
|
104
|
+
del headers["HPLS-AUTH"]
|
|
105
|
+
return api_response
|
|
106
|
+
|
|
107
|
+
def hello_world(self):
|
|
108
|
+
"""
|
|
109
|
+
Function for hello world, just to test the connection
|
|
110
|
+
:return: The response from the mailbox.org Business API
|
|
111
|
+
"""
|
|
112
|
+
api_response = self.api_request('hello.world',{})
|
|
113
|
+
return api_response
|
|
114
|
+
|
|
115
|
+
def hello_innerworld(self):
|
|
116
|
+
"""
|
|
117
|
+
Hello World function to test the authentication
|
|
118
|
+
:return: The response from the mailbox.org Business API
|
|
119
|
+
"""
|
|
120
|
+
api_response = self.api_request('hello.innerworld', {})
|
|
121
|
+
return api_response
|
|
122
|
+
|
|
123
|
+
def account_add(self, account_name: str) -> dict:
|
|
124
|
+
"""
|
|
125
|
+
Function to create a new account
|
|
126
|
+
:param account_name: the account name to create
|
|
127
|
+
:return: the response from the mailbox.org Business API
|
|
128
|
+
"""
|
|
129
|
+
api_response = self.api_request('account.add', {'account_name':account_name})
|
|
130
|
+
return api_response
|
|
131
|
+
|
|
132
|
+
def account_get(self, account_name: str) -> dict:
|
|
133
|
+
"""
|
|
134
|
+
Function to get a specific account
|
|
135
|
+
:param account_name: the account name to get
|
|
136
|
+
:return: the response from the mailbox.org Business API
|
|
137
|
+
"""
|
|
138
|
+
api_response = self.api_request('account.get', {'account_name':account_name})
|
|
139
|
+
return api_response
|
|
140
|
+
|
|
141
|
+
def account_set(self, account_name: str, attributes: dict) -> dict:
|
|
142
|
+
"""
|
|
143
|
+
Function to update a specific account
|
|
144
|
+
:param account_name: the account name to update
|
|
145
|
+
:param attributes: the attributes to update
|
|
146
|
+
:return: the response from the mailbox.org Business API
|
|
147
|
+
"""
|
|
148
|
+
params = {'account':account_name}
|
|
149
|
+
for attribute in attributes:
|
|
150
|
+
print('Attribute:', attribute)
|
|
151
|
+
if attribute not in account_set_arguments:
|
|
152
|
+
raise ValueError(attribute, 'not found')
|
|
153
|
+
if type(attributes[attribute]) != account_set_arguments[attribute]:
|
|
154
|
+
errormsg = ('Attribute ' + attribute + ' must be of type ' + str(account_set_arguments[attribute]) + '. '
|
|
155
|
+
+ str(type(attributes[attribute])) + ' provided.')
|
|
156
|
+
raise TypeError(errormsg)
|
|
157
|
+
params.update({attribute: attributes[attribute]})
|
|
158
|
+
api_response = self.api_request('account.set', params)
|
|
159
|
+
return api_response
|
|
160
|
+
|
|
161
|
+
def account_del(self, account_name: str) -> dict:
|
|
162
|
+
"""
|
|
163
|
+
Function to delete a specific account
|
|
164
|
+
:param account_name: the account name to delete
|
|
165
|
+
:return: the response from the mailbox.org Business API
|
|
166
|
+
"""
|
|
167
|
+
api_response = self.api_request('account.del', {'account_name':account_name})
|
|
168
|
+
return api_response
|
|
169
|
+
|
|
170
|
+
def domain_list(self, account: str) -> dict:
|
|
171
|
+
"""
|
|
172
|
+
Function to list all domains
|
|
173
|
+
:param account: the account to list domains for
|
|
174
|
+
:return: the API response
|
|
175
|
+
"""
|
|
176
|
+
api_response = self.api_request('domain.list',{'account':account})
|
|
177
|
+
return api_response
|
|
178
|
+
|
|
179
|
+
def domain_add(self, account: str, domain: str, password: str) -> dict:
|
|
180
|
+
"""
|
|
181
|
+
Function to add a domain
|
|
182
|
+
:param account: the account to add a domain for
|
|
183
|
+
:param domain: the domain to add
|
|
184
|
+
:param password: the password of the domain
|
|
185
|
+
:return: the API response
|
|
186
|
+
"""
|
|
187
|
+
api_response = self.api_request('domain.add', {'account':account, 'domain':domain, 'password':password})
|
|
188
|
+
return api_response
|
|
189
|
+
|
|
190
|
+
def domain_get(self, domain: str) -> dict:
|
|
191
|
+
"""
|
|
192
|
+
Function to get a specific domain
|
|
193
|
+
:param domain: the domain to get
|
|
194
|
+
:return: the API response
|
|
195
|
+
"""
|
|
196
|
+
api_response = self.api_request('domain.get',{'domain':domain})
|
|
197
|
+
return api_response
|
|
198
|
+
|
|
199
|
+
def domain_capabilities_set(self, domain: str, capabilties: dict) -> dict:
|
|
200
|
+
"""
|
|
201
|
+
Function to set a domain capabilities
|
|
202
|
+
:param domain: the domain to set the capabilities for
|
|
203
|
+
:param capabilties: a list of capabilities to set for the domain
|
|
204
|
+
:return: the API response
|
|
205
|
+
"""
|
|
206
|
+
params = {'domain': domain}
|
|
207
|
+
for element in capabilties:
|
|
208
|
+
if element not in domain_capabilities:
|
|
209
|
+
break
|
|
210
|
+
params.update({element: capabilties[element]})
|
|
211
|
+
api_response = self.api_request('domain.capabilities.set', params)
|
|
212
|
+
return api_response
|
|
213
|
+
|
|
214
|
+
def domain_set(self, domain: str, attributes: dict) -> dict:
|
|
215
|
+
"""
|
|
216
|
+
Function to set a domain
|
|
217
|
+
:param domain: the domain to update
|
|
218
|
+
:param attributes: the attributes to set
|
|
219
|
+
:return:
|
|
220
|
+
"""
|
|
221
|
+
params = {'domain':domain }
|
|
222
|
+
for element in attributes:
|
|
223
|
+
params.update({element:attributes[element]})
|
|
224
|
+
|
|
225
|
+
api_response = self.api_request('domain.set', params)
|
|
226
|
+
return api_response
|
|
227
|
+
|
|
228
|
+
def domain_del(self, account: str, domain: str) -> dict:
|
|
229
|
+
"""
|
|
230
|
+
Function to delete a domain
|
|
231
|
+
:param account: the account to delete a domain in
|
|
232
|
+
:param domain: the domain to delete
|
|
233
|
+
:return: the API response
|
|
234
|
+
"""
|
|
235
|
+
api_response = self.api_request('domain.del', {'account':account, 'domain':domain})
|
|
236
|
+
return api_response
|
|
237
|
+
|
|
238
|
+
def mail_list(self, domain) -> dict:
|
|
239
|
+
"""
|
|
240
|
+
Function to list all mailboxes
|
|
241
|
+
:return: the response from the mailbox.org Business API
|
|
242
|
+
"""
|
|
243
|
+
api_response = self.api_request('mail.list', {'domain':domain})
|
|
244
|
+
return api_response
|
|
245
|
+
|
|
246
|
+
def mail_add(self, mail:str, password: str, plan: str, first_name: str, last_name: str, inboxsave: bool = True,
|
|
247
|
+
forwards: list = None, memo: str = None, language: str = 'en_EN', uid_extern: str = None) -> dict:
|
|
248
|
+
"""
|
|
249
|
+
Function to add a mail
|
|
250
|
+
:param mail: the mail to add
|
|
251
|
+
:param password: the password for the mail
|
|
252
|
+
:param plan: the plan of the mail
|
|
253
|
+
:param first_name: the first name of the mail
|
|
254
|
+
:param last_name: the last name of the mail
|
|
255
|
+
:param inboxsave: True if the mail should be saved into the inbox folder (relevant for forwards)
|
|
256
|
+
:param forwards: List of addresses to forwards mails to
|
|
257
|
+
:param memo: Memo of the mail
|
|
258
|
+
:param language: the language of the mail in locale format
|
|
259
|
+
:param uid_extern: the external UID of the mail
|
|
260
|
+
:return: the response for the request
|
|
261
|
+
"""
|
|
262
|
+
if forwards is None:
|
|
263
|
+
forwards = []
|
|
264
|
+
if memo is None:
|
|
265
|
+
memo = ''
|
|
266
|
+
api_response = self.api_request('mail.add',{'mail':mail, 'password':password, 'plan':plan,
|
|
267
|
+
'first_name':first_name, 'last_name':last_name,
|
|
268
|
+
'inboxsave':inboxsave, 'forwards':forwards, 'memo':memo,
|
|
269
|
+
'language':language, 'uid_extern':uid_extern})
|
|
270
|
+
return api_response
|
|
271
|
+
|
|
272
|
+
def mail_get(self, mail: str):
|
|
273
|
+
"""
|
|
274
|
+
Function to retrieve a mail address
|
|
275
|
+
:param mail: the mail to retrieve
|
|
276
|
+
:return the response for the request
|
|
277
|
+
"""
|
|
278
|
+
api_response = self.api_request('mail.get', {'mail':mail})
|
|
279
|
+
return api_response
|
|
280
|
+
|
|
281
|
+
def mail_set(self, mail: str, attributes: dict):
|
|
282
|
+
"""
|
|
283
|
+
Function to update a mail
|
|
284
|
+
:param mail: the mail to update
|
|
285
|
+
:param attributes: dict of the attributes to update
|
|
286
|
+
:return:
|
|
287
|
+
"""
|
|
288
|
+
params = {'mail':mail}
|
|
289
|
+
for attribute in attributes:
|
|
290
|
+
print('Attribute:', attribute)
|
|
291
|
+
if attribute not in mail_set_arguments:
|
|
292
|
+
raise ValueError(attribute, 'not found')
|
|
293
|
+
if type(attributes[attribute]) != mail_set_arguments[attribute]:
|
|
294
|
+
errormsg = ('Attribute ' + attribute + ' must be of type ' + str(mail_set_arguments[attribute]) + '. '
|
|
295
|
+
+ str(type(attributes[attribute])) + ' provided.')
|
|
296
|
+
raise TypeError(errormsg)
|
|
297
|
+
params.update({attribute: attributes[attribute]})
|
|
298
|
+
api_response = self.api_request('mail.set', params)
|
|
299
|
+
return api_response
|
|
300
|
+
|
|
301
|
+
def mail_capabilities_set(self, mail: str, capabilties: dict) -> dict:
|
|
302
|
+
"""
|
|
303
|
+
Function to set a domain capabilities
|
|
304
|
+
:param mail: the mail to set the capabilities for
|
|
305
|
+
:param capabilties: a list of capabilities to set for the domain
|
|
306
|
+
:return: the API response
|
|
307
|
+
"""
|
|
308
|
+
params = {'mail': mail}
|
|
309
|
+
for attribute in capabilties:
|
|
310
|
+
if attribute not in mail_capabilities:
|
|
311
|
+
raise ValueError(attribute, 'not found')
|
|
312
|
+
params.update({attribute: capabilties[attribute]})
|
|
313
|
+
api_response = self.api_request('mail.capabilities.set', params)
|
|
314
|
+
return api_response
|
|
315
|
+
|
|
316
|
+
def mail_del(self, mail: str) -> dict:
|
|
317
|
+
"""
|
|
318
|
+
Function to delete a mail
|
|
319
|
+
:param mail: the mail to delete
|
|
320
|
+
:return: the response for the request
|
|
321
|
+
"""
|
|
322
|
+
api_response = self.api_request('mail.del', {'mail':mail})
|
|
323
|
+
return api_response
|
|
324
|
+
|
|
325
|
+
def mail_apppassword_list(self, mail:str) -> dict:
|
|
326
|
+
"""
|
|
327
|
+
Function to list all app passwords of a given mail
|
|
328
|
+
:param mail: the mail to list app passwords for
|
|
329
|
+
:return: the response for the request
|
|
330
|
+
"""
|
|
331
|
+
api_response = self.api_request('mail.apppassword.list', {'mail':mail})
|
|
332
|
+
return api_response
|
|
333
|
+
|
|
334
|
+
def mail_apppassword_add(self, mail:str, memo:str) -> dict:
|
|
335
|
+
"""
|
|
336
|
+
Function to generate a new mail app password for a mail
|
|
337
|
+
:param mail: the mail to generate a new mail app password
|
|
338
|
+
:param memo: memo of the app password
|
|
339
|
+
:return: the response for the request
|
|
340
|
+
"""
|
|
341
|
+
api_response = self.api_request('mail.apppassword.add', {'mail':mail, 'memo':memo})
|
|
342
|
+
return api_response
|
|
343
|
+
|
|
344
|
+
def mail_apppassword_delete(self, apppassword_id: int) -> dict:
|
|
345
|
+
"""
|
|
346
|
+
Function to delete a mail app password
|
|
347
|
+
:param apppassword_id: the id of the mail app password
|
|
348
|
+
:return: the response for the request
|
|
349
|
+
"""
|
|
350
|
+
api_response = self.api_request('mail.apppassword.delete', {'id':apppassword_id})
|
|
351
|
+
return api_response
|
|
352
|
+
|
|
353
|
+
def mail_externaluid(self, mail: str) -> dict:
|
|
354
|
+
"""
|
|
355
|
+
Function to get a mail using an external UID
|
|
356
|
+
:param mail: the mail to get
|
|
357
|
+
:return: the response for the request
|
|
358
|
+
"""
|
|
359
|
+
api_response = self.api_request('mail.externaluid', {'mail':mail})
|
|
360
|
+
return api_response
|
|
361
|
+
|
|
362
|
+
def context_list(self, account: str) -> dict:
|
|
363
|
+
"""
|
|
364
|
+
Function to list all contexts of a given account
|
|
365
|
+
:param account: the account to list all contexts for
|
|
366
|
+
:return: the response for the request
|
|
367
|
+
"""
|
|
368
|
+
api_response = self.api_request('context.list', {'account':account})
|
|
369
|
+
return api_response
|
|
370
|
+
|
|
371
|
+
def search(self, search_string: str) -> dict:
|
|
372
|
+
"""
|
|
373
|
+
Function to search for accounts, domains and email addresses
|
|
374
|
+
:param search_string: the query to search by
|
|
375
|
+
:return: the response for the request
|
|
376
|
+
"""
|
|
377
|
+
api_response = self.api_request('search', {'search':search_string})
|
|
378
|
+
return api_response
|
|
File without changes
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mailbox-org-api
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A library to access the mailbox.org Business API.
|
|
5
|
+
Author: Hendrik Schlange
|
|
6
|
+
Author-email: Hendrik Schlange <mail@heshsum.de>
|
|
7
|
+
Project-URL: Homepage, https://github.com/heshsum/mailbox-org-api
|
|
8
|
+
Project-URL: Issues, https://github.com/heshsum/mailbox-org-api/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
|
|
16
|
+
# mailbox-org-api
|
|
17
|
+
A library to access the mailbox.org Business API.
|
|
18
|
+
|
|
19
|
+
## Motivation and purpose
|
|
20
|
+
The goal is to provide a comprehensive library that can easily be used to integrate the business features at mailbox.org.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
### Using pip:
|
|
24
|
+
```bash
|
|
25
|
+
pip install mailbox-org-api
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Directly from source:
|
|
29
|
+
```bash
|
|
30
|
+
pip install git+https://github.com/heshsum/mailbox-org-api
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
Basic usage is fairly straightforward:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from mailbox_org_api import APIClient
|
|
38
|
+
|
|
39
|
+
username = 'foo'
|
|
40
|
+
password = 'bar'
|
|
41
|
+
|
|
42
|
+
# Initializing
|
|
43
|
+
api_connection = APIClient.APIClient()
|
|
44
|
+
|
|
45
|
+
# Testing with hello.world
|
|
46
|
+
api_connection.hello_world()
|
|
47
|
+
|
|
48
|
+
# Creating a new API session
|
|
49
|
+
api_connection.auth(username, password)
|
|
50
|
+
|
|
51
|
+
# Testing the session with hello.innerworld
|
|
52
|
+
api_connection.hello_innerworld()
|
|
53
|
+
|
|
54
|
+
# Closing the session
|
|
55
|
+
api_connection.deauth()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The implemented functions follow the naming scheme of the API, but with underscores instead of points (e.g. `mail_add()` for of `mail.add`).
|
|
59
|
+
|
|
60
|
+
## Here be dragons
|
|
61
|
+
1. I'm not a programmer. I'm not very good at this. Be aware of my incompetence.
|
|
62
|
+
2. Implementation is not complete. Not all functions of the API have been implemented
|
|
63
|
+
3. Type hinting is available for most functions, but not all of them.
|
|
64
|
+
E.g. `mail_add()` accepts kwargs due to the number of available attributes.
|
|
65
|
+
In that case type errors will be returned if wrong types are provided.
|
|
66
|
+
|
|
67
|
+
## API documentation
|
|
68
|
+
mailbox.org provides API documentation here: [https://api.mailbox.org](https://api.mailbox.org)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
mailbox_org_api/APIClient.py
|
|
6
|
+
mailbox_org_api/__init__.py
|
|
7
|
+
mailbox_org_api.egg-info/PKG-INFO
|
|
8
|
+
mailbox_org_api.egg-info/SOURCES.txt
|
|
9
|
+
mailbox_org_api.egg-info/dependency_links.txt
|
|
10
|
+
mailbox_org_api.egg-info/top_level.txt
|
|
11
|
+
tests/__init__.py
|
|
12
|
+
tests/tests.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mailbox-org-api"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
authors = [
|
|
5
|
+
{ name="Hendrik Schlange", email="mail@heshsum.de" },
|
|
6
|
+
]
|
|
7
|
+
description = "A library to access the mailbox.org Business API."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Homepage = "https://github.com/heshsum/mailbox-org-api"
|
|
18
|
+
Issues = "https://github.com/heshsum/mailbox-org-api/issues"
|
|
19
|
+
|
|
20
|
+
[build-system]
|
|
21
|
+
requires = ["setuptools>=61.0"]
|
|
22
|
+
build-backend = "setuptools.build_meta"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from setuptools import find_packages, setup
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='mailbox_org_api',
|
|
5
|
+
packages=find_packages(),
|
|
6
|
+
version='0.0.1',
|
|
7
|
+
description='A library to access the mailbox.org Business API',
|
|
8
|
+
author='Hendrik Schlange',
|
|
9
|
+
install_requires=['requests'],
|
|
10
|
+
tests_require=['pytest'],
|
|
11
|
+
test_suite='tests',
|
|
12
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from mailbox_org_api import APIClient
|
|
3
|
+
|
|
4
|
+
def test_headers():
|
|
5
|
+
client = APIClient.APIClient()
|
|
6
|
+
assert client.auth_id is None
|
|
7
|
+
assert client.level is None
|
|
8
|
+
assert client.jsonrpc_id == 0
|
|
9
|
+
|
|
10
|
+
def test_hello_world():
|
|
11
|
+
client = APIClient.APIClient()
|
|
12
|
+
assert client.jsonrpc_id == 0
|
|
13
|
+
assert client.hello_world() == 'Hello World!'
|
|
14
|
+
assert client.jsonrpc_id == 1
|