Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pyicloud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
AccountService,
DriveService,
)
from pyicloud.services.hidemyemail import HideMyEmailService
from pyicloud.utils import get_password_from_keyring


Expand Down Expand Up @@ -543,7 +544,12 @@ def devices(self):
return FindMyiPhoneServiceManager(
service_root, self.session, self.params, self.with_family
)

@property
def hidemyemail(self):
"""Gets the 'HME' service."""
service_root = self._get_webservice_url("premiummailsettings")
return HideMyEmailService(
service_root, self.session, self.params)
@property
def iphone(self):
"""Returns the iPhone."""
Expand Down
1 change: 1 addition & 0 deletions pyicloud/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from pyicloud.services.photos import PhotosService
from pyicloud.services.account import AccountService
from pyicloud.services.drive import DriveService
from pyicloud.services.hidemyemail import HideMyEmailService
44 changes: 44 additions & 0 deletions pyicloud/services/hidemyemail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Hide my email service."""


import json


class HideMyEmailService:
"""
The 'Hide My Email' iCloud service, connects to iCloud and create alias emails.
"""

def __init__(self, service_root, session, params):
self.session = session
self.params = params
self._service_root = service_root
hme_endpoint = "%s/v1/hme" % service_root
self._hidemyemail_generate = "%s/generate" % hme_endpoint
self._hidemyemail_reserve = "%s/reserve" % hme_endpoint

self.response = {}

def generate(self):
"""
Generate alias for the emails
"""
req = self.session.post(self._hidemyemail_generate, params=self.params)
self.response = req.json()
return self.response.get("result").get("hme")


def reserve(self, email, label, note="Generated"):
"""
Reserve alias for the emails
"""
data = json.dumps(
{
"hme": email,
"label": label,
"note": note
}
)

self.session.post(self._hidemyemail_reserve, params=self.params, data=data)

4 changes: 3 additions & 1 deletion tests/const_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"schoolwork": {},
"cksharews": {"url": "https://p31-ckshare.icloud.com:443", "status": "active"},
"findme": {"url": "https://p31-fmipweb.icloud.com:443", "status": "active"},
"premiummailsettings": {"url": "https://p42-maildomainws.icloud.com:443", "status": "active"},
"ckdeviceservice": {"url": "https://p31-ckdevice.icloud.com:443"},
"iworkthumbnailws": {
"url": "https://p31-iworkthumbnailws.icloud.com:443",
Expand Down Expand Up @@ -142,7 +143,7 @@
"contacts": {
"url": "https://p31-contactsws.icloud.com:443",
"status": "active",
},
},
},
"pcsEnabled": True,
"configBag": {
Expand Down Expand Up @@ -288,6 +289,7 @@
"schoolwork": {},
"cksharews": {"url": "https://p31-ckshare.icloud.com:443", "status": "active"},
"findme": {"url": "https://p31-fmipweb.icloud.com:443", "status": "active"},
"premiummailsettings": {"url": "https://p42-maildomainws.icloud.com:443", "status": "active"},
"ckdeviceservice": {"url": "https://p31-ckdevice.icloud.com:443"},
"iworkthumbnailws": {
"url": "https://p31-iworkthumbnailws.icloud.com:443",
Expand Down