Commit b7e5d5b3d556fbbff27d5d3b99d4be5b06292a43

Authored by Luan
2 parents cf44a3ad 915e79f8

Merge branch 'master' of github.com:TracyWebTech/colab

puppet/bootstrap.sh
1 1 #!/bin/bash
2 2  
3   -PUPPET_VERSION=`dpkg -l | grep puppet-common | awk '{ print $3 }'`
  3 +PUPPET_VERSION=`dpkg -l | grep puppet-common | awk '{ print $3 }' | cut -d- -f1`
  4 +dpkg --compare-versions "$PUPPET_VERSION" "<" "3.3" ; OUTDATED=$?
4 5  
5   -if [ "$PUPPET_VERSION" != '3.2.3-1puppetlabs1' ] ; then
  6 +if [ $OUTDATED -eq 0 ] ; then
6 7 wget -O /tmp/puppet_apt.deb http://apt.puppetlabs.com/puppetlabs-release-precise.deb &> /dev/null
7 8 dpkg -i /tmp/puppet_apt.deb
8 9 DEBIAN_FRONTEND=noninteractive apt-get update -y
... ...
src/super_archives/management/commands/import_emails.py
... ... @@ -13,8 +13,10 @@ from django.db import transaction
13 13 from django.template.defaultfilters import slugify
14 14 from django.core.management.base import BaseCommand, CommandError
15 15  
16   -from super_archives.models import MailingList, Message, Thread, EmailAddress
17   -from super_archives.management.commands.message import Message as CustomMessage
  16 +from colab.super_archives.models import MailingList, Message, \
  17 + Thread, EmailAddress
  18 +from colab.super_archives.management.commands.message import Message as \
  19 + CustomMessage
18 20  
19 21  
20 22 class Command(BaseCommand, object):
... ... @@ -149,6 +151,10 @@ class Command(BaseCommand, object):
149 151 def save_email(self, list_name, email_msg, index):
150 152 """Save email message into the database."""
151 153  
  154 + msg_id = email_msg.get('Message-ID')
  155 + if not msg_id:
  156 + return
  157 +
152 158 # Update last imported message into the DB
153 159 mailinglist, created = MailingList.objects.get_or_create(name=list_name)
154 160 mailinglist.last_imported_index = index
... ... @@ -162,7 +168,7 @@ class Command(BaseCommand, object):
162 168 # If the message is already at the database don't do anything
163 169 try:
164 170 messages = Message.objects.get(
165   - message_id=email_msg.get('Message-ID'),
  171 + message_id=msg_id,
166 172 thread__mailinglist=mailinglist
167 173 )
168 174  
... ... @@ -172,6 +178,9 @@ class Command(BaseCommand, object):
172 178 mailinglist.save()
173 179  
174 180 def create_email(self, mailinglist, email_msg):
  181 + received_time = email_msg.get_received_datetime()
  182 + if not received_time:
  183 + return
175 184  
176 185 real_name, from_ = email_msg.get_from_addr()
177 186  
... ...
src/super_archives/management/commands/message.py
... ... @@ -13,35 +13,35 @@ import chardet
13 13 def get_charset(message, default='ASCII'):
14 14 """Get the message charset"""
15 15  
16   - charset = message.get_content_charset()
17   -
  16 + charset = message.get_content_charset()
  17 +
18 18 if not charset:
19 19 charset = message.get_charset()
20   -
  20 +
21 21 if not charset:
22 22 charset = default
23   -
  23 +
24 24 try:
25 25 codecs.lookup(charset)
26 26 except LookupError:
27 27 charset = default
28   -
  28 +
29 29 return charset
30   -
  30 +
31 31  
32 32 class Message(mailbox.mboxMessage):
33   -
  33 +
34 34 RECEIVED_DELIMITER = re.compile('\n|;')
35   -
  35 +
36 36 def get_subject(self):
37 37 subject = email.header.decode_header(self['Subject'])
38   -
  38 +
39 39 if isinstance(subject, list):
40 40 new_subject = u''
41 41 for text_part, encoding in subject:
42 42 if not encoding:
43 43 encoding = get_charset(self)
44   -
  44 +
45 45 try:
46 46 new_subject += unicode(text_part, encoding)
47 47 except (UnicodeDecodeError, LookupError):
... ... @@ -50,7 +50,7 @@ class Message(mailbox.mboxMessage):
50 50 except (UnicodeDecodeError, LookupError):
51 51 encoding = chardet.detect(text_part)['encoding']
52 52 new_subject += unicode(text_part, encoding)
53   -
  53 +
54 54 return ''.join(new_subject)
55 55  
56 56 def get_body(self):
... ... @@ -77,25 +77,27 @@ class Message(mailbox.mboxMessage):
77 77 get_charset(self),
78 78 "replace")
79 79 return body.strip()
80   -
  80 +
81 81 def get_received_datetime(self):
  82 + if not self.has_key('Received'):
  83 + return None
82 84 # The time received should always be the last element
83   - # in the `Received` attribute from the message headers
  85 + # in the `Received` attribute from the message headers
84 86 received_header = self.RECEIVED_DELIMITER.split(self['Received'])
85 87 received_time_header = received_header[-1].strip()
86   -
  88 +
87 89 date_tuple = email.utils.parsedate_tz(received_time_header)
88 90 utc_timestamp = email.utils.mktime_tz(date_tuple)
89 91 utc_datetime = datetime.datetime.fromtimestamp(utc_timestamp,
90 92 pytz.utc)
91 93  
92 94 return utc_datetime
93   -
  95 +
94 96 def get_from_addr(self):
95 97 real_name_raw, from_ = email.utils.parseaddr(self['From'])
96 98 real_name_str, encoding = email.header.decode_header(real_name_raw)[0]
97 99 if not encoding:
98 100 encoding = 'ascii'
99   -
  101 +
100 102 real_name = unicode(real_name_str, encoding, errors='replace')
101 103 return real_name, from_
... ...