Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 9
- Log:
Reverting to the Tarball version of RForum. The prototype RISC OS Open
Ltd web site used a HEAD revision of RForum from RForum's SVN but this
specific revision was not recorded, so the changes are unknown. I'm
going to separately apply the current HEAD as a patch to the rolled
back Tarball revision, and apply the RISC OS Open Ltd site version as
a patch, then attempt to merge the latter to the former. If this fails
I'll revert to my original strategy - take the Tarball, commit HEAD,
then commit the web site version (which will implicitly revert to a
slightly earlier RForum version).
- Author:
- adh
- Date:
- Sat Jul 22 19:57:27 +0100 2006
- Size:
- 3511 Bytes
1 | module ReceivedMail |
2 | def from_guest? |
3 | User.find_by_email(self.from.first.downcase) == nil |
4 | end |
5 | |
6 | def from_unauthorized_user? |
7 | User.find_by_email(self.from.first.downcase).sends_email == 0 |
8 | end |
9 | |
10 | def author |
11 | if user = User.find_by_email(self.from.first.downcase) |
12 | return user |
13 | else |
14 | name = TMail::Address.parse(self['from'].to_s).phrase |
15 | if name.nil? || name.size < 2 |
16 | name = 'unknown' |
17 | end |
18 | email = self.from.first |
19 | return Guest.new(name, email) |
20 | end |
21 | end |
22 | |
23 | def parent |
24 | if self.references.nil? and self.in_reply_to.nil? |
25 | return nil |
26 | end |
27 | |
28 | if self['in-reply-to'] |
29 | if self.in_reply_to.first |
30 | parent_messageid = self.in_reply_to.first |
31 | else |
32 | # TMail fails to parse in-reply-to headers where <> is missing, |
33 | # so we do it manually here |
34 | parent_messageid = self['in-reply-to'].phrases.first |
35 | end |
36 | else |
37 | parent_messageid = self.references.reverse.first |
38 | end |
39 | |
40 | parent_messageid = parent_messageid.to_s.tr('<>', '') |
41 | |
42 | if post = Post.find_by_messageid(parent_messageid) |
43 | return post |
44 | else |
45 | if self.cleaned_subject =~ /^Re:/i |
46 | raise 'parent not found' |
47 | else |
48 | # if no parent is found and subject is no reply, treat as new topic |
49 | return nil |
50 | end |
51 | end |
52 | end |
53 | |
54 | def forum |
55 | ((self.to || []) | (self.cc || [])).each do |address| |
56 | if forum = Forum.find_by_list_address(address.downcase) |
57 | return forum |
58 | end |
59 | end |
60 | |
61 | raise "mail for unknown forum received (#{self.to.inspect})" |
62 | end |
63 | |
64 | def create_post |
65 | if Post.find_by_messageid(self.message_id.tr('<>', '')) |
66 | raise 'messageid : has already been taken' |
67 | end |
68 | |
69 | if self.parent |
70 | self.parent.add_reply(self.to_post) |
71 | else |
72 | self.forum.add_post(self.to_post) |
73 | end |
74 | end |
75 | |
76 | def to_post |
77 | post = Post.new |
78 | post.subject = self.cleaned_subject |
79 | post.text = self.cleaned_text |
80 | post.author = self.author |
81 | post.post_method = 'mail' |
82 | post.messageid = self.message_id.tr('<>', '') |
83 | post |
84 | end |
85 | |
86 | def cleaned_subject |
87 | s = self.subject |
88 | # remove first [tag] from subject |
89 | s.sub!(/\[.+?\] ?/, '') |
90 | s.strip! |
91 | if s.size == 0 |
92 | s = '(no subject)' |
93 | end |
94 | s |
95 | end |
96 | |
97 | def remove_signature(s) |
98 | s = s.dup |
99 | s.gsub!(/\n--(\n.+){0,3}\s*\Z/, '') |
100 | s.gsub!(/\n-- (\n.+){0,6}\s*\Z/, '') |
101 | s.gsub!(/\n-----+(\n.+){0,6}\s*\Z/, '') |
102 | s.gsub!(/\n______+(\n.+){0,6}\s*\Z/, '') |
103 | s |
104 | end |
105 | |
106 | def cleaned_text |
107 | s = self.plaintext_body |
108 | |
109 | s = remove_signature(s) |
110 | |
111 | # remove TOFU |
112 | s.gsub!(/(\n>.*)+\s*\Z/, '') |
113 | if $1 |
114 | # remove "xy wrote:" |
115 | s.gsub!(/\s*\n.*wrote.*:\s*\Z/, '') |
116 | end |
117 | |
118 | # remove attached "original message" |
119 | s.gsub!(/\s*\n-+Original Message-+.*$/m, '') |
120 | |
121 | # remove too long quoting |
122 | s.gsub!(/^(>.*\n)+?((>+.*\n){10})\s*/, '\3') |
123 | |
124 | s.strip! |
125 | s |
126 | end |
127 | |
128 | def plaintext_body |
129 | if self.multipart? |
130 | # look for multipart/alternative parts |
131 | alternative_parts = self.parts.reject {|p| not p.content_type =~ /^multipart/ } |
132 | interesting_parts = (alternative_parts.first.parts rescue []) + self.parts |
133 | plaintext_parts = interesting_parts.reject {|p| p.content_type != 'text/plain' } |
134 | raise "couln't find a text/plain mime part" if plaintext_parts.empty? |
135 | plaintext_parts.first.body |
136 | else |
137 | raise "body is not text/plain" unless self.content_type = 'text/plain' |
138 | self.body |
139 | end |
140 | end |
141 | end |