def send_update_notification_sync(mod, version, user):
    followers = [u.email for u in mod.followers]
    changelog = version.changelog
    if changelog:
        changelog = '\n'.join(['    ' + l for l in changelog.split('\n')])

    targets = list()
    for follower in followers:
        targets.append(follower)
    if len(targets) == 0:
        return
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.starttls()
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/mod-updated") as f:
        message = MIMEText(html.parser.HTMLParser().unescape(pystache.render(f.read(),
            {
                'mod': mod,
                'user': user,
                'domain': _cfg("domain"),
                'latest': version,
                'url': '/mod/' + str(mod.id) + '/' + secure_filename(mod.name)[:64],
                'changelog': changelog
            })))
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = user + " has just updated " + mod.name + "!"
    message['From'] = "*****@*****.**"
    message['To'] = ";".join(targets)
    smtp.sendmail("*****@*****.**", targets, message.as_string())
    smtp.quit()
Exemple #2
0
def send_mail(sender, recipients, subject, message, important=False):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(host=_cfg("smtp-host"), port=_cfgi("smtp-port"))
    if _cfgb("smtp-tls"):
        smtp.starttls()
    if _cfg("smtp-user") != "":
        smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    message = MIMEText(message)
    if important:
        message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = sender
    if len(recipients) > 1:
        message['Precedence'] = 'bulk'
    for group in chunks(recipients, 100):
        if len(group) > 1:
            message['To'] = "undisclosed-recipients:;"
        else:
            message['To'] = ";".join(group)
        print("Sending email from {} to {} recipients".format(
            sender, len(group)))
        smtp.sendmail(sender, group, message.as_string())
    smtp.quit()
Exemple #3
0
def send_autoupdate_notification(mod):
    if _cfg("smtp-host") == "":
        return
    followers = [u.email for u in mod.followers]
    changelog = mod.versions[-1].changelog
    if changelog:
        changelog = '\n'.join(['    ' + l for l in changelog.split('\n')])

    for follower in followers:
        smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
        smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
        with open("emails/mod-autoupdated") as f:
            message = MIMEText(pystache.render(f.read(),
                {
                    'mod': mod,
                    'domain': _cfg("domain"),
                    'latest': mod.versions[-1],
                    'url': '/mod/' + str(mod.id) + '/' + secure_filename(mod.name)[:64],
                    'changelog': changelog
                }))
        message['Subject'] = mod.name + " is compatible with KSP " + mod.versions[0].ksp_version + "!"
        message['From'] = "*****@*****.**"
        message['To'] = follower
        smtp.sendmail("*****@*****.**", [ follower ], message.as_string())
        smtp.quit()
Exemple #4
0
def sendEmail(message,emailto):
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.starttls()
    smtp.ehlo()
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    smtp.sendmail("*****@*****.**", [ emailto ], message.as_string())
    smtp.quit()
Exemple #5
0
def send_update_notification(mod):
    followers = [u.email for u in mod.followers]
    changelog = mod.versions[-1].changelog
    if changelog:
        changelog = '\n'.join(['    ' + l for l in changelog.split('\n')])

    for follower in followers:
        smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
        smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
        with open("emails/mod-updated") as f:
            message = MIMEText(
                pystache.render(
                    f.read(), {
                        'mod':
                        mod,
                        'domain':
                        _cfg("domain"),
                        'latest':
                        mod.versions[-1],
                        'url':
                        '/mod/' + str(mod.id) + '/' +
                        secure_filename(mod.name)[:64],
                        'changelog':
                        changelog
                    }))
        message[
            'Subject'] = mod.user.username + " has just updated " + mod.name + "!"
        message['From'] = "*****@*****.**"
        message['To'] = follower
        smtp.sendmail("*****@*****.**", [follower],
                      message.as_string())
        smtp.quit()
Exemple #6
0
def send_autoupdate_notification(mod):
    if _cfg("smtp-host") == "":
        return
    followers = [u.email for u in mod.followers]
    changelog = mod.default_version().changelog
    if changelog:
        changelog = '\n'.join(['    ' + l for l in changelog.split('\n')])

    targets = list()
    for follower in followers:
        targets.append(follower)
    if len(targets) == 0:
        return
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/mod-autoupdated") as f:
        message = MIMEText(html.parser.HTMLParser().unescape(pystache.render(f.read(),
            {
                'mod': mod,
                'domain': _cfg("domain"),
                'latest': mod.default_version(),
                'url': '/mod/' + str(mod.id) + '/' + secure_filename(mod.name)[:64],
                'changelog': changelog
            })))
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = mod.name + " is compatible with KSP " + mod.versions[0].ksp_version + "!"
    message['From'] = "*****@*****.**"
    message['To'] = ";".join(targets)
    smtp.sendmail("*****@*****.**", targets, message.as_string())
    smtp.quit()
Exemple #7
0
def send_confirmation(user):
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/confirm-account") as f:
        message = MIMEText(pystache.render(f.read(), { 'user': user, "domain": _cfg("domain"), 'confirmation': user.confirmation }))
    message['Subject'] = "Welcome to Kerbal Stuff!"
    message['From'] = "*****@*****.**"
    message['To'] = user.email
    smtp.sendmail("*****@*****.**", [ user.email ], message.as_string())
    smtp.quit()
Exemple #8
0
def send_reset(user):
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/password-reset") as f:
        message = MIMEText(pystache.render(f.read(), { 'user': user, "domain": _cfg("domain"), 'confirmation': user.passwordReset }))
    message['X-MC-Important'] = "true"
    message['Subject'] = "Reset your password on Kerbal Stuff"
    message['From'] = "*****@*****.**"
    message['To'] = user.email
    smtp.sendmail("*****@*****.**", [ user.email ], message.as_string())
    smtp.quit()
Exemple #9
0
def send_bulk_email(users, subject, body):
    if _cfg("smtp-host") == "":
        return
    for u in users:
        smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
        smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
        message = MIMEText(body)
        message['Subject'] = subject
        message['From'] = "*****@*****.**"
        message['To'] = u
        smtp.sendmail("*****@*****.**", [ u ], message.as_string())
        smtp.quit()
Exemple #10
0
def send_mail(sender, recipients, subject, message, important=False):
    if _cfg("smtp-host") == "":
        return
	smtp = None
	# If there's a config option provided, use starttls
	if _cfgb('tls'):
		smtp = smtplib.SMTP_SSL(_cfg("smtp-host"), _cfgi("smtp-port"), )
	else:		
		smtp = smtplib.SMTP(host=_cfg("smtp-host"), port=_cfgi("smtp-port"), keyfile=open(_cfg('tls-keyfile')), certfile=open(_cfg('tls-certfile')))
	if _cfg("smtp-user") == "" and _cfg("smtp-password") == "":
		smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    message = MIMEText(message)
    if important:
        message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = sender
    for group in chunks(recipients, 100):
        message['To'] = ";".join(group)
        print("Sending email from {} to {} recipients".format(sender, len(group)))
        smtp.sendmail(sender, group, message.as_string())
    smtp.quit()
Exemple #11
0
def send_bulk_email(users, subject, body):
    if _cfg("smtp-host") == "":
        return
    targets = list()
    for u in users:
        targets.append(u)
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    message = MIMEText(body)
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = "*****@*****.**"
    message['To'] = ";".join(targets)
    smtp.sendmail("*****@*****.**", targets, message.as_string())
    smtp.quit()
Exemple #12
0
def send_mail(sender, recipients, subject, message, important=False):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(host=_cfg("smtp-host"), port=_cfgi("smtp-port"))
    message = MIMEText(message)
    if important:
        message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = sender
    for group in chunks(recipients, 100):
        message['To'] = ";".join(group)
        print("Sending email from {} to {} recipients".format(sender, len(group)))
        smtp.sendmail(sender, group, message.as_string())
    smtp.quit()
Exemple #13
0
def send_reset(user):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/password-reset") as f:
        message = MIMEText(html.parser.HTMLParser().unescape(\
                pystache.render(f.read(), { 'user': user, "domain": _cfg("domain"), 'confirmation': user.passwordReset })))
    message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = "Reset your password on Kerbal Stuff"
    message['From'] = "*****@*****.**"
    message['To'] = user.email
    smtp.sendmail("*****@*****.**", [ user.email ], message.as_string())
    smtp.quit()
def send_reset(user):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.starttls()
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/password-reset") as f:
        message = MIMEText(html.parser.HTMLParser().unescape(\
                pystache.render(f.read(), { 'user': user, "domain": _cfg("domain"), 'confirmation': user.passwordReset })))
    message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = "Reset your password on Modulous"
    message['From'] = "*****@*****.**"
    message['To'] = user.email
    smtp.sendmail("*****@*****.**", [ user.email ], message.as_string())
    smtp.quit()
Exemple #15
0
def send_mail(sender, recipients, subject, message, important=False):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(host=_cfg("smtp-host"), port=_cfgi("smtp-port"))
    message = MIMEText(message)
    if important:
        message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = sender
    for group in chunks(recipients, 100):
        message['To'] = ";".join(group)
        print("Sending email from {} to {} recipients".format(
            sender, len(group)))
        smtp.sendmail(sender, group, message.as_string())
    smtp.quit()
Exemple #16
0
def send_grant_notice(mod, user):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/grant-notice") as f:
        message = MIMEText(html.parser.HTMLParser().unescape(\
                pystache.render(f.read(), { 'user': user, "domain": _cfg("domain"),\
                'mod': mod, 'url': url_for('mods.mod', id=mod.id, mod_name=mod.name) })))
    message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = "You've been asked to co-author a mod on Kerbal Stuff"
    message['From'] = "*****@*****.**"
    message['To'] = user.email
    smtp.sendmail("*****@*****.**", [ user.email ], message.as_string())
    smtp.quit()
Exemple #17
0
def send_confirmation(user):
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/confirm-account") as f:
        message = MIMEText(
            pystache.render(
                f.read(), {
                    'user': user,
                    "domain": _cfg("domain"),
                    'confirmation': user.confirmation
                }))
    message['X-MC-Important'] = "true"
    message['Subject'] = "Welcome to Kerbal Stuff!"
    message['From'] = "*****@*****.**"
    message['To'] = user.email
    smtp.sendmail("*****@*****.**", [user.email], message.as_string())
    smtp.quit()
Exemple #18
0
def create(background_path: str, thumbnail_path: str) -> None:
    if not os.path.isfile(background_path):
        raise FileNotFoundError('Background image does not exist')

    size_str = _cfg('thumbnail_size')
    if not size_str:
        size_str = "320x195"
    size_str_tuple = size_str.split('x')
    size = (int(size_str_tuple[0]), int(size_str_tuple[1]))

    quality = _cfgi('thumbnail_quality')
    # Docs say the quality shouldn't be above 95:
    # https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#jpeg
    if not quality or not (0 <= quality <= 95):
        quality = 80

    im = Image.open(background_path)

    # We want to resize the image to the desired size in the least costly way,
    # while not distorting it. This means we first check which side needs _less_ rescaling to reach
    # the target size. After that we scale it down while keeping the original aspect ratio.
    x_ratio = abs(im.width / size[0])
    y_ratio = abs(im.height / size[1])

    if x_ratio < y_ratio:
        im = im.resize((size[0], round(im.height / x_ratio)), Image.LANCZOS)
    else:
        im = im.resize((round(im.width / y_ratio), size[1]), Image.LANCZOS)

    # Now there's one pair of edges that already has the target length (height or width).
    # Next step is cropping the thumbnail out of the center of the down-scaled base image,
    # to also downsize the other edge pair without distorting the image.
    # We basically define the upper left and the lower right corner of the area to crop out here,
    # but we have to serve them separately (better: in one 4-tuple) to im.crop():
    # https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.crop
    box_left = round(0.5 * (im.width - size[0]))
    box_upper = round(0.5 * (im.height - size[1]))
    box_right = round(0.5 * (im.width + size[0]))
    box_lower = round(0.5 * (im.height + size[1]))
    im = im.crop((box_left, box_upper, box_right, box_lower))

    if im.mode != "RGB":
        im = im.convert("RGB")
    im.save(thumbnail_path, 'jpeg', quality=quality, optimize=True)
Exemple #19
0
def send_confirmation(user, followMod=None):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(_cfg("smtp-host"), _cfgi("smtp-port"))
    smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    with open("emails/confirm-account") as f:
        if followMod != None:
            message = MIMEText(pystache.render(f.read(), { 'user': user, "domain": _cfg("domain"),\
                    'confirmation': user.confirmation + "?f=" + followMod }))
        else:
            message = MIMEText(html.parser.HTMLParser().unescape(\
                    pystache.render(f.read(), { 'user': user, "domain": _cfg("domain"), 'confirmation': user.confirmation })))
    message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = "Welcome to Kerbal Stuff!"
    message['From'] = "*****@*****.**"
    message['To'] = user.email
    smtp.sendmail("*****@*****.**", [ user.email ], message.as_string())
    smtp.quit()
Exemple #20
0
def send_mail(sender, recipients, subject, message, important=False):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(host=_cfg("smtp-host"), port=_cfgi("smtp-port"))
    if _cfgb("smtp-tls"):
        smtp.starttls()
    if _cfg("smtp-user") != "":
        smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    message = MIMEText(message)
    if important:
        message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = sender
    if len(recipients) > 1:
        message['Precedence'] = 'bulk'
    for group in chunks(recipients, 100):
        if len(group) > 1:
            message['To'] = "undisclosed-recipients:;"
        else:
            message['To'] = ";".join(group)
        print("Sending email from {} to {} recipients".format(sender, len(group)))
        smtp.sendmail(sender, group, message.as_string())
    smtp.quit()
Exemple #21
0
            # TODO: Bug the slimit guys to support python 3
            #if not app.debug:
            #    javascript = minify(javascript)

            with open(os.path.join(app.static_folder, output), "w") as w:
                w.write(javascript)
                w.flush()

    d = os.walk('images')
    for f in list(d)[0][2]:
        outputpath = os.path.join(app.static_folder, os.path.basename(f))
        inputpath = os.path.join('images', f)
        copyfile(inputpath, outputpath)


@app.before_first_request
def compile_first():
    pass
    #prepare()


@app.before_request
def compile_if_debug():
    if app.debug and _cfg("debug-static-recompile").lower() in ['true', 'yes']:
        prepare()


if __name__ == '__main__':
    app.run(host=_cfg("debug-host"), port=_cfgi('debug-port'), debug=True)
Exemple #22
0
                    else:
                        javascript += coffeescript.compile(coffee, bare=bare)
            output = '.'.join(f.rsplit('.')[:-1]) + '.js'

            # TODO: Bug the slimit guys to support python 3
            #if not app.debug:
            #    javascript = minify(javascript)

            with open(os.path.join(app.static_folder, output), "w") as w:
                w.write(javascript)
                w.flush()

    d = os.walk('images')
    for f in list(d)[0][2]:
        outputpath = os.path.join(app.static_folder, os.path.basename(f))
        inputpath = os.path.join('images', f)
        copyfile(inputpath, outputpath)

@app.before_first_request
def compile_first():
    pass
    #prepare()

@app.before_request
def compile_if_debug():
    if app.debug and _cfg("debug-static-recompile").lower() in ['true','yes']:
        prepare()

if __name__ == '__main__':
    app.run(host=_cfg("debug-host"), port=_cfgi('debug-port'), debug=True)