]> git.pld-linux.org Git - packages/cvsspam.git/commitdiff
- svn_cvsspam.rb updated from cvsspam.rb (merged 230:258)
authorElan Ruusamäe <glen@pld-linux.org>
Wed, 4 Mar 2009 22:04:23 +0000 (22:04 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    cvsspam-svnspam-branch.diff -> 1.3

cvsspam-svnspam-branch.diff

index 40d107c489dce6b96bb77a8659198bd8f27ae78a..afa2d69c4311c99622a252b13c0bb769a2d7e936 100644 (file)
@@ -1,14 +1,68 @@
 --- cvsspam-0.2.12/svn_cvsspam.rb      2005-07-11 18:53:29.000000000 +0300
-+++ cvsspam-svn/svn_cvsspam.rb 2008-08-07 17:27:52.632725455 +0300
-@@ -18,7 +18,7 @@
++++ cvsspam-svn/svn_cvsspam.rb 2009-03-04 23:47:04.364552847 +0200
+@@ -18,8 +18,9 @@
  # to your cvssppam.conf
  
  
 -$version = "0.2.11"
 +$version = "0.2.12"
  
++require 'time'
  
  $maxSubjectLength = 200
+ $maxLinesPerDiff = 1000
+@@ -35,10 +36,6 @@
+   a<b ? a : b
+ end
+-# NB must ensure the time is UTC
+-# (the Ruby Time object's strftime() doesn't supply a numeric timezone)
+-DATE_HEADER_FORMAT = "%a, %d %b %Y %H:%M:%S +0000"
+-
+ # Perform (possibly) multiple global substitutions on a string.
+ # the regexps given as keys must not use capturing subexpressions '(...)'
+ class MultiSub
+@@ -48,7 +45,7 @@
+     @mash = Array.new
+     expr = nil
+     hash.each do |key,val|
+-      if expr == nil ; expr="(" else expr<<"|(" end
++      if expr == nil ; expr="(" else expr << "|(" end
+       expr << key << ")"
+       @mash << val
+     end
+@@ -116,6 +113,8 @@
+   UNDERSCORE = chr("_")
+   SPACE = chr(" ")
+   TAB = chr("\t")
++  HOOK = chr("?")
++  EQUALS = chr("=")
+   # encode a header value according to the RFC-2047 quoted-printable spec,
+   # allowing non-ASCII characters to appear in header values, and wrapping
+@@ -137,8 +136,8 @@
+   # return a string representing the given character-code in quoted-printable
+   # format
+   def quoted_encode_char(b)
+-    if b>126 || b==UNDERSCORE || b==TAB
+-      sprintf("=%02x", b)
++    if b>126 || b==UNDERSCORE || b==TAB || b==HOOK || b==EQUALS
++      sprintf("=%02X", b)
+     elsif b == SPACE
+       "_"
+     else
+@@ -163,8 +162,9 @@
+   # gives a string starting "=?", and including a charset specification, that
+   # marks the start of a quoted-printable character sequence
+-  def marker_start_quoted
+-    "=?#{@charset}?#{@encoding}?"
++  def marker_start_quoted(charset=nil)
++    charset = @charset if charset.nil?
++    "=?#{charset}?#{@encoding}?"
+   end
+   # test to see of the given string contains non-ASCII characters
 @@ -339,8 +339,11 @@
  
    # gets the Repository object for the first component of the given path
  bugzillaSub = proc { |match|
    match =~ /([0-9]+)/
    "<a href=\"#{$bugzillaURL.sub(/%s/, $1)}\">#{match}</a>"
-@@ -541,9 +564,15 @@
+@@ -541,9 +564,31 @@
    match =~ /([0-9]+)/
    "<a href=\"#{$ticketURL.sub(/%s/, $1)}\">#{match}</a>"
  }
++issueSub = proc { |match|
++  match =~ /([0-9]+)/
++  "<a href=\"#{$issueURL.sub(/%s/, $1)}\">#{match}</a>"
++}
 +wikiSub = proc { |match| 
-+  match =~ /\[\[(.*)\]\]/
++  match =~ /\[\[(.*?)\]\]/
 +  raw = $1
 +  "<a href=\"#{$wikiURL.sub(/%s/, urlEncode(raw))}\">[[#{raw}]]</a>"
++}
++xplannerIterationSub = proc { |match|
++  match =~ /([0-9]+)/
++  "<a href=\"#{$xplannerIterationURL.sub(/%s/, $1)}\">#{match}</a>"
++}
++xplannerProjectSub = proc { |match|
++  match =~ /([0-9]+)/
++  "<a href=\"#{$xplannerProjectURL.sub(/%s/, $1)}\">#{match}</a>"
++}
++xplannerStorySub = proc { |match|
++  match =~ /([0-9]+)/
++  "<a href=\"#{$xplannerStoryURL.sub(/%s/, $1)}\">#{match}</a>"
 +}
  commentSubstitutions = {
                '(?:mailto:)?[\w\.\-\+\=]+\@[\w\-]+(?:\.[\w\-]+)+\b' => mailSub,
  
  # outputs commit log comment text supplied by LogReader as preformatted HTML
  class CommentHandler < LineConsumer
-@@ -661,6 +690,12 @@
+@@ -661,6 +706,12 @@
    def diff(file)
      '-&gt;'
    end
  end
  
  # Superclass for objects that can link to CVS frontends on the web (ViewCVS,
-@@ -701,6 +736,14 @@
+@@ -701,6 +752,14 @@
      "<a href=\"#{diff_url(file)}\">#{super(file)}</a>"
    end
  
   protected
    def add_repo(url)
      if @repository_name
-@@ -713,6 +756,10 @@
+@@ -713,6 +772,10 @@
        url
      end
    end
  end
  
  # Link to ViewCVS
-@@ -771,6 +818,17 @@
+@@ -736,6 +799,15 @@
+   def diff_url(file)
+     add_repo("#{@base_url}#{urlEncode(file.path)}.diff?r1=#{file.fromVer}&amp;r2=#{file.toVer}")
+   end
++
++  def log_url(file)
++    if file.toVer
++      log_anchor = "#rev#{file.toVer}"
++    else
++      log_anchor = ""
++    end
++    add_repo("#{@base_url}#{urlEncode(file.path)}#{log_anchor}")
++  end
+ end
+ # Link to Chora, from the Horde framework
+@@ -758,9 +830,9 @@
+ class CVSwebFrontend < WebFrontend
+   def path_url(path, tag)
+     if tag == nil
+-      add_repo(@base_url + urlEncode(path))
++      add_repo(@base_url + urlEncode(path) + "/")
+     else
+-      add_repo("#{@base_url}#{urlEncode(path)}?only_with_tag=#{urlEncode(tag)}")
++      add_repo("#{@base_url}#{urlEncode(path)}/?only_with_tag=#{urlEncode(tag)}")
+     end
+   end
+@@ -771,6 +843,17 @@
    def diff_url(file)
      add_repo("#{@base_url}#{urlEncode(file.path)}.diff?r1=text&amp;tr1=#{file.fromVer}&amp;r2=text&amp;tr2=#{file.toVer}&amp;f=h")
    end
  end
  
  
-@@ -792,6 +850,15 @@
+@@ -792,6 +875,15 @@
    end
  end
  
  # Note when LogReader finds record of a file that was modified in this commit
  class ModifiedFileHandler < FileHandler
    def handleFile(file)
-@@ -801,6 +868,15 @@
+@@ -801,6 +893,15 @@
    end
  end
  
  
  # Used by UnifiedDiffHandler to record the number of added and removed lines
  # appearing in a unidiff.
-@@ -967,11 +1043,21 @@
+@@ -949,7 +1050,7 @@
+     end
+     shift(nil)
+     if @truncatedLineCount>0
+-      println("<strong class=\"error\" title=\"#{@truncatedLineCount} lines truncated at column #{$maxDiffLineLength}\">[Note: Some over-long lines of diff output only partialy shown]</strong>")
++      println("<strong class=\"error\" title=\"#{@truncatedLineCount} lines truncated at column #{$maxDiffLineLength}\">[Note: Some over-long lines of diff output only partially shown]</strong>")
+     end
+   end
+@@ -967,11 +1068,21 @@
          print($frontend.path($file.basedir, $file.tag))
          println("</span><br />")
          println("<div class=\"fileheader\" id=\"removed\"><big><b>#{htmlEncode($file.file)}</b></big> <small id=\"info\">removed after #{$frontend.version($file.path,$file.fromVer)}</small></div>")
      end
      print("<pre class=\"diff\"><small id=\"info\">")
      lines.each do |line|
-@@ -1045,7 +1131,7 @@
+@@ -1045,7 +1156,7 @@
       else
        @stats.consume(line)
        if $file.wants_diff_in_mail?
            @colour.consume(line)
          elsif @stats.diffLines == $maxLinesPerDiff
            @colour.consume(line)
-@@ -1062,7 +1148,7 @@
+@@ -1062,7 +1173,7 @@
        $file.isBinary = true
      else
        if $file.wants_diff_in_mail?
            println("</pre>")
            println("<strong class=\"error\">[truncated at #{$maxLinesPerDiff} lines; #{@stats.diffLines-$maxLinesPerDiff} more skipped]</strong>")
          else
-@@ -1230,13 +1316,18 @@
+@@ -1172,7 +1283,7 @@
+ # an RFC 822 email address
+ class EmailAddress
+-  def initialize(text)
++  def initialize(text, charset=nil)
+     if text =~ /^\s*([^<]+?)\s*<\s*([^>]+?)\s*>\s*$/
+       @personal_name = $1
+       @address = $2
+@@ -1180,9 +1291,10 @@
+       @personal_name = nil
+       @address = text
+     end
++    @charset=charset
+   end
+-  attr_accessor :personal_name, :address
++  attr_accessor :personal_name, :address, :charset
+   def has_personal_name?
+     return !@personal_name.nil?
+@@ -1213,7 +1325,7 @@
+   # rfc2047 encode the word, if it contains non-ASCII characters
+   def encode_word(word)
+     if $encoder.requires_rfc2047?(word)
+-      encoded = $encoder.marker_start_quoted
++      encoded = $encoder.marker_start_quoted(@charset)
+       $encoder.each_char_encoded(word) do |code|
+       encoded << code
+       end
+@@ -1228,18 +1340,28 @@
+ cvsroot_dir = "#{ENV['CVSROOT']}/CVSROOT"
+ $config = "#{cvsroot_dir}/cvsspam.conf"
  $users_file = "#{cvsroot_dir}/users"
++$users_file_charset = nil
  
  $debug = false
 +$svn = false
 +$wikiURL = nil
  $jiraURL = nil
  $ticketURL = nil
++$issueURL = nil
  $viewcvsURL = nil
-@@ -1257,6 +1348,7 @@
++$xplannerIterationURL = nil
++$xplannerProjectURL = nil
++$xplannerStoryURL = nil
+ $choraURL = nil
+ $cvswebURL = nil
+ $from_address = nil
+@@ -1250,6 +1372,7 @@
+ # 2MiB limit on attached diffs,
+ $mail_size_limit = 1024 * 1024 * 2
+ $arg_charset = nil
++$cvsroot_email_header = false
+ require 'getoptlong'
+@@ -1257,6 +1380,7 @@
    [ "--to",     "-t", GetoptLong::REQUIRED_ARGUMENT ],
    [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ],
    [ "--debug",  "-d", GetoptLong::NO_ARGUMENT ],
    [ "--from",   "-u", GetoptLong::REQUIRED_ARGUMENT ],
    [ "--charset",      GetoptLong::REQUIRED_ARGUMENT ]
  )
-@@ -1265,6 +1357,7 @@
+@@ -1265,6 +1389,7 @@
    $recipients << EmailAddress.new(arg) if opt=="--to"
    $config = arg if opt=="--config"
    $debug = true if opt=="--debug"
    $from_address = EmailAddress.new(arg) if opt=="--from"
    # must use different variable as the config is readed later.
    $arg_charset = arg if opt == "--charset"
-@@ -1277,12 +1370,13 @@
+@@ -1277,12 +1402,13 @@
    else
      $stderr.puts "missing required file argument"
    end
  $additionalHeaders = Array.new
  $problemHeaders = Array.new
  
-@@ -1343,12 +1437,21 @@
+@@ -1341,7 +1467,13 @@
  if $bugzillaURL != nil
-   commentSubstitutions['\b[Bb][Uu][Gg]\s*#?[0-9]+'] = bugzillaSub
- end
+-  commentSubstitutions['\b[Bb][Uu][Gg]\s*#?[0-9]+'] = bugzillaSub
++  commentSubstitutions['\b[Bb](?:[Uu][Gg])?\s*[#:]?\s*\[?[0-9]+\]?'] = bugzillaSub
++end
 +if $gforgeBugURL != nil
 +  commentSubstitutions['\B\[#[0-9]+\]'] = gforgeBugSub
 +end
 +if $gforgeTaskURL != nil
 +  commentSubstitutions['\B\[[Tt][0-9]+\]'] = gforgeTaskSub
-+end
+ end
  if $jiraURL != nil
    commentSubstitutions['\b[a-zA-Z]+-[0-9]+\b'] = jiraSub
- end
+@@ -1349,6 +1481,21 @@
  if $ticketURL != nil
    commentSubstitutions['\b[Tt][Ii][Cc][Kk][Ee][Tt]\s*#?[0-9]+\b'] = ticketSub
  end
++if $issueURL != nil
++  commentSubstitutions['\b[Ii][Ss][Ss][Uu][Ee]\s*#?[0-9]+\b'] = issueSub
++end
 +if $wikiURL != nil
 +  commentSubstitutions['\[\[.+\]\]'] = wikiSub
++end
++if $xplannerIterationURL != nil
++  commentSubstitutions['\bXI\[?[0-9]+\]?'] = xplannerIterationSub
++end
++if $xplannerProjectURL != nil
++  commentSubstitutions['\bXP\[?[0-9]+\]?'] = xplannerProjectSub
++end
++if $xplannerStoryURL != nil
++  commentSubstitutions['\bXS\[?[0-9]+\]?'] = xplannerStorySub
 +end
  $commentEncoder = MultiSub.new(commentSubstitutions)
  
  
-@@ -1359,12 +1462,16 @@
+@@ -1359,12 +1506,16 @@
                 "T" => tagHandler,
                 "A" => AddedFileHandler.new,
                 "R" => RemovedFileHandler.new,
  
  $fileEntries = Array.new
  $task_list = Array.new
-@@ -1374,7 +1481,8 @@
+@@ -1374,7 +1525,8 @@
  
    $diff_output_limiter = OutputSizeLimiter.new(mail, $mail_size_limit)
  
  
      until reader.eof
        handler = $handlers[reader.currentLineCode]
-@@ -1383,11 +1491,16 @@
+@@ -1383,11 +1535,16 @@
        end
        handler.handleLines(reader.getLines, $diff_output_limiter)
      end
  end
  
  if $files_in_subject
-@@ -1434,13 +1547,15 @@
+@@ -1434,13 +1591,15 @@
    #removed {background-color:#ffdddd;}
    #removedchars {background-color:#ff9999;font-weight:bolder;}
    tr.alt #removed {background-color:#f7cccc;}
    .error {color:red;}
    hr {border-width:0px;height:2px;background:black;}
  --></style>
-@@ -1466,7 +1581,9 @@
+@@ -1466,7 +1625,9 @@
  
    filesAdded = 0
    filesRemoved = 0
    totalLinesAdded = 0
    totalLinesRemoved = 0
    file_count = 0
-@@ -1475,24 +1592,26 @@
+@@ -1475,24 +1636,26 @@
    $fileEntries.each do |file|
      unless file.repository == last_repository
        last_repository = file.repository
          end
        end
        mail.puts("</td></tr>")
-@@ -1507,8 +1626,12 @@
+@@ -1507,8 +1670,12 @@
        filesAdded += 1
      elsif file.removal?
        filesRemoved += 1
      end
      name = htmlEncode(file.name_after_common_prefix)
      slashPos = name.rindex("/")
-@@ -1528,17 +1651,29 @@
+@@ -1528,17 +1695,29 @@
        name = "<span id=\"added\">#{name}</span>"
      elsif file.removal?
        name = "<span id=\"removed\">#{name}</span>"
        if file.lineAdditions>0
          totalLinesAdded += file.lineAdditions
          mail.print("<td align=\"right\" id=\"added\">+#{file.lineAdditions}</td>")
-@@ -1565,15 +1700,19 @@
+@@ -1565,15 +1744,19 @@
        mail.print("<td nowrap=\"nowrap\" align=\"right\">added #{$frontend.version(file.path,file.toVer)}</td>")
      elsif file.removal?
        mail.print("<td nowrap=\"nowrap\">#{$frontend.version(file.path,file.fromVer)} removed</td>")
      if totalLinesAdded>0
        mail.print("<td align=\"right\" id=\"added\">+#{totalLinesAdded}</td>")
      else
-@@ -1590,7 +1729,7 @@
+@@ -1590,7 +1773,7 @@
    
    mail.puts("</table>")
  
    if totalFilesChanged > 1
      mail.print("<small id=\"info\">")
      changeKind = 0
-@@ -1603,11 +1742,21 @@
+@@ -1603,11 +1786,21 @@
        mail.print("#{filesRemoved} removed")
        changeKind += 1
      end
      mail.print(", total #{totalFilesChanged}") if changeKind > 1
      mail.puts(" files</small><br />")
    end
-@@ -1742,7 +1891,7 @@
+@@ -1655,7 +1848,7 @@
+       io.each_line do |line|
+         if line =~ /^([^:]+)\s*:\s*(['"]?)([^\n\r]+)(\2)/
+           if email.address == $1
+-            return EmailAddress.new($3)
++            return EmailAddress.new($3, $users_file_charset)
+           end
+         end
+       end
+@@ -1669,6 +1862,8 @@
+ # sensible header formatting, and for ensuring that the body is seperated
+ # from the message headers by a blank line (as it is required to be).
+ class MailContext
++  ENCODE_HEADERS = ["Subject", "X-CVSspam-Module-Path"]
++
+   def initialize(io)
+     @done_headers = false
+     @io = io
+@@ -1678,8 +1873,8 @@
+   # called
+   def header(name, value)
+     raise "headers already commited" if @done_headers
+-    if name == "Subject"
+-      $encoder.encode_header(@io, "Subject", value)
++    if ENCODE_HEADERS.include?(name)
++      $encoder.encode_header(@io, name, value)
+     else
+       @io.puts("#{name}: #{value}")
+     end
+@@ -1742,7 +1937,7 @@
        from = EmailAddress.new(ENV['USER'] || ENV['USERNAME'] || 'cvsspam')
      end  
      unless from.address =~ /@/
      end
      smtp = Net::SMTP.new(@smtp_host)
      blah("connecting to '#{@smtp_host}'")
-@@ -1758,6 +1907,40 @@
+@@ -1752,12 +1947,46 @@
+       ctx.header("To", recipients.map{|addr| addr.encoded}.join(','))
+       blah("Mail From: <#{from}>")
+       ctx.header("From", from.encoded) if from
+-      ctx.header("Date", Time.now.utc.strftime(DATE_HEADER_FORMAT))
++      ctx.header("Date", Time.now.rfc2822)
+       yield ctx
+     end
    end
  end
  
  if $smtp_host
    require 'net/smtp'
    mailer = SMTPMailer.new($smtp_host)
-@@ -1769,6 +1952,7 @@
+@@ -1769,6 +1998,7 @@
  
  mailer.send($from_address, $recipients) do |mail|
    mail.header("Subject", mailSubject)
    mail.header("MIME-Version", "1.0")
    mail.header("Content-Type", "text/html" + ($charset.nil? ? "" : "; charset=\"#{$charset}\""))
    if ENV['REMOTE_HOST']
+@@ -1782,6 +2012,14 @@
+     end
+   end
+   mail.header("X-Mailer", "CVSspam #{$version} <http://www.badgers-in-foil.co.uk/projects/cvsspam/>")
++  if $cvsroot_email_header
++    mod = '/'
++    if Repository.count == 1
++      rep = Repository.array.first
++      mod << rep.common_prefix
++    end
++    mail.header("X-CVSspam-Module-Path", mod)
++  end
+   mail.body do |body|
+     make_html_email(body)
+
 --- cvsspam-0.2.12/svn_post_commit_hook.rb     2005-07-11 18:53:29.000000000 +0300
 +++ cvsspam/cvsspam-svn/svn_post_commit_hook.rb        2008-08-07 17:27:52.628725224 +0300
 @@ -34,7 +34,7 @@
This page took 0.135619 seconds and 4 git commands to generate.