msgthr 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a571597f50c7ec04abef8c956d811854d727bcc
4
+ data.tar.gz: 07f8634e7f6bd758206ad6e8170acd5048af2b07
5
+ SHA512:
6
+ metadata.gz: 1e13bda13b30d4548955d306570848c8bf5f0993575617b81822a4fc684085182eb7200f5e0cadfc56c38215c166d06d8fa07853cbbad784c21665b13e9355ee
7
+ data.tar.gz: 7217b572b347c32ef5a01d0b95c805dfc37e28bd54ad078d4bd38f8b7c5396ba0806d052c2194b078fac78770c72cb449cb485f2ec8af1f8fdff68b528fd3db6
data/.document ADDED
@@ -0,0 +1 @@
1
+ lib
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ *.gz
3
+ .manifest
4
+ pkg/
5
+ /LATEST
6
+ /NEWS
7
+ /NEWS.atom.xml
8
+ /doc
9
+ /www
data/.olddoc.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ cgit_url: https://80x24.org/msgthr.git
3
+ git_url: git://80x24.org/msgthr.git
4
+ rdoc_url: https://80x24.org/msgthr/rdoc/
5
+ ml_url: https://80x24.org/msgthr-public/
6
+ public_email: msgthr-public@80x24.org
data/COPYING ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
data/GNUmakefile ADDED
@@ -0,0 +1,76 @@
1
+ # Copyright (C) 2016 all contributors <msgthr-public@80x24.org>
2
+ # License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>
3
+ all::
4
+ pkg = msgthr
5
+ RUBY = ruby
6
+ lib := lib
7
+ VERSION := 1.0.1
8
+ RSYNC_DEST := 80x24.org:/srv/80x24/msgthr/
9
+
10
+ RSYNC = rsync
11
+ OLDDOC = olddoc
12
+ RDOC = rdoc
13
+
14
+ all:: test
15
+ test_units := $(wildcard test/test_*.rb)
16
+ test: $(test_units)
17
+ $(test_units):
18
+ $(RUBY) -w -I $(lib) $@ -v
19
+
20
+ check-warnings:
21
+ @(for i in $$(git ls-files '*.rb'| grep -v '^setup\.rb$$'); \
22
+ do $(RUBY) -d -W2 -c $$i; done) | grep -v '^Syntax OK$$' || :
23
+
24
+ check: test
25
+
26
+ pkggem := pkg/$(pkg)-$(VERSION).gem
27
+
28
+ fix-perms:
29
+ git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
30
+
31
+ gem: $(pkggem)
32
+
33
+ install-gem: $(pkggem)
34
+ gem install --local $(CURDIR)/$<
35
+
36
+ $(pkggem): .manifest
37
+ VERSION=$(VERSION) gem build $(pkg).gemspec
38
+ mkdir -p pkg
39
+ mv $(@F) $@
40
+
41
+ pkg_extra :=
42
+
43
+ .manifest: fix-perms
44
+ git ls-files | LC_ALL=C sort >$@+
45
+ cmp $@+ $@ || mv $@+ $@; rm -f $@+
46
+
47
+ package: $(pkggem)
48
+
49
+ NEWS: .olddoc.yml
50
+ $(OLDDOC) prepare
51
+ LATEST: NEWS
52
+
53
+ doc:: .document .olddoc.yml
54
+ -find lib -type f -name '*.rbc' -exec rm -f '{}' ';'
55
+ $(RM) -r doc
56
+ $(RDOC) -f oldweb
57
+
58
+ # this requires GNU coreutils variants
59
+ ifneq ($(RSYNC_DEST),)
60
+ publish_doc:
61
+ -git set-file-times
62
+ $(MAKE) doc
63
+ mkdir -p www
64
+ $(RM) -r www/rdoc
65
+ mv doc www/rdoc
66
+ install -m644 README www/README
67
+ install -m644 NEWS www/NEWS
68
+ install -m644 NEWS.atom.xml www/NEWS.atom.xml
69
+ for i in $$(find www -type f ! -regex '^.*\.gz$$'); do \
70
+ gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
71
+ $(RSYNC) -av www/ $(RSYNC_DEST)
72
+ git ls-files | xargs touch
73
+ endif
74
+
75
+ .PHONY: all test $(test_units)
76
+ .PHONY: check-warnings fix-perms
data/README ADDED
@@ -0,0 +1,102 @@
1
+ msgthr - container-agnostic, non-recursive message threading
2
+ ------------------------------------------------------------
3
+
4
+ Pure Ruby message threading based on the algorithm described by
5
+ JWZ in <https://www.jwz.org/doc/threading.html> and used in
6
+ countless mail and news readers; but with some features removed
7
+ and improved flexibility:
8
+
9
+ * Message format-agnostic, not limited to email or NNTP;
10
+ but even appropriate for forums, blog comments, IM, etc.
11
+ For mail and NNTP messages, that means you must extract
12
+ the Message-ID and parse the References and In-Reply-To
13
+ headers into an array yourself.
14
+
15
+ * No recursion; all algorithms are non-recursive to avoid
16
+ SystemStackError exceptions in deep message threads.
17
+ Memory usage is bound by the number of lightweight containers
18
+ needed to represent a thread.
19
+
20
+ * No pruning of non-leaf ghosts. Readers are not shielded
21
+ from deleted or lost messages. Equivalent to setting
22
+ "hide_missing" to "no" in mutt.
23
+
24
+ * No grouping by subject[1]. This makes things ideal for short
25
+ messages such as chat and status updates. For email, this
26
+ encourages the use of proper client which set In-Reply-To
27
+ or References headers. Equivalent to setting "strict_threads"
28
+ to "yes" in mutt.
29
+
30
+ [1] - Instead, messages with the same Subject can be grouped
31
+ by a search engine. For email, this would be done using
32
+ a mail search engine like notmuch or mairix.
33
+
34
+ Source code
35
+ -----------
36
+
37
+ Our Ruby 1.9.3+ compatible code is available via git,
38
+ no C compiler or other dependencies are required:
39
+
40
+ git clone git://80x24.org/msgthr
41
+ git clone https://80x24.org/msgthr.git
42
+
43
+ Releases may be downloaded via RubyGems:
44
+
45
+ gem fetch [-v VERSION] msgthr
46
+
47
+ The code used in this Ruby library was originally derived from
48
+ the Mail::Thread module for Perl 5.x:
49
+
50
+ https://metacpan.org/release/Mail-Thread
51
+
52
+ Contact
53
+ -------
54
+
55
+ Feedback is welcome via plain-text mail (no HTML, images, etc).
56
+ Please send comments, user/dev discussion, patches, bug reports,
57
+ and pull requests to the open-to-all mailing list at:
58
+
59
+ msgthr-public@80x24.org
60
+
61
+ No subscription will ever be required to post. Please Cc: all
62
+ recipients as subscription will never be necessary.
63
+
64
+ Mailing list archives are available via HTTPS and NNTP:
65
+
66
+ https://80x24.org/msgthr-public/
67
+ nntp://news.public-inbox.org/inbox.comp.lang.ruby.msgthr
68
+
69
+ You may optionally subscribe, but will never be required to:
70
+
71
+ msgthr-public+subscribe@80x24.org
72
+
73
+ This README is our homepage, we would rather be working on cool
74
+ stuff day than worrying about the next browser vulnerability
75
+ because CSS/JS/images are all too complicated for us.
76
+
77
+ RDoc API documentation in simple HTML is available at:
78
+
79
+ https://80x24.org/msgthr/rdoc/
80
+
81
+ Copyright
82
+ ---------
83
+
84
+ Copyright 2016-2017, all contributors (see git repo).
85
+ License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>
86
+
87
+ msgthr is copyrighted Free Software by all contributors, see logs in
88
+ revision control for names and email addresses of all of them.
89
+
90
+ msgthr is free software; you can redistribute it and/or modify
91
+ it under the terms of the GNU General Public License as
92
+ published by the Free Software Foundation; either version 2 of
93
+ the License, or (at your option) any later version.
94
+
95
+ msgthr is distributed in the hope that it will be useful, but
96
+ WITHOUT ANY WARRANTY; without even the implied warranty of
97
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98
+ GNU General Public License for more details.
99
+
100
+ You should have received a copy of the GNU General Public
101
+ License along with this program; if not, see
102
+ https://www.gnu.org/licenses/gpl-2.0.txt
@@ -0,0 +1,91 @@
1
+ # Copyright (C) 2016 all contributors <msgthr-public@80x24.org>
2
+ # License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>
3
+
4
+ # An internal container class, this is exposed for Msgthr#order!
5
+ # and Msgthr#walk_thread APIs. They should should not be initialized
6
+ # in your own code.
7
+ #
8
+ # One container object will exist for every message you call Msgthr#add! on,
9
+ # so there can potentially be many of these objects for large sets of
10
+ # messages.
11
+ class Msgthr::Container
12
+
13
+ # Unique message identifier, typically the Message-Id header for mail
14
+ # and news messages. This may be any hashable object, Integer values
15
+ # are allowed and will not be coerced to string values.
16
+ attr_reader :mid
17
+
18
+ # Opaque data pointer, may be used by the user for any purpose.
19
+ # This is +nil+ to denote missing (aka "ghost") messages.
20
+ attr_accessor :msg
21
+
22
+ # You probably do not need to use this.
23
+ # It is only safe to access this after Msgthr#order!
24
+ # This contains an Array of Msgthr::Container objects which have the
25
+ # +parent+ field pointing to us
26
+ attr_accessor :children
27
+
28
+ # You probably do not need to use this; and you should only use
29
+ # this after Msgthr#order! This points to the +parent+ of the
30
+ # message if one exists, and +nil+ if a message has no parent.
31
+ # This will only be accurate once all messages are added to
32
+ # a Msgthr set via Msgthr#add
33
+ attr_accessor :parent # :nodoc:
34
+
35
+ def initialize(mid) # :nodoc:
36
+ @mid = mid
37
+ @children = {} # becomes an Array after order!
38
+ @parent = nil
39
+ @msg = nil # opaque pointer supplied by user
40
+ end
41
+
42
+ # Returns the topmost message container with an opaque message pointer
43
+ # in it. This may be +nil+ if no message is available.
44
+ # This is preferable to using the container yielded by Msgthr#order!
45
+ # directly when handling incomplete message sets.
46
+ def topmost
47
+ q = [ self ]
48
+ while cont = q.shift
49
+ return cont if cont.msg
50
+ q.concat(cont.children.values)
51
+ end
52
+ nil
53
+ end
54
+
55
+ def add_child(child) # :nodoc:
56
+ raise 'cannot become child of self' if child == self
57
+ cid = child.mid
58
+
59
+ # reparenting:
60
+ parent = child.parent and parent.children.delete(cid)
61
+
62
+ @children[cid] = child
63
+ child.parent = self
64
+ end
65
+
66
+ def has_descendent(child) # :nodoc:
67
+ seen = Hash.new(0)
68
+ while child
69
+ return true if self == child || (seen[child] += 1) != 0
70
+ child = child.parent
71
+ end
72
+ false
73
+ end
74
+
75
+ # only called by Msgthr#order!
76
+ def order! # :nodoc:
77
+ seen = { @mid => true }
78
+ q = [ self ]
79
+ while cur = q.shift
80
+ c = []
81
+ cur.children.each do |cmid, cont|
82
+ next if seen[cmid]
83
+ c << cont
84
+ seen[cmid] = true
85
+ end.clear
86
+ yield(c) if c.size > 1
87
+ cur.children = c
88
+ q.concat(c)
89
+ end
90
+ end
91
+ end
data/lib/msgthr.rb ADDED
@@ -0,0 +1,155 @@
1
+ # Copyright (C) 2016 all contributors <msgthr-public@80x24.org>
2
+ # License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>
3
+
4
+ # Non-recursive, container-agnostic message threading.
5
+ #
6
+ # Usage is typically:
7
+ #
8
+ # * use Msgthr.new to create a new object
9
+ # * use Msgthr#add! for every message you have
10
+ # * use Msgthr#thread! to perform threading operations
11
+ # * optionally, use Msgthr#order! to sort messages
12
+ # * use Msgthr#walk_thread to iterate through the threaded tree
13
+ #
14
+ # See https://80x24.org/msgthr/README for more info
15
+ # You may email us publically at mailto:msgthr-public@80x24.org
16
+ # Archives are at https://80x24.org/msgthr-public/
17
+ class Msgthr
18
+
19
+ # an Array of root (parent-less) messages, only populated after
20
+ # calling Msgthr#thread!
21
+ attr_reader :rootset
22
+
23
+ # Initialize a Msgthr object
24
+ def initialize
25
+ @id_table = {}
26
+ @rootset = []
27
+ end
28
+
29
+ # Clear internal data structures to save memory and prepare for reuse
30
+ def clear
31
+ @rootset.clear
32
+ @id_table.clear
33
+ end
34
+
35
+ # Performs threading on the messages and returns the rootset
36
+ # (set of message containers without parents).
37
+ #
38
+ # Call this after all #add operations are complete.
39
+ # This does not sort, use #order! if sorting is necessary.
40
+ def thread!
41
+ ret = @rootset
42
+ @id_table.each_value { |cont| ret << cont if cont.parent.nil? }.clear
43
+ ret
44
+ end
45
+
46
+ # Performs an in-place sort on messages after thread!
47
+ # This is optional and intended to be called this only after #thread!
48
+ #
49
+ # This takes a block which yields an array of Msgthr::Container
50
+ # objects for sorting.
51
+ #
52
+ # To sort by unique +mid+ identifiers for each container:
53
+ #
54
+ # msgthr.order! { |ary| ary.sort_by!(&:mid) }
55
+ #
56
+ # If your opaque message pointer contains a +time+ accessor which gives
57
+ # a Time object:
58
+ #
59
+ # msgthr.order! do |ary|
60
+ # ary.sort_by! do |cont| # Msgthr::Container
61
+ # cur = cont.topmost
62
+ # cur ? cur.msg.time : Time.at(0)
63
+ # end
64
+ # end
65
+ #
66
+ # Note, using Msgthr::Container#topmost is NOT necessary when accessing
67
+ # Msgthr::Container#mid, as any known missing messages (ghosts)
68
+ # will still have a +mid+. However, Msgthr::Container#topmost is
69
+ # necessary if accessing Msgthr::Container#msg.
70
+ def order!
71
+ yield @rootset
72
+ @rootset.each do |cont|
73
+ # this calls Msgthr::Container#order!, which is non-recursive
74
+ cont.order! { |children| yield(children) }
75
+ end
76
+ end
77
+
78
+ # non-recursively walk a set of messages after #thread!
79
+ # (and optionally, #order!)
80
+ #
81
+ # This takes a block and yields 3 elements to it: +|level, container, index|+
82
+ # for each message container.
83
+ #
84
+ # * +level+ is the current depth within the walk (non-negative Integer)
85
+ # * +container+ is the Msgthr::Container object
86
+ # * +index+ is the offset of the container within its level (starting at 0)
87
+ #
88
+ # To display the subject of each message with indentation,
89
+ # assuming your +msg+ pointer has a +subject+ field:
90
+ #
91
+ # msgthr.walk_thread do |level, container, index|
92
+ # msg = container.msg
93
+ # subject = msg ? msg.subject : "[missing: <#{container.mid}>]"
94
+ # indent = ' ' * level
95
+ # printf("#{indent} % 3d. %s\n", index, subject)
96
+ # end
97
+ def walk_thread
98
+ i = -1
99
+ q = @rootset.map { |cont| [ 0, cont, i += 1 ] }
100
+ while tmp = q.shift
101
+ level, cont, idx = tmp
102
+ yield(level, cont, idx)
103
+ level += 1
104
+ i = -1
105
+ q = cont.children.map { |cld| [ level, cld, i += 1 ] }.concat(q)
106
+ end
107
+ end
108
+
109
+ # Adds a message to prepare a Msgthr object for threading.
110
+ #
111
+ # * +mid+ is a unique identifier for the message in a given thread.
112
+ # It is typically a String or Integer, but may be anything usable
113
+ # as a Hash key in Ruby.
114
+ #
115
+ # * +refs+ should be an Array of unique identifiers belonging
116
+ # to ancestors of the current message.
117
+ # For mail and news messages, this is usually the parsed result
118
+ # of the "References:" header. Order should be oldest to newest
119
+ # in terms of ancestry, with the last element being the
120
+ # immediate parent of the given message.
121
+ #
122
+ # This is +nil+ for messages with no parent (root messages).
123
+ #
124
+ # * +msg+ is an opaque object which typically contains a
125
+ # Mail or Tmail object for handling mail.
126
+ #
127
+ # If +mid+ is a String, it is recommended to freeze the string before
128
+ # calling this method to avoid wasting memory on hash keys. Likewise
129
+ # is true for any String objects in +refs+.
130
+ def add(mid, refs, msg)
131
+ cur = @id_table[mid] ||= Msgthr::Container.new(mid)
132
+ cur.msg = msg
133
+ refs or return
134
+
135
+ # n.b. centralized messaging systems (e.g. forums) do not need
136
+ # multiple References:, only decentralized systems need it to
137
+ # tolerate missing messages
138
+ prev = nil
139
+ refs.each do |ref|
140
+ cont = @id_table[ref] ||= Msgthr::Container.new(ref)
141
+
142
+ # link refs together in order implied,
143
+ # but do not change existing links or loop
144
+ if prev && !cont.parent && !cont.has_descendent(prev)
145
+ prev.add_child(cont)
146
+ end
147
+ prev = cont
148
+ end
149
+
150
+ # set parent of this message to be the last element in refs
151
+ prev.add_child(cur) if prev
152
+ end
153
+ end
154
+
155
+ require_relative 'msgthr/container'
data/msgthr.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # Copyright (C) 2016 all contributors <msgthr-public@80x24.org>
2
+ # License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>
3
+
4
+ Gem::Specification.new do |s|
5
+ manifest = File.read('.manifest').split(/\n/)
6
+ s.name = %q{msgthr}
7
+ s.version = ENV['VERSION'] || '1.0.1'
8
+ s.authors = ['msgthr hackers']
9
+ s.summary = 'container-agnostic, non-recursive message threading'
10
+ s.description = File.read('README').split(/\n\n/)[1].strip
11
+ s.email = %q{msgthr-public@80x24.org}
12
+ s.homepage = 'https://80x24.org/msgthr/'
13
+ s.executables = []
14
+ s.files = manifest
15
+ s.licenses = 'GPL-2.0+'
16
+ s.required_ruby_version = '>= 1.9.3'
17
+ end
@@ -0,0 +1,36 @@
1
+ # Copyright (C) 2016 all contributors <msgthr-public@80x24.org>
2
+ # License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>
3
+ require 'test/unit'
4
+ require 'msgthr'
5
+
6
+ class TestMsgthr < Test::Unit::TestCase
7
+ def test_msgthr
8
+ thr = Msgthr.new
9
+ thr.add('a', %w(c b), 'abc')
10
+ thr.add('b', %w(c), 'B')
11
+ thr.add('c', nil, 'c')
12
+ thr.add('D', nil, 'D')
13
+ thr.add('d', %w(missing), 'd')
14
+ thr.thread!
15
+ rootset = thr.order! { |c| c.sort_by!(&:mid) }
16
+ assert_equal %w(D c missing), rootset.map(&:mid)
17
+ assert_equal 'D', rootset[0].msg
18
+ assert_equal %w(b), rootset[1].children.map(&:mid)
19
+ out = ''.b
20
+ thr.walk_thread do |level, container, index|
21
+ msg = container.msg
22
+ summary = msg ? msg : "[missing: <#{container.mid}>]"
23
+ indent = ' ' * level
24
+ out << sprintf("#{indent} % 3d. %s\n", index, summary)
25
+ end
26
+ exp = <<EOF.b
27
+ 0. D
28
+ 1. c
29
+ 0. B
30
+ 0. abc
31
+ 2. [missing: <missing>]
32
+ 0. d
33
+ EOF
34
+ assert_equal exp, out
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: msgthr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - msgthr hackers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Pure Ruby message threading based on the algorithm described by
15
+ JWZ in <https://www.jwz.org/doc/threading.html> and used in
16
+ countless mail and news readers; but with some features removed
17
+ and improved flexibility:
18
+ email: msgthr-public@80x24.org
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".document"
24
+ - ".gitignore"
25
+ - ".olddoc.yml"
26
+ - COPYING
27
+ - GNUmakefile
28
+ - README
29
+ - lib/msgthr.rb
30
+ - lib/msgthr/container.rb
31
+ - msgthr.gemspec
32
+ - test/test_msgthr.rb
33
+ homepage: https://80x24.org/msgthr/
34
+ licenses:
35
+ - GPL-2.0+
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.9.3
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.6.12
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: container-agnostic, non-recursive message threading
57
+ test_files: []