1# Copyright 2013-2020 The Distro Tracker Developers 

2# See the COPYRIGHT file at the top-level directory of this distribution and 

3# at https://deb.li/DTAuthors 

4# 

5# This file is part of Distro Tracker. It is subject to the license terms 

6# in the LICENSE file found in the top-level directory of this 

7# distribution and at https://deb.li/DTLicense. No part of Distro Tracker, 

8# including this file, may be copied, modified, propagated, or distributed 

9# except according to the terms contained in the LICENSE file. 

10 

11""" 

12A management command which is used to process an email message which could 

13potentially be turned into a news item. 

14""" 

15 

16import logging 

17import sys 

18 

19from django.core.management.base import BaseCommand 

20 

21from distro_tracker.core.utils import message_from_bytes 

22from distro_tracker.mail.dispatch import classify_message 

23 

24logger = logging.getLogger(__name__) 

25 

26 

27class Command(BaseCommand): 

28 input_file = sys.stdin 

29 

30 def handle(self, *args, **kwargs): 

31 logger.info("Processing a received message") 

32 # Make sure to read binary data. 

33 input_data = self.input_file.detach().read() 

34 

35 msg = message_from_bytes(input_data) 

36 pkg, keyword = classify_message(msg) 

37 

38 logger.info('Completed processing a received message for %s/%s', 

39 pkg, keyword)