Skip to content
Snippets Groups Projects
Select Git revision
  • eb48fb68925e7b3b14ca68118d87585db63c43c8
  • master default protected
  • 9.0
  • marcus/wix3
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

backend.c

Blame
  • main.py 1.40 KiB
    #!/usr/bin/env python3
    
    import smtpd
    import asyncore
    from email import message_from_bytes
    import email.policy
    from dateutil.parser import parse
    import subprocess
    import re
    
    class CustomSMTPServer(smtpd.SMTPServer):
        def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
            msg = message_from_bytes(data, policy=email.policy.default)
            body = msg.get_content()
            d = parse(msg.get('Date'))
            title = msg.get('Subject')
    
            if not title:
                print("Title missing")
                return
    
            valid_destinations = [
                    'massutskick@vastgota.nation.liu.se',
                    'massutskick@vastgota.lysator.liu.se',
                    ]
    
            for destination in valid_destinations:
                if destination in msg.get('To'):
                    break
            else:
                print('Will only publish massutskick')
                return
    
            title = re.sub('^\[.*\] *', '', title)
    
            subprocess.run(['wp', 'post', 'create',
                    '--post_author=2'
                    f'--post_date={d:%Y-%m-%d}',
                    f"--post_title={title}",
                    '--post_status=publish',
                    '--post_category=Veckomail',
                    f"--post_content=<pre>{body}</pre>"],
                    cwd='/usr/share/wordpress',
                    shell=False)
            return
    
    
    server = CustomSMTPServer(('0.0.0.0', 1025), None,
            decode_data=False)
    asyncore.loop()