Skip to content

Commit 049bd74

Browse files
committed
refactor shell
1 parent 5a712f3 commit 049bd74

File tree

3 files changed

+4
-120
lines changed

3 files changed

+4
-120
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ exclude =
1717
templates,
1818
# migrations are generated by alembic
1919
migrations,
20-
docs
20+
docs,
21+
shell.py
2122

2223
per-file-ignores =
2324
# ignore unused imports in __init__

app/email_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def send_email(
284284
)
285285
return
286286

287-
LOG.d("send email to %s, subject %s", to_email, subject)
287+
LOG.d("send email to %s, subject '%s'", to_email, subject)
288288

289289
if html:
290290
msg = MIMEMultipart("alternative")

shell.py

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
from app.db import Session
99
from app.email_utils import send_email, render
1010
from app.log import LOG
11-
from app.models import (
12-
User,
13-
Mailbox,
14-
)
11+
from app.models import *
1512
from job_runner import (
1613
onboarding_pgp,
1714
onboarding_browser_extension,
@@ -42,119 +39,5 @@ def reset_db():
4239
create_db()
4340

4441

45-
def send_mailbox_newsletter():
46-
for user in User.order_by(User.id).all():
47-
if user.notification and user.activated:
48-
try:
49-
LOG.d("Send newsletter to %s", user)
50-
send_email(
51-
user.email,
52-
"Introducing Mailbox - our most requested feature",
53-
render("com/newsletter/mailbox.txt", user=user),
54-
render("com/newsletter/mailbox.html", user=user),
55-
)
56-
sleep(1)
57-
except Exception:
58-
LOG.w("Cannot send to user %s", user)
59-
60-
61-
def send_pgp_newsletter():
62-
for user in User.order_by(User.id).all():
63-
if user.notification and user.activated:
64-
try:
65-
LOG.d("Send PGP newsletter to %s", user)
66-
send_email(
67-
user.email,
68-
"Introducing PGP - encrypt your emails so only you can read them",
69-
render("com/newsletter/pgp.txt", user=user),
70-
render("com/newsletter/pgp.html", user=user),
71-
)
72-
sleep(1)
73-
except Exception:
74-
LOG.w("Cannot send to user %s", user)
75-
76-
77-
def send_mobile_newsletter():
78-
count = 0
79-
for user in User.order_by(User.id).all():
80-
if user.notification and user.activated:
81-
count += 1
82-
try:
83-
LOG.d("#%s: send to %s", count, user)
84-
send_email(
85-
user.email,
86-
"Mobile and Dark Mode",
87-
render("com/newsletter/mobile-darkmode.txt", user=user),
88-
render("com/newsletter/mobile-darkmode.html", user=user),
89-
)
90-
except Exception:
91-
LOG.w("Cannot send to user %s", user)
92-
93-
if count % 5 == 0:
94-
# sleep every 5 sends to avoid hitting email limits
95-
LOG.d("Sleep 1s")
96-
sleep(1)
97-
98-
99-
def disable_mailbox(mailbox_id):
100-
"""disable a mailbox and all of its aliases"""
101-
mailbox = Mailbox.get(mailbox_id)
102-
mailbox.verified = False
103-
for alias in mailbox.aliases:
104-
alias.enabled = False
105-
106-
Session.commit()
107-
108-
email_msg = f"""Hi,
109-
110-
Your mailbox {mailbox.email} cannot receive emails.
111-
To avoid forwarding emails to an invalid mailbox, we have disabled this mailbox along with all of its aliases.
112-
113-
If this is a mistake, please reply to this email.
114-
115-
Thanks,
116-
SimpleLogin team.
117-
"""
118-
119-
try:
120-
send_email(
121-
mailbox.user.email,
122-
f"{mailbox.email} is disabled",
123-
email_msg,
124-
email_msg.replace("\n", "<br>"),
125-
)
126-
except Exception:
127-
LOG.e("Cannot send disable mailbox email to %s", mailbox.user)
128-
129-
130-
def send_onboarding_emails(user):
131-
onboarding_send_from_alias(user)
132-
onboarding_mailbox(user)
133-
onboarding_browser_extension(user)
134-
onboarding_pgp(user)
135-
136-
13742
if __name__ == "__main__":
138-
# to test email template
139-
# with open("/tmp/email.html", "w") as f:
140-
# user = User.first()
141-
# f.write(
142-
# render(
143-
# "transactional/reset-password.html",
144-
# email=user.email,
145-
# user=user,
146-
# name=user.name,
147-
# activation_link="https://ab.cd",
148-
# alias="[email protected]",
149-
# directory="dir",
150-
# domain="domain",
151-
# new_email="[email protected]",
152-
# current_email="[email protected]",
153-
# link="https://link.com",
154-
# mailbox_email="[email protected]",
155-
# sender="[email protected]",
156-
# reset_password_link="http://reset_password_link",
157-
# )
158-
# )
159-
16043
embed()

0 commit comments

Comments
 (0)