12 app = flask.Flask(__name__)
25 @app.route('/tags', methods=['GET'])
27 return flask.Response(
28 response=json.dumps(sorted(_AVAILABLE_TAGS)),
29 mimetype='application/json')
32 @app.route('/mid/<message_id>', methods=['GET', 'POST'])
33 def message_id_tags(message_id):
34 if flask.request.method == 'POST':
35 tags = _TAGS.get(message_id, set())
36 new_tags = tags.copy()
37 for change in flask.request.get_json():
38 if change.startswith('+'):
39 new_tags.add(change[1:])
40 elif change.startswith('-'):
42 new_tags.remove(change[1:])
44 return flask.Response(status=400)
46 return flask.Response(status=400)
47 _TAGS[message_id] = new_tags
48 return flask.Response(
49 response=json.dumps(sorted(new_tags)),
50 mimetype='application/json')
51 elif flask.request.method == 'GET':
53 tags = _TAGS[message_id]
55 return flask.Response(status=404)
56 return flask.Response(
57 response=json.dumps(sorted(tags)),
58 mimetype='application/json')
61 @app.route('/gmane/<group>/<int:article>', methods=['GET'])
62 def gmane_message_id(group, article):
63 url = 'http://download.gmane.org/{}/{}/{}'.format(
64 group, article, article + 1)
65 response = urllib.request.urlopen(url=url, timeout=3)
66 mbox_bytes = response.read()
67 with tempfile.NamedTemporaryFile(prefix='nmbug-', suffix='.mbox') as f:
69 mbox = mailbox.mbox(path=f.name)
70 _, message = mbox.popitem()
71 message_id = message['message-id']
72 return flask.Response(
73 response=message_id.lstrip('<').rstrip('>'),
74 mimetype='text/plain')
77 if __name__ == '__main__':
79 app.run(host='0.0.0.0')