Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.3 KiB

  1. package URI::mailto; # RFC 2368
  2. require URI;
  3. require URI::_query;
  4. @ISA=qw(URI URI::_query);
  5. use strict;
  6. sub to
  7. {
  8. my $self = shift;
  9. my @old = $self->headers;
  10. if (@_) {
  11. my @new = @old;
  12. # get rid of any other to: fields
  13. for (my $i = 0; $i < @new; $i += 2) {
  14. if (lc($new[$i]) eq "to") {
  15. splice(@new, $i, 2);
  16. redo;
  17. }
  18. }
  19. my $to = shift;
  20. $to = "" unless defined $to;
  21. unshift(@new, "to" => $to);
  22. $self->headers(@new);
  23. }
  24. return unless defined wantarray;
  25. my @to;
  26. while (@old) {
  27. my $h = shift @old;
  28. my $v = shift @old;
  29. push(@to, $v) if lc($h) eq "to";
  30. }
  31. join(",", @to);
  32. }
  33. sub headers
  34. {
  35. my $self = shift;
  36. # The trick is to just treat everything as the query string...
  37. my $opaque = "to=" . $self->opaque;
  38. $opaque =~ s/\?/&/;
  39. if (@_) {
  40. my @new = @_;
  41. # strip out any "to" fields
  42. my @to;
  43. for (my $i=0; $i < @new; $i += 2) {
  44. if (lc($new[$i]) eq "to") {
  45. push(@to, (splice(@new, $i, 2))[1]); # remove header
  46. redo;
  47. }
  48. }
  49. my $new = join(",",@to);
  50. $new =~ s/%/%25/g;
  51. $new =~ s/\?/%3F/g;
  52. $self->opaque($new);
  53. $self->query_form(@new) if @new;
  54. }
  55. return unless defined wantarray;
  56. # I am lazy today...
  57. URI->new("mailto:?$opaque")->query_form;
  58. }
  59. 1;