]> Pileus Git - ~andy/linux/blob - scripts/get_maintainer.pl
scripts/get_maintainer.pl: add --git-blame
[~andy/linux] / scripts / get_maintainer.pl
1 #!/usr/bin/perl -w
2 # (c) 2007, Joe Perches <joe@perches.com>
3 #           created from checkpatch.pl
4 #
5 # Print selected MAINTAINERS information for
6 # the files modified in a patch or for a file
7 #
8 # usage: perl scripts/get_maintainers.pl [OPTIONS] <patch>
9 #        perl scripts/get_maintainers.pl [OPTIONS] -f <file>
10 #
11 # Licensed under the terms of the GNU GPL License version 2
12
13 use strict;
14
15 my $P = $0;
16 my $V = '0.18beta2';
17
18 use Getopt::Long qw(:config no_auto_abbrev);
19
20 my $lk_path = "./";
21 my $email = 1;
22 my $email_usename = 1;
23 my $email_maintainer = 1;
24 my $email_list = 1;
25 my $email_subscriber_list = 0;
26 my $email_git = 1;
27 my $email_git_penguin_chiefs = 0;
28 my $email_git_min_signatures = 1;
29 my $email_git_max_maintainers = 5;
30 my $email_git_min_percent = 5;
31 my $email_git_since = "1-year-ago";
32 my $email_git_blame = 0;
33 my $output_multiline = 1;
34 my $output_separator = ", ";
35 my $scm = 0;
36 my $web = 0;
37 my $subsystem = 0;
38 my $status = 0;
39 my $from_filename = 0;
40 my $version = 0;
41 my $help = 0;
42
43 my $exit = 0;
44
45 my @penguin_chief = ();
46 push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org");
47 #Andrew wants in on most everything - 2009/01/14
48 #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org");
49
50 my @penguin_chief_names = ();
51 foreach my $chief (@penguin_chief) {
52     if ($chief =~ m/^(.*):(.*)/) {
53         my $chief_name = $1;
54         my $chief_addr = $2;
55         push(@penguin_chief_names, $chief_name);
56     }
57 }
58 my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)";
59
60 # rfc822 email address - preloaded methods go here.
61 my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
62 my $rfc822_char = '[\\000-\\377]';
63
64 if (!GetOptions(
65                 'email!' => \$email,
66                 'git!' => \$email_git,
67                 'git-chief-penguins!' => \$email_git_penguin_chiefs,
68                 'git-min-signatures=i' => \$email_git_min_signatures,
69                 'git-max-maintainers=i' => \$email_git_max_maintainers,
70                 'git-min-percent=i' => \$email_git_min_percent,
71                 'git-since=s' => \$email_git_since,
72                 'git-blame!' => \$email_git_blame,
73                 'm!' => \$email_maintainer,
74                 'n!' => \$email_usename,
75                 'l!' => \$email_list,
76                 's!' => \$email_subscriber_list,
77                 'multiline!' => \$output_multiline,
78                 'separator=s' => \$output_separator,
79                 'subsystem!' => \$subsystem,
80                 'status!' => \$status,
81                 'scm!' => \$scm,
82                 'web!' => \$web,
83                 'f|file' => \$from_filename,
84                 'v|version' => \$version,
85                 'h|help' => \$help,
86                 )) {
87     usage();
88     die "$P: invalid argument\n";
89 }
90
91 if ($help != 0) {
92     usage();
93     exit 0;
94 }
95
96 if ($version != 0) {
97     print("${P} ${V}\n");
98     exit 0;
99 }
100
101 if ($#ARGV < 0) {
102     usage();
103     die "$P: argument missing: patchfile or -f file please\n";
104 }
105
106 my $selections = $email + $scm + $status + $subsystem + $web;
107 if ($selections == 0) {
108     usage();
109     die "$P:  Missing required option: email, scm, status, subsystem or web\n";
110 }
111
112 if ($email &&
113     ($email_maintainer + $email_list + $email_subscriber_list +
114      $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
115     usage();
116     die "$P: Please select at least 1 email option\n";
117 }
118
119 if (!top_of_kernel_tree($lk_path)) {
120     die "$P: The current directory does not appear to be "
121         . "a linux kernel source tree.\n";
122 }
123
124 ## Read MAINTAINERS for type/value pairs
125
126 my @typevalue = ();
127 open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
128 while (<MAINT>) {
129     my $line = $_;
130
131     if ($line =~ m/^(\C):\s*(.*)/) {
132         my $type = $1;
133         my $value = $2;
134
135         ##Filename pattern matching
136         if ($type eq "F" || $type eq "X") {
137             $value =~ s@\.@\\\.@g;       ##Convert . to \.
138             $value =~ s/\*/\.\*/g;       ##Convert * to .*
139             $value =~ s/\?/\./g;         ##Convert ? to .
140             ##if pattern is a directory and it lacks a trailing slash, add one
141             if ((-d $value)) {
142                 $value =~ s@([^/])$@$1/@;
143             }
144         }
145         push(@typevalue, "$type:$value");
146     } elsif (!/^(\s)*$/) {
147         $line =~ s/\n$//g;
148         push(@typevalue, $line);
149     }
150 }
151 close(MAINT);
152
153 ## use the filenames on the command line or find the filenames in the patchfiles
154
155 my @files = ();
156 my @range = ();
157
158 foreach my $file (@ARGV) {
159     ##if $file is a directory and it lacks a trailing slash, add one
160     if ((-d $file)) {
161         $file =~ s@([^/])$@$1/@;
162     } elsif (!(-f $file)) {
163         die "$P: file '${file}' not found\n";
164     }
165     if ($from_filename) {
166         push(@files, $file);
167     } else {
168         my $file_cnt = @files;
169         my $lastfile;
170         open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
171         while (<PATCH>) {
172             if (m/^\+\+\+\s+(\S+)/) {
173                 my $filename = $1;
174                 $filename =~ s@^[^/]*/@@;
175                 $filename =~ s@\n@@;
176                 $lastfile = $filename;
177                 push(@files, $filename);
178             } elsif (m/^\@\@ -(\d+),(\d+)/) {
179                 if ($email_git_blame) {
180                     push(@range, "$lastfile:$1:$2");
181                 }
182             }
183         }
184         close(PATCH);
185         if ($file_cnt == @files) {
186             warn "$P: file '${file}' doesn't appear to be a patch.  "
187                 . "Add -f to options?\n";
188         }
189         @files = sort_and_uniq(@files);
190     }
191 }
192
193 my @email_to = ();
194 my @list_to = ();
195 my @scm = ();
196 my @web = ();
197 my @subsystem = ();
198 my @status = ();
199
200 # Find responsible parties
201
202 foreach my $file (@files) {
203
204 #Do not match excluded file patterns
205
206     my $exclude = 0;
207     foreach my $line (@typevalue) {
208         if ($line =~ m/^(\C):\s*(.*)/) {
209             my $type = $1;
210             my $value = $2;
211             if ($type eq 'X') {
212                 if (file_match_pattern($file, $value)) {
213                     $exclude = 1;
214                 }
215             }
216         }
217     }
218
219     if (!$exclude) {
220         my $tvi = 0;
221         foreach my $line (@typevalue) {
222             if ($line =~ m/^(\C):\s*(.*)/) {
223                 my $type = $1;
224                 my $value = $2;
225                 if ($type eq 'F') {
226                     if (file_match_pattern($file, $value)) {
227                         add_categories($tvi);
228                     }
229                 }
230             }
231             $tvi++;
232         }
233     }
234
235     if ($email && $email_git) {
236         recent_git_signoffs($file);
237     }
238
239     if ($email && $email_git_blame) {
240         git_assign_blame($file);
241     }
242 }
243
244 if ($email) {
245     foreach my $chief (@penguin_chief) {
246         if ($chief =~ m/^(.*):(.*)/) {
247             my $email_address;
248             if ($email_usename) {
249                 $email_address = format_email($1, $2);
250             } else {
251                 $email_address = $2;
252             }
253             if ($email_git_penguin_chiefs) {
254                 push(@email_to, $email_address);
255             } else {
256                 @email_to = grep(!/${email_address}/, @email_to);
257             }
258         }
259     }
260 }
261
262 if ($email || $email_list) {
263     my @to = ();
264     if ($email) {
265         @to = (@to, @email_to);
266     }
267     if ($email_list) {
268         @to = (@to, @list_to);
269     }
270     output(uniq(@to));
271 }
272
273 if ($scm) {
274     @scm = sort_and_uniq(@scm);
275     output(@scm);
276 }
277
278 if ($status) {
279     @status = sort_and_uniq(@status);
280     output(@status);
281 }
282
283 if ($subsystem) {
284     @subsystem = sort_and_uniq(@subsystem);
285     output(@subsystem);
286 }
287
288 if ($web) {
289     @web = sort_and_uniq(@web);
290     output(@web);
291 }
292
293 exit($exit);
294
295 sub file_match_pattern {
296     my ($file, $pattern) = @_;
297     if (substr($pattern, -1) eq "/") {
298         if ($file =~ m@^$pattern@) {
299             return 1;
300         }
301     } else {
302         if ($file =~ m@^$pattern@) {
303             my $s1 = ($file =~ tr@/@@);
304             my $s2 = ($pattern =~ tr@/@@);
305             if ($s1 == $s2) {
306                 return 1;
307             }
308         }
309     }
310     return 0;
311 }
312
313 sub usage {
314     print <<EOT;
315 usage: $P [options] patchfile
316        $P [options] -f file|directory
317 version: $V
318
319 MAINTAINER field selection options:
320   --email => print email address(es) if any
321     --git => include recent git \*-by: signers
322     --git-chief-penguins => include ${penguin_chiefs}
323     --git-min-signatures => number of signatures required (default: 1)
324     --git-max-maintainers => maximum maintainers to add (default: 5)
325     --git-min-percent => minimum percentage of commits required (default: 5)
326     --git-since => git history to use (default: 1-year-ago)
327     --git-blame => use git blame to find modified commits for patch or file
328     --m => include maintainer(s) if any
329     --n => include name 'Full Name <addr\@domain.tld>'
330     --l => include list(s) if any
331     --s => include subscriber only list(s) if any
332   --scm => print SCM tree(s) if any
333   --status => print status if any
334   --subsystem => print subsystem name if any
335   --web => print website(s) if any
336
337 Output type options:
338   --separator [, ] => separator for multiple entries on 1 line
339   --multiline => print 1 entry per line
340
341 Default options:
342   [--email --git --m --n --l --multiline]
343
344 Other options:
345   --version => show version
346   --help => show this help information
347
348 Notes:
349   Using "-f directory" may give unexpected results:
350       Used with "--git", git signators for _all_ files in and below
351           directory are examined as git recurses directories.
352           Any specified X: (exclude) pattern matches are _not_ ignored.
353       Used with "--nogit", directory is used as a pattern match,
354          no individual file within the directory or subdirectory
355          is matched.
356       Used with "--git-blame", does not iterate all files in directory
357   Using "--git-blame" is slow and may add old committers and authors
358       that are no longer active maintainers to the output.
359 EOT
360 }
361
362 sub top_of_kernel_tree {
363         my ($lk_path) = @_;
364
365         if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
366             $lk_path .= "/";
367         }
368         if (   (-f "${lk_path}COPYING")
369             && (-f "${lk_path}CREDITS")
370             && (-f "${lk_path}Kbuild")
371             && (-f "${lk_path}MAINTAINERS")
372             && (-f "${lk_path}Makefile")
373             && (-f "${lk_path}README")
374             && (-d "${lk_path}Documentation")
375             && (-d "${lk_path}arch")
376             && (-d "${lk_path}include")
377             && (-d "${lk_path}drivers")
378             && (-d "${lk_path}fs")
379             && (-d "${lk_path}init")
380             && (-d "${lk_path}ipc")
381             && (-d "${lk_path}kernel")
382             && (-d "${lk_path}lib")
383             && (-d "${lk_path}scripts")) {
384                 return 1;
385         }
386         return 0;
387 }
388
389 sub format_email {
390     my ($name, $email) = @_;
391
392     $name =~ s/^\s+|\s+$//g;
393     $name =~ s/^\"|\"$//g;
394     $email =~ s/^\s+|\s+$//g;
395
396     my $formatted_email = "";
397
398     if ($name =~ /[^a-z0-9 \.\-]/i) {    ##has "must quote" chars
399         $name =~ s/(?<!\\)"/\\"/g;       ##escape quotes
400         $formatted_email = "\"${name}\"\ \<${email}\>";
401     } else {
402         $formatted_email = "${name} \<${email}\>";
403     }
404     return $formatted_email;
405 }
406
407 sub add_categories {
408     my ($index) = @_;
409
410     $index = $index - 1;
411     while ($index >= 0) {
412         my $tv = $typevalue[$index];
413         if ($tv =~ m/^(\C):\s*(.*)/) {
414             my $ptype = $1;
415             my $pvalue = $2;
416             if ($ptype eq "L") {
417                 my $list_address = $pvalue;
418                 my $list_additional = "";
419                 if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
420                     $list_address = $1;
421                     $list_additional = $2;
422                 }
423                 if ($list_additional =~ m/subscribers-only/) {
424                     if ($email_subscriber_list) {
425                         push(@list_to, $list_address);
426                     }
427                 } else {
428                     if ($email_list) {
429                         push(@list_to, $list_address);
430                     }
431                 }
432             } elsif ($ptype eq "M") {
433                 my $p_used = 0;
434                 if ($index >= 0) {
435                     my $tv = $typevalue[$index - 1];
436                     if ($tv =~ m/^(\C):\s*(.*)/) {
437                         if ($1 eq "P") {
438                             if ($email_usename) {
439                                 push_email_address(format_email($2, $pvalue));
440                                 $p_used = 1;
441                             }
442                         }
443                     }
444                 }
445                 if (!$p_used) {
446                     push_email_addresses($pvalue);
447                 }
448             } elsif ($ptype eq "T") {
449                 push(@scm, $pvalue);
450             } elsif ($ptype eq "W") {
451                 push(@web, $pvalue);
452             } elsif ($ptype eq "S") {
453                 push(@status, $pvalue);
454             }
455
456             $index--;
457         } else {
458             push(@subsystem,$tv);
459             $index = -1;
460         }
461     }
462 }
463
464 sub push_email_address {
465     my ($email_address) = @_;
466
467     my $email_name = "";
468
469     if ($email_maintainer) {
470         if ($email_address =~ m/([^<]+)<(.*\@.*)>$/) {
471             $email_name = $1;
472             $email_address = $2;
473             if ($email_usename) {
474                 push(@email_to, format_email($email_name, $email_address));
475             } else {
476                 push(@email_to, $email_address);
477             }
478         } elsif ($email_address =~ m/<(.+)>/) {
479             $email_address = $1;
480             push(@email_to, $email_address);
481         } else {
482             push(@email_to, $email_address);
483         }
484     }
485 }
486
487 sub push_email_addresses {
488     my ($address) = @_;
489
490     my @address_list = ();
491
492     if (rfc822_valid($address)) {
493         push_email_address($address);
494     } elsif (@address_list = rfc822_validlist($address)) {
495         my $array_count = shift(@address_list);
496         while (my $entry = shift(@address_list)) {
497             push_email_address($entry);
498         }
499     } else {
500         warn("Invalid MAINTAINERS address: '" . $address . "'\n");
501     }
502 }
503
504 sub which {
505     my ($bin) = @_;
506
507     foreach my $path (split(/:/, $ENV{PATH})) {
508         if (-e "$path/$bin") {
509             return "$path/$bin";
510         }
511     }
512
513     return "";
514 }
515
516 sub recent_git_signoffs {
517     my ($file) = @_;
518
519     my $sign_offs = "";
520     my $cmd = "";
521     my $output = "";
522     my $count = 0;
523     my @lines = ();
524     my $total_sign_offs;
525
526     if (which("git") eq "") {
527         warn("$P: git not found.  Add --nogit to options?\n");
528         return;
529     }
530     if (!(-d ".git")) {
531         warn("$P: .git directory not found.  Use a git repository for better results.\n");
532         warn("$P: perhaps 'git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git'\n");
533         return;
534     }
535
536     $cmd = "git log --since=${email_git_since} -- ${file}";
537     $cmd .= " | grep -Ei \"^[-_         a-z]+by:.*\\\@.*\$\"";
538     if (!$email_git_penguin_chiefs) {
539         $cmd .= " | grep -Ev \"${penguin_chiefs}\"";
540     }
541     $cmd .= " | cut -f2- -d\":\"";
542     $cmd .= " | sort | uniq -c | sort -rn";
543
544     $output = `${cmd}`;
545     $output =~ s/^\s*//gm;
546
547     @lines = split("\n", $output);
548
549     $total_sign_offs = 0;
550     foreach my $line (@lines) {
551         if ($line =~ m/([0-9]+)\s+(.*)/) {
552             $total_sign_offs += $1;
553         } else {
554             die("$P: Unexpected git output: ${line}\n");
555         }
556     }
557
558     foreach my $line (@lines) {
559         if ($line =~ m/([0-9]+)\s+(.*)/) {
560             my $sign_offs = $1;
561             $line = $2;
562             $count++;
563             if ($sign_offs < $email_git_min_signatures ||
564                 $count > $email_git_max_maintainers ||
565                 $sign_offs * 100 / $total_sign_offs < $email_git_min_percent) {
566                 last;
567             }
568         }
569         push_email_address($line);
570     }
571 }
572
573 sub save_commits {
574     my ($cmd, @commits) = @_;
575     my $output;
576     my @lines = ();
577
578     $output = `${cmd}`;
579
580     @lines = split("\n", $output);
581     foreach my $line (@lines) {
582         if ($line =~ m/^(\w+) /) {
583             push (@commits, $1);
584         }
585     }
586     return @commits;
587 }
588
589 sub git_assign_blame {
590     my ($file) = @_;
591
592     my @lines = ();
593     my @commits = ();
594     my $cmd;
595     my $output;
596     my %hash;
597     my $total_sign_offs;
598     my $count;
599
600     if (@range) {
601         foreach my $file_range_diff (@range) {
602             next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
603             my $diff_file = $1;
604             my $diff_start = $2;
605             my $diff_length = $3;
606             next if (!("$file" eq "$diff_file"));
607             $cmd = "git blame -l -L $diff_start,+$diff_length $file\n";
608             @commits = save_commits($cmd, @commits);
609         }
610     } else {
611         if (-f $file) {
612             $cmd = "git blame -l $file\n";
613             @commits = save_commits($cmd, @commits);
614         }
615     }
616
617     $total_sign_offs = 0;
618     @commits = uniq(@commits);
619     foreach my $commit (@commits) {
620         $cmd = "git log -1 ${commit}";
621         $cmd .= " | grep -Ei \"^[-_     a-z]+by:.*\\\@.*\$\"";
622         if (!$email_git_penguin_chiefs) {
623             $cmd .= " | grep -Ev \"${penguin_chiefs}\"";
624         }
625         $cmd .= " | cut -f2- -d\":\"";
626
627         $output = `${cmd}`;
628         $output =~ s/^\s*//gm;
629         @lines = split("\n", $output);
630         $hash{$_}++ for @lines;
631         $total_sign_offs += @lines;
632     }
633
634     $count = 0;
635     foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
636         my $sign_offs = $hash{$line};
637         $count++;
638         last if ($sign_offs < $email_git_min_signatures ||
639                  $count > $email_git_max_maintainers ||
640                  $sign_offs * 100 / $total_sign_offs < $email_git_min_percent);
641         push_email_address($line);
642     }
643 }
644
645 sub uniq {
646     my @parms = @_;
647
648     my %saw;
649     @parms = grep(!$saw{$_}++, @parms);
650     return @parms;
651 }
652
653 sub sort_and_uniq {
654     my @parms = @_;
655
656     my %saw;
657     @parms = sort @parms;
658     @parms = grep(!$saw{$_}++, @parms);
659     return @parms;
660 }
661
662 sub output {
663     my @parms = @_;
664
665     if ($output_multiline) {
666         foreach my $line (@parms) {
667             print("${line}\n");
668         }
669     } else {
670         print(join($output_separator, @parms));
671         print("\n");
672     }
673 }
674
675 my $rfc822re;
676
677 sub make_rfc822re {
678 #   Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
679 #   comment.  We must allow for rfc822_lwsp (or comments) after each of these.
680 #   This regexp will only work on addresses which have had comments stripped
681 #   and replaced with rfc822_lwsp.
682
683     my $specials = '()<>@,;:\\\\".\\[\\]';
684     my $controls = '\\000-\\037\\177';
685
686     my $dtext = "[^\\[\\]\\r\\\\]";
687     my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*";
688
689     my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*";
690
691 #   Use zero-width assertion to spot the limit of an atom.  A simple
692 #   $rfc822_lwsp* causes the regexp engine to hang occasionally.
693     my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))";
694     my $word = "(?:$atom|$quoted_string)";
695     my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*";
696
697     my $sub_domain = "(?:$atom|$domain_literal)";
698     my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*";
699
700     my $addr_spec = "$localpart\@$rfc822_lwsp*$domain";
701
702     my $phrase = "$word*";
703     my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)";
704     my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*";
705     my $mailbox = "(?:$addr_spec|$phrase$route_addr)";
706
707     my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
708     my $address = "(?:$mailbox|$group)";
709
710     return "$rfc822_lwsp*$address";
711 }
712
713 sub rfc822_strip_comments {
714     my $s = shift;
715 #   Recursively remove comments, and replace with a single space.  The simpler
716 #   regexps in the Email Addressing FAQ are imperfect - they will miss escaped
717 #   chars in atoms, for example.
718
719     while ($s =~ s/^((?:[^"\\]|\\.)*
720                     (?:"(?:[^"\\]|\\.)*"(?:[^"\\]|\\.)*)*)
721                     \((?:[^()\\]|\\.)*\)/$1 /osx) {}
722     return $s;
723 }
724
725 #   valid: returns true if the parameter is an RFC822 valid address
726 #
727 sub rfc822_valid ($) {
728     my $s = rfc822_strip_comments(shift);
729
730     if (!$rfc822re) {
731         $rfc822re = make_rfc822re();
732     }
733
734     return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/;
735 }
736
737 #   validlist: In scalar context, returns true if the parameter is an RFC822
738 #              valid list of addresses.
739 #
740 #              In list context, returns an empty list on failure (an invalid
741 #              address was found); otherwise a list whose first element is the
742 #              number of addresses found and whose remaining elements are the
743 #              addresses.  This is needed to disambiguate failure (invalid)
744 #              from success with no addresses found, because an empty string is
745 #              a valid list.
746
747 sub rfc822_validlist ($) {
748     my $s = rfc822_strip_comments(shift);
749
750     if (!$rfc822re) {
751         $rfc822re = make_rfc822re();
752     }
753     # * null list items are valid according to the RFC
754     # * the '1' business is to aid in distinguishing failure from no results
755
756     my @r;
757     if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so &&
758         $s =~ m/^$rfc822_char*$/) {
759         while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) {
760             push @r, $1;
761         }
762         return wantarray ? (scalar(@r), @r) : 1;
763     }
764     else {
765         return wantarray ? () : 0;
766     }
767 }