From jupp at gmx.de Fri Jan 14 09:50:57 2005 From: jupp at gmx.de (Josef 'Jupp' Schugt) Date: Fri Jan 14 16:35:58 2005 Subject: [Ruby-de-talk] Etwas gegen die Flaute: Freshmeat-Newsletter parsen In-Reply-To: <20040619111127.GA8678@miya.intranet.ntecs.de> References: <20040619111127.GA8678@miya.intranet.ntecs.de> Message-ID: <41E7DC51.2090906@gmx.de> Hi! Bei mir ist seit 2004-11-23 nichts mehr ?ber diese Liste angekommen. Andererseits wollte ich jetzt nicht die tausendunderste Testmail verschicken, um die Erreichbarkeit der Liste zu testen. Also habe ich mein neuestes Ruby-Machwerk angeh?ngt: Ein Programm, das den Freshmeat-Newsletter in einzelne Mails zerlegt. Ich rufe es mit dem folgenden procmail-Rezept auf: :0 c * ^From:.*freshmeat-news@lists.freshmeat.net * ^TOfreshmeat-news@freshmeat.net * ^Subject:.*[fm-news] |/home/jupp/bin/fm.rb Ob man es auch unter Windows nutzen kann wei? ich nicht, da ich schon seit Jahren nur noch Linux einsetze. Na ja, nicht ganz; ich habe einige Monate FreeBSD verwendet. Josef 'Jupp' Schugt -- The most severe crime in Germany is being on board of a plane that is hijacked. Separation of powers is bypassed, the only punishment for it is death, no legal proceedigs are necessary. It is the *only* crime for which germans may sentence you to death. Ask German DoD for details. -------------- next part -------------- #!/usr/bin/env ruby require 'net/smtp' require 'yaml' User = ENV['USER'].nil? ? ENV['LOGNAME'] : ENV['USER'] raise "User name unknown" if User.nil? class Array def extract_next_part! if /::: ([^(]*) (\(\d+\) )?:::/.match(first) title = $1.gsub(/ /, "-").delete(' ').downcase! shift data = '' data << shift << "\n\n" until first =~ /^:::/ or empty? data.gsub!(/^[-. ]+\n$/, '') [ title, data.strip.split(/- % - % - % - % -/).map{ |part| part.strip } ] else shift [ nil, nil ] end end end class String def to_msg(type) time = Time.now.to_f body, head, msgId, name, title = [ ], [ ], '', '', '' case type when 'articles' body = split(/\n\n/) title = 'Article: ' + /(.+)^by/m.match(body.first)[1].gsub(/\n/, ' ') name = /^URL: (http:\/\/freshmeat.net\/articles\/view\/(\d+)\/)/.match(self)[1] name = $2 body = [ body[1], $1 ] when 'release-details' about, changes, license, url = '', '', '', '', '' name = /^URL: http:\/\/freshmeat.net\/projects\/([^\\]+)\//.match(self)[1] split(/\n\n/).each_with_index { |part,i| case i when 1 head = part.split(/\n/).map { |cat| "X-Trove-Category: #{cat}" } head.push "X-Trove-Category: none provided" if head.empty? else case part when /^\[\d+\] - (.*)^ by/m then title = $1.gsub(/\n/, ' ') when /^About: (.*)/m then about = $1.gsub(/\n/, ' ') when /^Changes: (.*)/m then changes = $1.gsub(/\n/, ' ') when /^URL: (.*)/m then url = $1.gsub(/\n/, ' ') when /^License: (.*)/m then license = $1.gsub(/\n/, ' ') end end } body += [ about, url ] body += [ '', '*Changes*', '', changes ] unless changes.empty? body += [ '', '*License*', '', license ] unless license.empty? else return nil end msgId = "<#{time}-#{name}-#{type}-for-#{User}@freshmeat.net>" head.push "X-Freshmeat-Parser: fm.rb" head.push "From: #{User}@localhost" head.push "Message-Id: #{msgId}" unless msgId.empty? head.push "Subject: #{title}" unless title.empty? head.push "References: #{$refto[name]}" if $refto.include?(name) $refto[name] = msgId head.join("\n") + "\n\n" + body.join("\n") end end if File::exist?("#{ENV['HOME']}/.fm.yaml") $refto = YAML::load(File::open("#{ENV['HOME']}/.fm.yaml")) else $refto = Hash.new end msgPart = $stdin.readlines.join.split(/\n\n/)[1..-1] list = Hash.new until msgPart.empty? title, data = msgPart.extract_next_part! list[title] = data unless title.nil? end unless list['release-details'].nil? or list['release-details'].empty? fmSig = [ '_______________________________________________', 'The freshmeat daily newsletter', 'To unsubscribe, send email to freshmeat-news-request@lists.freshmeat.net', 'or visit http://lists.freshmeat.net/mailman/listinfo/freshmeat-news'] list['release-details'][-1].gsub!(Regexp.new(fmSig.join("\n")), '').strip! unless list['release-details'].empty? end Net::SMTP::start('localhost') { |smtp| list.each_pair { |type, value| next unless ['articles', 'release-details'].member?(type) next if value.nil? value.each { |body| smtp.ready("#{User}@localhost", "#{User}@localhost") { |msg| msg.write body.to_msg(type) } } } } File::open("#{ENV['HOME']}/.fm.yaml", 'w') { |f| f.puts $refto.to_yaml } From detlef.reichl at gmx.org Sun Jan 16 08:04:09 2005 From: detlef.reichl at gmx.org (Detlef Reichl) Date: Sun Jan 16 08:02:12 2005 Subject: [Ruby-de-talk] Bug in Digest::MD5 Message-ID: <1105880649.4512.4.camel@localhost.localdomain> Hallo, rubys MD5.hexdigest liefert andere Ergebnisse als der Shell-Befehl md5sum, obwohl nach meinem Verst?ndnis beide das gleiche tun sollten. Bug oder Verst?ndnisproblem? #!/usr/bin/ruby require 'digest/md5' p Digest::MD5.hexdigest('meinpasswort') system('echo meinpasswort | md5sum') gruss detlef From dblack at wobblini.net Sun Jan 16 08:54:04 2005 From: dblack at wobblini.net (David A. Black) Date: Sun Jan 16 08:51:38 2005 Subject: [Ruby-de-talk] Bug in Digest::MD5 In-Reply-To: <1105880649.4512.4.camel@localhost.localdomain> References: <1105880649.4512.4.camel@localhost.localdomain> Message-ID: Hi -- On Sun, 16 Jan 2005, Detlef Reichl wrote: > Hallo, > > rubys MD5.hexdigest liefert andere Ergebnisse als der Shell-Befehl > md5sum, obwohl nach meinem Verständnis beide das gleiche tun sollten. > Bug oder Verständnisproblem? > > #!/usr/bin/ruby > require 'digest/md5' > > p Digest::MD5.hexdigest('meinpasswort') > system('echo meinpasswort | md5sum') Ich glaube, es hat wie so oft der Fall ist mit "\n" zu tun: $ ruby -r 'digest/md5' -e 'p Digest::MD5.hexdigest("meinpasswort\n")' "121868f498263b6f93212708bd2a4009" David -- David A. Black dblack@wobblini.net From phil at philkern.de Sun Jan 16 10:33:30 2005 From: phil at philkern.de (Philipp Kern) Date: Sun Jan 16 10:31:12 2005 Subject: [Ruby-de-talk] Bug in Digest::MD5 In-Reply-To: <1105880649.4512.4.camel@localhost.localdomain> References: <1105880649.4512.4.camel@localhost.localdomain> Message-ID: On 16 Jan 2005, at 14:04, Detlef Reichl wrote: > p Digest::MD5.hexdigest('meinpasswort') > system('echo meinpasswort | md5sum') ``echo'' gibt dir ein \n am Ende der Zeile, sofern du es nicht mit -n aufrufst. furie:~ phil$ echo -n foo | md5sum acbd18db4cc2f85cedef654fccc4a4d8 - furie:~ phil$ ruby -e "require 'digest/md5'; puts Digest::MD5.hexdigest('foo')" acbd18db4cc2f85cedef654fccc4a4d8 Regards, Philipp Kern -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/ruby-de-talk/attachments/20050116/69eb114c/PGP.bin From chneukirchen at gmail.com Sun Jan 16 08:18:36 2005 From: chneukirchen at gmail.com (Christian Neukirchen) Date: Mon Jan 17 12:46:37 2005 Subject: [Ruby-de-talk] Bug in Digest::MD5 In-Reply-To: <1105880649.4512.4.camel@localhost.localdomain> (Detlef Reichl's message of "Sun, 16 Jan 2005 14:04:09 +0100") References: <1105880649.4512.4.camel@localhost.localdomain> Message-ID: Detlef Reichl writes: > Hallo, > > rubys MD5.hexdigest liefert andere Ergebnisse als der Shell-Befehl > md5sum, obwohl nach meinem Verst?ndnis beide das gleiche tun sollten. > Bug oder Verst?ndnisproblem? > > #!/usr/bin/ruby > require 'digest/md5' > > p Digest::MD5.hexdigest('meinpasswort') > system('echo meinpasswort | md5sum') system('echo -n meinpasswort | md5sum') Trailing newline. > gruss > detlef > > _______________________________________________ > Ruby-de-talk mailing list > Ruby-de-talk@rubyforge.org > http://rubyforge.org/mailman/listinfo/ruby-de-talk -- Christian Neukirchen http://kronavita.de/chris/