ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/ipo.ext
(Generate patch)

Comparing deliantra/maps/perl/ipo.ext (file contents):
Revision 1.2 by elmex, Mon Jul 24 18:10:12 2006 UTC vs.
Revision 1.3 by elmex, Mon Jul 24 19:51:43 2006 UTC

246 } 246 }
247 1 247 1
248}; 248};
249 249
250package CFMail; 250package CFMail;
251use YAML qw/LoadFile DumpFile Dump/;
252use POSIX qw/strftime/; 251use POSIX qw/strftime/;
253 252
253require YAMLDB;
254my $maildb_file = cf::localdir . "/crossfiremail.perl"; 254my $MAILDB = YAMLDB->new (db_file => cf::localdir . "/crossfiremail.perl");
255my $last_check = (-M $maildb_file) + 1;
256my $MAILDB;
257
258sub check_maildb {
259 if ($last_check > (-M $maildb_file)) {
260 $last_check = -M $maildb_file;
261
262 my $maildb = eval { my $m = LoadFile ($maildb_file); return $m };
263 if ($@) {
264 warn "ERROR when reading mail database $maildb_file: $@\n";
265 $maildb_file = cf::localdir . "/crossfiremail.perl.after_load_failure";
266 } else {
267 $MAILDB = $maildb;
268 }
269 }
270}
271
272# This is not thread or multiprocess safe!
273# XXX: A second process will (of course) terribly damage the maildatabase
274# but i assume there wont be any second process.
275sub sync_maildb {
276 eval {
277 DumpFile ("$maildb_file.tmp", $MAILDB);
278 };
279 if ($@) {
280 warn "ERROR when writing mail database $maildb_file.tmp: $@\n";
281 } else {
282 rename "$maildb_file.tmp", $maildb_file;
283 $last_check = -M $maildb_file;
284 }
285}
286 255
287sub get_mail { 256sub get_mail {
288 my ($toname) = @_; 257 my ($toname) = @_;
289 check_maildb;
290 $MAILDB->{$toname}; 258 $MAILDB->get ($toname);
291} 259}
292 260
293sub clear_mail { 261sub clear_mail {
294 my ($toname) = @_; 262 my ($toname) = @_;
295 check_maildb; 263 $MAILDB->clear ($toname);
296 $MAILDB->{$toname} = [];
297 sync_maildb;
298} 264}
299 265
300sub store_mail { 266sub store_mail {
301 my ($type, $toname, $fromname, $message) = @_; 267 my ($type, $toname, $fromname, $message) = @_;
302 check_maildb; 268 my $mails = $MAILDB->get ($toname);
303 push @{$MAILDB->{$toname}}, [$type, $fromname, $message]; 269 push @$mails, [$type, $fromname, $message];
304 sync_maildb; 270 $MAILDB->set ($toname, $mails);
305} 271}
306 272
307sub send_mail { 273sub send_mail {
308 my ($type, $toname, $fromname, $message) = @_; 274 my ($type, $toname, $fromname, $message) = @_;
309 my $time = strftime ("%a, %d %b %Y %H:%M:%S CEST", localtime (time)); 275 my $time = strftime ("%a, %d %b %Y %H:%M:%S CEST", localtime (time));
310 my $msg = "From: $fromname\nTo: $toname\nDate: $time\n\n$message\n"; 276 my $msg = "From: $fromname\nTo: $toname\nDate: $time\n\n$message\n";
311 check_maildb; 277 store_mail ($type, $toname, $fromname, $msg);
312 push @{$MAILDB->{$toname}}, [$type, $fromname, $msg];
313 sync_maildb;
314} 278}
315
316check_maildb ();
317 279
3181; 2801;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines