| 1 | package Palm::Mail; | ||||||||||||
| 2 | # | ||||||||||||
| 3 | # ABSTRACT: Handler for Palm OS Mail databases | ||||||||||||
| 4 | # | ||||||||||||
| 5 | # Copyright (C) 1999, 2000, Andrew Arensburger. | ||||||||||||
| 6 | # | ||||||||||||
| 7 | # This program is free software; you can redistribute it and/or modify | ||||||||||||
| 8 | # it under the same terms as Perl itself. | ||||||||||||
| 9 | # | ||||||||||||
| 10 | # This program is distributed in the hope that it will be useful, | ||||||||||||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the | ||||||||||||
| 13 | # GNU General Public License or the Artistic License for more details. | ||||||||||||
| 14 | |||||||||||||
| 15 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 3 | ▶ | use Palm::Raw(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 3 | ▶ | use Palm::StdAppInfo(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 3 | ▶ | use vars qw( $VERSION @ISA ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | # One liner, to allow MakeMaker to work. | ||||||||||||
| 21 | 3 | $VERSION = '1.400'; | |||||||||||
| 22 | # This file is part of Palm 1.400 (March 14, 2015) | ||||||||||||
| 23 | |||||||||||||
| 24 | 3 | @ISA = qw( Palm::StdAppInfo Palm::Raw ); | |||||||||||
| 25 | |||||||||||||
| 26 | #' | ||||||||||||
| 27 | |||||||||||||
| 28 | sub import | ||||||||||||
| 29 | 2 | ▶ | { | ||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | 2 | &Palm::PDB::RegisterPDBHandlers(__PACKAGE__, | |||||||||||
| 31 | [ "mail", "DATA" ], | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | #' | ||||||||||||
| 36 | |||||||||||||
| 37 | sub new | ||||||||||||
| 38 | 0 | ▶ | { | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 39 | 0 | my $classname = shift; | |||||||||||
| 40 | 0 | my $self = $classname->SUPER::new(@_); | |||||||||||
| 41 | # Create a generic PDB. No need to rebless it, | ||||||||||||
| 42 | # though. | ||||||||||||
| 43 | |||||||||||||
| 44 | 0 | $self->{name} = "MailDB"; # Default | |||||||||||
| 45 | 0 | $self->{creator} = "mail"; | |||||||||||
| 46 | 0 | $self->{type} = "DATA"; | |||||||||||
| 47 | 0 | $self->{attributes}{resource} = 0; | |||||||||||
| 48 | # The PDB is not a resource database by | ||||||||||||
| 49 | # default, but it's worth emphasizing, | ||||||||||||
| 50 | # since MailDB is explicitly not a PRC. | ||||||||||||
| 51 | |||||||||||||
| 52 | # Initialize the AppInfo block | ||||||||||||
| 53 | $self->{appinfo} = { | ||||||||||||
| 54 | 0 | sortOrder => undef, # XXX - ? | |||||||||||
| 55 | unsent => undef, # XXX - ? | ||||||||||||
| 56 | sigOffset => 0, # XXX - ? | ||||||||||||
| 57 | }; | ||||||||||||
| 58 | |||||||||||||
| 59 | # Add the standard AppInfo block stuff | ||||||||||||
| 60 | 0 | &Palm::StdAppInfo::seed_StdAppInfo($self->{appinfo}); | |||||||||||
| 61 | |||||||||||||
| 62 | 0 | $self->{sort} = undef; # Empty sort block | |||||||||||
| 63 | |||||||||||||
| 64 | 0 | $self->{records} = []; # Empty list of records | |||||||||||
| 65 | |||||||||||||
| 66 | 0 | return $self; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | |||||||||||||
| 70 | sub new_Record | ||||||||||||
| 71 | 0 | ▶ | { | ||||||||||
|
Subroutine
new_Record: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 72 | 0 | my $classname = shift; | |||||||||||
| 73 | 0 | my $retval = $classname->SUPER::new_Record(@_); | |||||||||||
| 74 | |||||||||||||
| 75 | # Set the date and time on this message to today and now. This | ||||||||||||
| 76 | # is arguably bogus, since the Date: header on a message ought | ||||||||||||
| 77 | # to represent the time when the message was sent, rather than | ||||||||||||
| 78 | # the time when the user started composing it, but this is | ||||||||||||
| 79 | # better than nothing. | ||||||||||||
| 80 | |||||||||||||
| 81 | ($retval->{year}, | ||||||||||||
| 82 | $retval->{month}, | ||||||||||||
| 83 | $retval->{day}, | ||||||||||||
| 84 | $retval->{hour}, | ||||||||||||
| 85 | 0 | $retval->{minute}) = (localtime(time))[5,4,3,2,1]; | |||||||||||
| 86 | |||||||||||||
| 87 | 0 | $retval->{is_read} = 0; # Message hasn't been read yet. | |||||||||||
| 88 | |||||||||||||
| 89 | # No delivery service notification (DSN) by default. | ||||||||||||
| 90 | 0 | $retval->{confirm_read} = 0; | |||||||||||
| 91 | 0 | $retval->{confirm_delivery} = 0; | |||||||||||
| 92 | |||||||||||||
| 93 | 0 | $retval->{priority} = 1; # Normal priority | |||||||||||
| 94 | |||||||||||||
| 95 | 0 | $retval->{addressing} = 0; # XXX - ? | |||||||||||
| 96 | |||||||||||||
| 97 | # All header fields empty by default. | ||||||||||||
| 98 | 0 | $retval->{from} = undef; | |||||||||||
| 99 | 0 | $retval->{to} = undef; | |||||||||||
| 100 | 0 | $retval->{cc} = undef; | |||||||||||
| 101 | 0 | $retval->{bcc} = undef; | |||||||||||
| 102 | 0 | $retval->{replyTo} = undef; | |||||||||||
| 103 | 0 | $retval->{sentTo} = undef; | |||||||||||
| 104 | |||||||||||||
| 105 | 0 | $retval->{body} = ""; | |||||||||||
| 106 | |||||||||||||
| 107 | 0 | return $retval; | |||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | # ParseAppInfoBlock | ||||||||||||
| 111 | # Parse the AppInfo block for Mail databases. | ||||||||||||
| 112 | sub ParseAppInfoBlock | ||||||||||||
| 113 | 1 | ▶ | { | ||||||||||
|
Subroutine
ParseAppInfoBlock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 114 | 1 | my $self = shift; | |||||||||||
| 115 | 1 | my $data = shift; | |||||||||||
| 116 | 1 | my $dirtyAppInfo; | |||||||||||
| 117 | my $sortOrder; | ||||||||||||
| 118 | 1 | my $unsent; | |||||||||||
| 119 | 1 | my $sigOffset; # XXX - Offset of signature? | |||||||||||
| 120 | 1 | my $appinfo = {}; | |||||||||||
| 121 | 1 | my $std_len; | |||||||||||
| 122 | |||||||||||||
| 123 | # Get the standard parts of the AppInfo block | ||||||||||||
| 124 | 1 | $std_len = &Palm::StdAppInfo::parse_StdAppInfo($appinfo, $data); | |||||||||||
| 125 | |||||||||||||
| 126 | 1 | $data = $appinfo->{other}; # Look at the non-category part | |||||||||||
| 127 | |||||||||||||
| 128 | # Get the rest of the AppInfo block | ||||||||||||
| 129 | 1 | my $unpackstr = # Argument to unpack() | |||||||||||
| 130 | "x2" . # Padding | ||||||||||||
| 131 | "n" . # Dirty AppInfo (what is this?) | ||||||||||||
| 132 | "Cx" . # Sort order | ||||||||||||
| 133 | "N" . # Unique ID of unsent message (what is this?) | ||||||||||||
| 134 | "n"; # Signature offset | ||||||||||||
| 135 | |||||||||||||
| 136 | 1 | ($dirtyAppInfo, $sortOrder, $unsent, $sigOffset) = | |||||||||||
| 137 | unpack $unpackstr, $data; | ||||||||||||
| 138 | |||||||||||||
| 139 | 1 | $appinfo->{dirty_AppInfo} = $dirtyAppInfo; | |||||||||||
| 140 | 1 | $appinfo->{sort_order} = $sortOrder; | |||||||||||
| 141 | 1 | $appinfo->{unsent} = $unsent; | |||||||||||
| 142 | 1 | $appinfo->{sig_offset} = $sigOffset; | |||||||||||
| 143 | |||||||||||||
| 144 | 1 | return $appinfo; | |||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | sub PackAppInfoBlock | ||||||||||||
| 148 | 0 | ▶ | { | ||||||||||
|
Subroutine
PackAppInfoBlock: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 149 | 0 | my $self = shift; | |||||||||||
| 150 | 0 | my $retval; | |||||||||||
| 151 | |||||||||||||
| 152 | # Pack the non-category part of the AppInfo block | ||||||||||||
| 153 | $self->{appinfo}{other} = pack "x2 n Cx N n", | ||||||||||||
| 154 | $self->{appinfo}{dirty_AppInfo}, | ||||||||||||
| 155 | $self->{appinfo}{sort_order}, | ||||||||||||
| 156 | $self->{appinfo}{unsent}, | ||||||||||||
| 157 | 0 | $self->{appinfo}{sig_offset}; | |||||||||||
| 158 | |||||||||||||
| 159 | # Pack the AppInfo block | ||||||||||||
| 160 | 0 | $retval = &Palm::StdAppInfo::pack_StdAppInfo($self->{appinfo}); | |||||||||||
| 161 | |||||||||||||
| 162 | 0 | return $retval; | |||||||||||
| 163 | } | ||||||||||||
| 164 | |||||||||||||
| 165 | sub ParseRecord | ||||||||||||
| 166 | 2 | ▶ | { | ||||||||||
|
Subroutine
ParseRecord: called CC=11 SCAR=25.3
Pod
documented
| |||||||||||||
| 167 | 2 | my $self = shift; | |||||||||||
| 168 | 2 | my %record = @_; | |||||||||||
| 169 | 2 | my $data = $record{data}; | |||||||||||
| 170 | |||||||||||||
| 171 | 2 | delete $record{offset}; # This is useless | |||||||||||
| 172 | 2 | delete $record{data}; | |||||||||||
| 173 | |||||||||||||
| 174 | 2 | my $date; | |||||||||||
| 175 | my $hour; | ||||||||||||
| 176 | 2 | my $minute; | |||||||||||
| 177 | 2 | my $flags; | |||||||||||
| 178 | 2 | my $subject; | |||||||||||
| 179 | 2 | my $from; | |||||||||||
| 180 | 2 | my $to; | |||||||||||
| 181 | 2 | my $cc; | |||||||||||
| 182 | 2 | my $bcc; | |||||||||||
| 183 | 2 | my $replyTo; | |||||||||||
| 184 | 2 | my $sentTo; | |||||||||||
| 185 | 2 | my $body; | |||||||||||
| 186 | 2 | my $extra; # Extra field after body. I don't know what | |||||||||||
| 187 | # it is. | ||||||||||||
| 188 | 2 | my $unpackstr = | |||||||||||
| 189 | "n" . # Date | ||||||||||||
| 190 | "C" . # Hour | ||||||||||||
| 191 | "C" . # Minute | ||||||||||||
| 192 | "n"; # Flags | ||||||||||||
| 193 | |||||||||||||
| 194 | 2 | ($date, $hour, $minute, $flags) = unpack $unpackstr, $data; | |||||||||||
| 195 | |||||||||||||
| 196 | 2 | my $year; | |||||||||||
| 197 | my $month; | ||||||||||||
| 198 | 2 | my $day; | |||||||||||
| 199 | |||||||||||||
| 200 | 2 | ▶ | if ($date != 0) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 201 | { | ||||||||||||
| 202 | 0 | $day = $date & 0x001f; # 5 bits | |||||||||||
| 203 | 0 | $month = ($date >> 5) & 0x000f; # 4 bits | |||||||||||
| 204 | 0 | $year = ($date >> 9) & 0x007f; # 7 bits (years since 1904) | |||||||||||
| 205 | 0 | $year += 1904; | |||||||||||
| 206 | |||||||||||||
| 207 | 0 | $record{year} = $year; | |||||||||||
| 208 | 0 | $record{month} = $month; | |||||||||||
| 209 | 0 | $record{day} = $day; | |||||||||||
| 210 | 0 | $record{hour} = $hour; | |||||||||||
| 211 | 0 | $record{minute} = $minute; | |||||||||||
| 212 | } | ||||||||||||
| 213 | |||||||||||||
| 214 | 2 | my $is_read = ($flags & 0x8000); | |||||||||||
| 215 | 2 | my $has_signature = ($flags & 0x4000); | |||||||||||
| 216 | 2 | my $confirm_read = ($flags & 0x2000); | |||||||||||
| 217 | 2 | my $confirm_delivery = ($flags & 0x1000); | |||||||||||
| 218 | 2 | my $priority = ($flags >> 10) & 0x03; | |||||||||||
| 219 | 2 | my $addressing = ($flags >> 8) & 0x03; | |||||||||||
| 220 | |||||||||||||
| 221 | # The signature is problematic: it's not stored in | ||||||||||||
| 222 | # "MailDB.pdb": it's actually in "Saved Preferences.pdb". Work | ||||||||||||
| 223 | # around this somehow; either read it from "Saved | ||||||||||||
| 224 | # Preferences.pdb" or, more simply, just read ~/.signature if | ||||||||||||
| 225 | # it exists. | ||||||||||||
| 226 | |||||||||||||
| 227 | 2 | ▶ | $record{is_read} = 1 if $is_read; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 228 | 2 | ▶ | $record{has_signature} = 1 if $has_signature; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 229 | 2 | ▶ | $record{confirm_read} = 1 if $confirm_read; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 230 | 2 | ▶ | $record{confirm_delivery} = 1 if $confirm_delivery; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 231 | 2 | $record{priority} = $priority; | |||||||||||
| 232 | 2 | $record{addressing} = $addressing; | |||||||||||
| 233 | |||||||||||||
| 234 | 2 | my $fields = substr $data, 6; | |||||||||||
| 235 | 2 | my @fields = split /\0/, $fields; | |||||||||||
| 236 | |||||||||||||
| 237 | 2 | ($subject, $from, $to, $cc, $bcc, $replyTo, $sentTo, $body, | |||||||||||
| 238 | $extra) = @fields; | ||||||||||||
| 239 | |||||||||||||
| 240 | # Clean things up a bit | ||||||||||||
| 241 | |||||||||||||
| 242 | # Multi-line values are bad in these headers. Replace newlines | ||||||||||||
| 243 | # with commas. Ideally, we'd use arrays for multiple | ||||||||||||
| 244 | # recipients, but that would involve parsing addresses, which | ||||||||||||
| 245 | # is non-trivial. Besides, most likely we'll just wind up | ||||||||||||
| 246 | # sending these strings as they are to 'sendmail', which is | ||||||||||||
| 247 | # better equipped to parse them. | ||||||||||||
| 248 | |||||||||||||
| 249 | 2 | ▶ | $to =~ s/\s*\n\s*(?!$)/, /gs if defined($to); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 250 | 2 | ▶ | $cc =~ s/\s*\n\s*(?!$)/, /gs if defined($cc); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 251 | 2 | ▶ | $bcc =~ s/\s*\n\s*(?!$)/, /gs if defined($bcc); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 252 | 2 | ▶ | $replyTo =~ s/\s*\n\s*(?!$)/, /gs if defined($replyTo); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 253 | 2 | ▶ | $sentTo =~ s/\s*\n\s*(?!$)/, /gs if defined($sentTo); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 254 | |||||||||||||
| 255 | 2 | $record{subject} = $subject; | |||||||||||
| 256 | 2 | $record{from} = $from; | |||||||||||
| 257 | 2 | $record{to} = $to; | |||||||||||
| 258 | 2 | $record{cc} = $cc; | |||||||||||
| 259 | 2 | $record{bcc} = $bcc; | |||||||||||
| 260 | 2 | $record{replyTo} = $replyTo; | |||||||||||
| 261 | 2 | $record{sentTo} = $sentTo; | |||||||||||
| 262 | 2 | $record{body} = $body; | |||||||||||
| 263 | 2 | $record{extra} = $extra; | |||||||||||
| 264 | |||||||||||||
| 265 | 2 | return \%record; | |||||||||||
| 266 | } | ||||||||||||
| 267 | |||||||||||||
| 268 | sub PackRecord | ||||||||||||
| 269 | 0 | ▶ | { | ||||||||||
|
Subroutine
PackRecord: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||
| 270 | 0 | my $self = shift; | |||||||||||
| 271 | 0 | my $record = shift; | |||||||||||
| 272 | 0 | my $retval; | |||||||||||
| 273 | my $rawDate; | ||||||||||||
| 274 | 0 | my $flags; | |||||||||||
| 275 | |||||||||||||
| 276 | $rawDate = ($record->{day} & 0x001f) | | ||||||||||||
| 277 | (($record->{month} & 0x000f) << 5) | | ||||||||||||
| 278 | 0 | ((($record->{year} - 1904) & 0x07f) << 9); | |||||||||||
| 279 | 0 | $flags = 0; | |||||||||||
| 280 | 0 | ▶ | $flags |= 0x8000 if $record->{is_read}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 281 | 0 | ▶ | $flags |= 0x4000 if $record->{has_signature}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 282 | 0 | ▶ | $flags |= 0x2000 if $record->{confirm_read}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 283 | 0 | ▶ | $flags |= 0x1000 if $record->{confirm_delivery}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 284 | 0 | $flags |= (($record->{priority} & 0x03) << 10); | |||||||||||
| 285 | 0 | $flags |= (($record->{addressing} & 0x03) << 8); | |||||||||||
| 286 | |||||||||||||
| 287 | $retval = pack "n C C n", | ||||||||||||
| 288 | $rawDate, | ||||||||||||
| 289 | $record->{hour}, | ||||||||||||
| 290 | $record->{minute}, | ||||||||||||
| 291 | 0 | $flags; | |||||||||||
| 292 | |||||||||||||
| 293 | # can't leave any of these undef or join() complains | ||||||||||||
| 294 | 0 | foreach (qw(subject from to cc bcc replyTo sentTo body) ) | |||||||||||
| 295 | { | ||||||||||||
| 296 | 0 | ▶ | $record->{$_} ||= ""; | ||||||||||
|
Condition0%0/2
$record->{$_} ||= ""
MC/DC0%0/1
$record->{$_} ||= ""
$record->{$_}
Truth table0%0/2
A
A= $record->{$_}
| |||||||||||||
| 297 | } | ||||||||||||
| 298 | |||||||||||||
| 299 | $retval .= join "\0", | ||||||||||||
| 300 | $record->{subject}, | ||||||||||||
| 301 | $record->{from}, | ||||||||||||
| 302 | $record->{to}, | ||||||||||||
| 303 | $record->{cc}, | ||||||||||||
| 304 | $record->{bcc}, | ||||||||||||
| 305 | $record->{replyTo}, | ||||||||||||
| 306 | $record->{sentTo}, | ||||||||||||
| 307 | 0 | $record->{body}; | |||||||||||
| 308 | 0 | $retval .= "\0"; | |||||||||||
| 309 | |||||||||||||
| 310 | 0 | return $retval; | |||||||||||
| 311 | } | ||||||||||||
| 312 | |||||||||||||
| 313 | 3 | 1; | |||||||||||
| 314 | |||||||||||||
| 315 | __END__ | ||||||||||||