11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/sum/model/incoming_mail.rb', line 11
def receive(mail)
return unless body = get_body(mail)
emails = parse_emails(mail.subject, body.body)
numbers = parse_numbers(mail.subject, body.body)
start = parse_start(mail.subject, body.body)
stop = parse_stop(mail.subject, body.body)
if mail.from[0] && email = UserEmail.find_by_email(mail.from[0])
user = email.user
else
return
end
if user
emails.each do |email|
user.add_email!(email, true)
end
numbers.each do |number|
user.spend!(number)
end
email.activate! if start
email.deactivate! if stop
end
[ emails, numbers, start, stop ]
end
|