#========================================================
# ALMail32
#========================================================
package ALMail32;
use Mail::MailFile;
@ISA = qw(MailFile);
use strict;
use Jcode;
use IniFile;
#============================================================
# 変数等取得関数
#============================================================
#============================================================
# 静的関数
#============================================================
#============================================================
# コンストラクタ、デストラクタ
#============================================================
BEGIN { }
sub new
{
my ($module) = @_;
my $this = {};
bless $this;
return $this;
}
sub DESTROY
{
my $this = shift;
}
#============================================================
# 一般関数
#============================================================
my $AccountDir;
sub SetAccountDir() { my ($this,$d)=@_; $AccountDir = $this->{AccountDir} = $d; }
sub GetAccountDir() {
my ($this) = @_;
$this->{AccountDir} = $AccountDir if($this->{AccountDir} eq '');
return $this->{AccountDir};
}
sub AccountDir() { my ($this)=@_; return $this->{AccountDir}; }
sub GetMailboxDir() {
my ($this) = @_;
my $AccountDir = $this->GetAccountDir();
# return $AccountDir;
my ($MailboxDir) = ($AccountDir =~ /^(.*[\/\\]Mailbox)/);
return $MailboxDir;
}
sub pFolders() { return shift->{pFolders}; }
sub nFolders() { return shift->{nFolders}; }
sub GetALMailFolderTitle
{
my ($this, $FolderPath, $IsPrint) = @_;
$IsPrint = 1 if(!defined $IsPrint);
# return '' if(!-d $FolderPath);
my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($FolderPath);
return ('郵便受け', 'Mailfolder') if($filename eq 'Inbox.box');
return ('送信箱', 'Mailfolder') if($filename eq 'Outbox.box');
my $IniPath = Utils::MakePath($FolderPath, "Entry.ini", '/', 0);
$IniPath = Utils::MakePath($FolderPath, "Account.ini", '/', 0) if(!-f $IniPath);
return ('', '') if(!-f $IniPath and !$IsPrint);
my $ini = new IniFile($IniPath);
my $title = $ini->GetString("Property", "Title", "");
Utils::DelQuote($title);
my $Type = $ini->GetString("Property", "Type", "");
if($filebody =~ /^Account/i) {
$Type = 'Rootfolder';
}
elsif($Type eq '') {
$Type = 'Mailfolder';
}
#print "type[$Type][$FolderPath][$filebody]
\n";
return ($title, $Type);
}
sub GetLSTFileHashByDir
{
my ($this, $dir) = @_;
my $f = Utils::MakePath($dir, 'Entry.lst', '/', 0);
#$App->print("f[$]\n");
return undef if(!-e $f);
my $in = new JFile($f, 'r');
return undef if(!$in);
my %hash;
while(1) {
my $line = $in->ReadLine();
last if(!$line);
my ($key, $code, $from, $subject) = ($line =~ /^(.*?)=(.{16})(.*?):\s*(.*)\s*$/);
$subject =~ s/::/:/g;
#$App->print("$key: $from: $subject\n");
$hash{$key} = {
key => $key,
code => $code,
from => $from,
subject => $subject,
};
}
$in->Close();
return \%hash;
}
sub GetFolderInf
{
my ($this, $i) = @_;
my $pInf = $this->pFolders()->[$i];
return $pInf;
}
sub GetFolderList
{
my ($this) = @_;
my $AccountDir = $this->AccountDir();
$this->{pFolders} = [];
$this->{nFolders} = 0;
$this->SearchFolders($AccountDir);
}
sub SearchFolders
{
my ($this, $ParentDir, $ParentFolder) = @_;
$ParentFolder = '' if(!defined $ParentFolder);
my $path = Deps::MakePath($ParentDir, "*.box", 0);
#print "path:$path\n";
my @dirs = glob($path);
for(my $i = 0 ; $i < @dirs ; $i++) {
my ($title, $type);
if($dirs[$i] =~ /[\\\/]Inbox.box$/i) {
$title = "郵便受け";
Jcode::convert(\$title, "sjis");
}
elsif($dirs[$i] =~ /[\\\/]Outbox.box$/i) {
$title = "送信箱";
}
elsif($dirs[$i] =~ /[\\\/]Trash.box$/i) {
$title = "ごみ箱";
}
else {
my $IniFile = Deps::MakePath($dirs[$i], "Entry.ini", 0);
my $ini = new IniFile($IniFile);
$title = $ini->GetString("Property", "Title", "");
Jcode::convert(\$title, "sjis");
$type = $ini->GetString("Property", "Type", "");
}
my $FullTitle = $title;
$FullTitle = "$ParentFolder::$title" if($ParentFolder);
#print "$this->{nFolders}: $dirs[$i]: [$FullTitle]: $type\n";
my %inf = (
iFolder => $this->{nFolders}-1,
Path => $dirs[$i],
Title => $title,
FullTitle => $FullTitle,
Type => $type
);
$this->{pFolders}->[$this->{nFolders}] = \%inf;
$this->{nFolders}++;
if($type eq 'Subfolder') {
my @Folders = $this->SearchFolders($dirs[$i]);
}
}
}
sub SearchFolderByTitle
{
my ($this, $title) = @_;
$title = uc $title;
my $nFolders = $this->nFolders();
for(my $i = 0 ; $i < $nFolders ; $i++) {
my $pInf = $this->GetFolderInf($i);
return $pInf if($title eq uc $pInf->{Title});
#print "$i: $pInf->{Title}: $pInf->{Path}: $pInf->{Type}\n";
}
return undef;
}
sub GetTrashboxHash
{
my ($this, $AccountDir) = @_;
$AccountDir = $this->GetAccountDir() if($AccountDir eq '');
my $TrashboxPath = Utils::MakePath($AccountDir, 'Trash.box', '/', 0);
#print "T[$TrashboxPath]
\n";
return {} if(!-f $TrashboxPath);
my $in = new JFile();
return if(!$in->Open($TrashboxPath, 'r'));
my %hash;
while(1) {
my $line = $in->ReadLine();
last if(!defined $line);
my ($path, $attr, $from, $subject) = ($line =~ /^(.*?)=(.{16})(.*?):(.*)$/);
my ($key) = ($path =~ /\\([^\\]+?)$/);
#print("p[$key][$path][$attr][$from][$subject]
\n");
$hash{$key} = {
key => $key,
path => $path,
attr => $attr,
from => $from,
subject => $subject,
};
}
$in->Close();
return \%hash
}
1;