1# Copyright 2013-2015 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""" 

11Implements a management command used to invoke the processing of control 

12messages. 

13""" 

14import io 

15import sys 

16 

17from django.core.management.base import BaseCommand 

18 

19from distro_tracker.core.utils.email_messages import message_from_bytes 

20from distro_tracker.mail.processor import MailProcessor 

21 

22 

23class Command(BaseCommand): 

24 """ 

25 A Django management command used to invoke the processing of control 

26 messages. 

27 

28 The received message is expected as input on stdin. 

29 """ 

30 input_file = sys.stdin 

31 

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

33 # Get the binary buffer behind the textual one 

34 try: 

35 self.input_file = self.input_file.detach() 

36 except io.UnsupportedOperation: 

37 pass 

38 msg = message_from_bytes(self.input_file.read()) 

39 handler = MailProcessor(msg) 

40 handler.process()