Skip to content

Commit

Permalink
Shrink the <style> section a little when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jun 21, 2016
1 parent aa53562 commit 2271d56
Showing 1 changed file with 72 additions and 8 deletions.
80 changes: 72 additions & 8 deletions archive_imessage.pl
Expand Up @@ -213,11 +213,17 @@ sub load_attachment {
my %longnames = ();
my %shortnames = ();

# !!! FIXME: this should probably go in a hash or something.
my $outperson = undef;
my $outmsgid = undef;
my $outhandle_id = undef;
my $outid = undef;
my $outtimestamp = undef;
my $outhasfromme = 0;
my $outhasfromthem = 0;
my $outhasfromme_a = 0;
my $outhasfromme_sms = 0;
my $outhasfromme_sms_a = 0;
my $output_text = '';
my $output_html = '';
my @output_attachments = ();
Expand Down Expand Up @@ -313,7 +319,6 @@ sub flush_conversation {
font-size: 20px;
font-weight: normal;
}
section {
max-width: 450px;
margin: 50px auto;
Expand All @@ -324,11 +329,15 @@ sub flush_conversation {
margin-bottom: 10px;
line-height: 24px;
}
.clear {
clear: both;
}
EOF
;

# Don't output parts of the CSS we don't need to save a little space.
if ($outhasfromme) {
print TMPEMAIL <<EOF
.from-me {
position: relative;
padding: 10px 20px;
Expand All @@ -337,10 +346,6 @@ sub flush_conversation {
border-radius: 25px;
float: right;
}
.from-me a {
color: white;
background: #0B93F6;
}
.from-me:before {
content: "";
position: absolute;
Expand All @@ -364,16 +369,44 @@ sub flush_conversation {
border-bottom-left-radius: 10px;
transform: translate(-30px, -2px);
}
EOF
;
}

if ($outhasfromme_a) {
print TMPEMAIL <<EOF
.from-me a {
color: white;
background: #0B93F6;
}
EOF
;
}

if ($outhasfromme_sms) {
print TMPEMAIL <<EOF
.sms {
background: #04D74A;
}
.sms:before {
border-right: 20px solid #04D74A;
}
EOF
;
}

if ($outhasfromme_sms_a) {
print TMPEMAIL <<EOF
.sms a {
color: white;
background: #04D74A;
}
EOF
;
}

if ($outhasfromthem) {
print TMPEMAIL <<EOF
.from-them {
position: relative;
padding: 10px 20px;
Expand Down Expand Up @@ -405,6 +438,11 @@ sub flush_conversation {
border-bottom-right-radius: 10px;
transform: translate(-30px, -2px);
}
EOF
;
}

print TMPEMAIL <<EOF
</style></head><body><section>
$output_html</section></body></html>
Expand Down Expand Up @@ -916,6 +954,12 @@ sub talk_gap {
$lastdate = 0;
$lastday = '';

$outhasfromme = 0;
$outhasfromthem = 0;
$outhasfromme_a = 0;
$outhasfromme_sms = 0;
$outhasfromme_sms_a = 0;

$output_text = '';
$output_html = '';
@output_attachments = ();
Expand All @@ -935,6 +979,8 @@ sub talk_gap {
}
}

my $is_sms = (defined $service) && ($service eq 'SMS');

# UTF-8 for non-breaking space (&nbsp;). Dump it at end of line; iMessage seems to add it occasionally (maybe double-space to add a period then hit Send?).
$text =~ s/\xC2\xA0\Z//;

Expand All @@ -954,7 +1000,25 @@ sub talk_gap {
$htmltext = "<b>$htmltext</b>";
}

$htmltext =~ s/($RE{URI})/<a href="$1">$1<\/a>/g;
if ($is_from_me) {
if ($is_sms) {
$outhasfromme_sms = 1;
} else {
$outhasfromme = 1;
}
} else {
$outhasfromthem = 1;
}

if ($htmltext =~ s/($RE{URI})/<a href="$1">$1<\/a>/g) {
if ($is_from_me) {
if ($is_sms) {
$outhasfromme_sms_a = 1;
} else {
$outhasfromme_a = 1;
}
}
}

if ($cache_has_attachments) {
$attachmentstmt->execute($msgid) or fail("Couldn't execute attachment lookup SELECT statement: " . $DBI::errstr);
Expand Down Expand Up @@ -1032,7 +1096,7 @@ sub talk_gap {
if ($allow_html) {
my $htmlfromclass;
if ($is_from_me) {
$htmlfromclass = ($service ne 'SMS') ? 'from-me' : 'from-me sms';
$htmlfromclass = $is_sms ? 'from-me sms' : 'from-me';
} else {
$htmlfromclass = 'from-them';
}
Expand Down

0 comments on commit 2271d56

Please sign in to comment.