[Rt-commit] r4469 - in Data-ICal: . lib/Data/ICal t
glasser at bestpractical.com
glasser at bestpractical.com
Fri Feb 3 12:52:22 EST 2006
Author: glasser
Date: Fri Feb 3 12:52:22 2006
New Revision: 4469
Added:
Data-ICal/t/10.mime-vcal10.t
Modified:
Data-ICal/ (props changed)
Data-ICal/lib/Data/ICal.pm
Data-ICal/lib/Data/ICal/Property.pm
Data-ICal/t/05.prop-params.t
Data-ICal/t/09.mime.t
Log:
r53606 at david-glassers-powerbook-g4-15: glasser | 2006-02-03 12:48:15 -0500
Checkpoint on equals-based folding (10.mime-vcal10 doesn't pass yet)
Modified: Data-ICal/lib/Data/ICal.pm
==============================================================================
--- Data-ICal/lib/Data/ICal.pm (original)
+++ Data-ICal/lib/Data/ICal.pm Fri Feb 3 12:52:22 2006
@@ -140,8 +140,11 @@
@lines = split /\n/, $args{data};
}
+ @lines = $self->_vcal10_input_cleanup(@lines) if $self->vcal10;
+
# Parse the lines; Text::vFile doesn't want trailing newlines
- my $cal = Text::vFile::asData->new->parse_lines(@lines);
+ my $cal = eval { Text::vFile::asData->new->parse_lines(@lines) };
+ return $self->_error("parse failure: $@") if $@;
return $self->_error("parse failure") unless $cal and exists $cal->{objects};
@@ -224,6 +227,40 @@
);
}
+
+# In quoted-printable sections, convert from vcal10 "=\n" line endings to
+# ical20 "\n ".
+sub _vcal10_input_cleanup {
+ my $self = shift;
+ my @in_lines = @_;
+
+ my @out_lines;
+
+ my $in_qp = 0;
+ LINE: while (@in_lines) {
+ my $line = shift @in_lines;
+
+ if (not $in_qp and $line =~ /^[^:]+;ENCODING=QUOTED-PRINTABLE/i) {
+ $in_qp = 1;
+ }
+
+ unless ($in_qp) {
+ push @out_lines, $line;
+ next LINE;
+ }
+
+ if ($line =~ s/=$//) {
+ push @out_lines, $line;
+ $in_lines[0] = ' ' . $in_lines[0] if @in_lines;
+ } else {
+ push @out_lines, $line;
+ $in_qp = 0;
+ }
+ }
+
+ return @out_lines;
+}
+
=head1 CONFIGURATION AND ENVIRONMENT
L<Data::ICal> requires no configuration files or environment variables.
Modified: Data-ICal/lib/Data/ICal/Property.pm
==============================================================================
--- Data-ICal/lib/Data/ICal/Property.pm (original)
+++ Data-ICal/lib/Data/ICal/Property.pm Fri Feb 3 12:52:22 2006
@@ -267,6 +267,8 @@
(Note that it folds at 75 characters, not 75 bytes as specified in the standard.)
+If this is vCalendar 1.0 and encoded with QUOTED-PRINTABLE, folds with = instead.
+
=end private
=cut
@@ -275,10 +277,19 @@
my $self = shift;
my $string = shift;
+ my $use_equals = $self->vcal10 &&
+ uc $self->parameters->{'ENCODING'} eq 'QUOTED-PRINTABLE';
+
+ my $replacement = $use_equals ? "=\n" : "\n ";
+
# We can't just use a s//g, because we need to include the added space and
# first character of the next line in the count for the next line.
+ #
+ # Note that while it tries to break up lines of 76 chars, it actually inserts
+ # the split after the 74th, not 75th, char, since otherwise it would be replacing
+ # the last char with an = in $use_equals mode which would not decrease its length.
while ( $string =~ /(.{76})/ ) {
- $string =~ s/(.{75})(.)/$1\n $2/;
+ $string =~ s/(.{74})(.)/$1$replacement$2/;
}
return $string;
}
Modified: Data-ICal/t/05.prop-params.t
==============================================================================
--- Data-ICal/t/05.prop-params.t (original)
+++ Data-ICal/t/05.prop-params.t Fri Feb 3 12:52:22 2006
@@ -19,8 +19,8 @@
is_string($todo->as_string, <<'END_VCAL', "Got the right output");
BEGIN:VTODO
-ATTENDEE;MEMBER="MAILTO:projectA at host.com","MAILTO:projectB at host.com":MAILT
- O:janedoe at host.com
+ATTENDEE;MEMBER="MAILTO:projectA at host.com","MAILTO:projectB at host.com":MAIL
+ TO:janedoe at host.com
SUMMARY;LANGUAGE=en-US;VALUE=TEXT:Sum it up.
END:VTODO
END_VCAL
Modified: Data-ICal/t/09.mime.t
==============================================================================
--- Data-ICal/t/09.mime.t (original)
+++ Data-ICal/t/09.mime.t Fri Feb 3 12:52:22 2006
@@ -12,8 +12,8 @@
PRODID:Data::ICal 0.07
VERSION:2.0
BEGIN:VTODO
-DESCRIPTION;ENCODING=QUOTED-PRINTABLE:interesting things =0D=0AYeah
- !!=3D cbla=0D=0A=0D=0A=0D=0AGo team syncml!=0D=0A=0D=0A=0D=0A
+DESCRIPTION;ENCODING=QUOTED-PRINTABLE:interesting things =0D=0AYea
+ h!!=3D cbla=0D=0A=0D=0A=0D=0AGo team syncml!=0D=0A=0D=0A=0D=0A
END:VTODO
END:VCALENDAR
END_VCAL
@@ -47,17 +47,3 @@
$cal->entries->[0]->property('description')->[0]->encode('QUotED-PRintabLE');
is_string($cal->as_string, $encoded_vcal);
-
-
-__END__
-possibly useful later
-DESCRIPTION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:interesting thi=
-ngs =0D=0A=
-Yeah!!=3D =C3=AAtre=0D=0A=
-=0D=0A=
-=0D=0A=
-Go team syncml!=0D=0A=
-=0D=0A=
-=0D=0A=
-END_DESC
-
Added: Data-ICal/t/10.mime-vcal10.t
==============================================================================
--- (empty file)
+++ Data-ICal/t/10.mime-vcal10.t Fri Feb 3 12:52:22 2006
@@ -0,0 +1,74 @@
+#!/usr/bin/perl -w
+
+use warnings;
+use strict;
+
+use Test::More tests => 7;
+use Test::LongString;
+use Test::NoWarnings;
+
+my $encoded_vcal = <<'END_VCAL';
+BEGIN:VCALENDAR
+PRODID:Data::ICal 0.07
+VERSION:1.0
+BEGIN:VTODO
+DESCRIPTION;ENCODING=QUOTED-PRINTABLE:interesting thi=
+ngs =0D=0A=
+Yeah!!=3D cbla=0D=0A=
+=0D=0A=
+=0D=0A=
+Go team syncml!=0D=0A=
+=0D=0A=
+=0D=0A=
+
+END:VTODO
+END:VCALENDAR
+END_VCAL
+
+my $decoded_desc = <<'END_DESC';
+interesting things
+Yeah!!= cbla
+
+
+Go team syncml!
+
+
+END_DESC
+
+BEGIN { use_ok('Data::ICal') }
+
+my $cal = Data::ICal->new(data => $encoded_vcal, vcal10 => 1);
+
+isa_ok($cal, 'Data::ICal');
+
+is_string($cal->entries->[0]->property("description")->[0]->decoded_value, $decoded_desc);
+
+$cal = Data::ICal->new;
+
+BEGIN { use_ok 'Data::ICal::Entry::Todo' }
+
+$cal = Data::ICal->new(vcal10 => 1);
+
+isa_ok($cal, 'Data::ICal');
+
+my $todo = Data::ICal::Entry::Todo->new;
+$cal->add_entry($todo);
+
+$todo->add_property(description => $decoded_desc);
+
+$cal->entries->[0]->property('description')->[0]->encode('QUotED-PRintabLE');
+is_string($cal->as_string, $encoded_vcal);
+
+
+__END__
+possibly useful later
+DESCRIPTION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:interesting thi=
+ngs =0D=0A=
+Yeah!!=3D =C3=AAtre=0D=0A=
+=0D=0A=
+=0D=0A=
+Go team syncml!=0D=0A=
+=0D=0A=
+=0D=0A=
+END_DESC
+
More information about the Rt-commit
mailing list