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

11Module implementing the processing of received emails which could be turned 

12into news items. 

13""" 

14from distro_tracker.core.models import EmailNews, PackageName 

15from distro_tracker.core.utils import get_or_none 

16 

17 

18def create_news(message, package, create_package=False, **kwargs): 

19 """ 

20 Create a news item from the given message. 

21 

22 The created news parameters are: 

23 

24 - title - the Subject of the message 

25 - content - the message content itself 

26 - content_type - message/rfc822 

27 

28 :param message: A message which should be turned into a news item. 

29 :type message: :class:`email.message.Message` 

30 :param package: The package for which this news item should be created. 

31 :type package: :class:`distro_tracker.core.models.PackageName` or a string. 

32 

33 :returns: The created news item 

34 :rtype: :class:`distro_tracker.core.models.News` 

35 """ 

36 if not isinstance(package, PackageName): 

37 if create_package: 

38 package, _ = PackageName.objects.get_or_create(name=package) 

39 else: 

40 package = get_or_none(PackageName, name=package) 

41 if package is None: # Don't record news for non-existing packages 

42 return 

43 return EmailNews.objects.create_email_news(message, package, **kwargs)