亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 6207 | 回復: 5
打印 上一主題 下一主題

perl 訪問操作 Lotus Notes [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-08-12 19:36 |只看該作者 |倒序瀏覽
公司OA系統(tǒng)使用的是 Lotus  Notes ,內(nèi)部往往多人使用一個郵箱,郵件管理混亂。計劃用 perl 做一個管理工具,查閱了一些資料,做些筆記,整理如下,供大家參考。

參考文章:http://www-12.lotus.com/ldd/doc/ ... 7687cb?OpenDocument

下面通過實例來具體說明如何訪問 Notes:

  1. # 使用 Win32::OLE 訪問 Lotus Notes
  2. # 只能在 windwos 下使用,并且需要啟動 Notes,正常登錄
  3. use Win32::OLE;
  4. use Data::Dumper;

  5. # 定義基本連接信息,需要同你的 Notes 場所里面定義一致。
  6. my $server = 'yourserver';
  7. my $database = 'yourmail';
  8. # 定義需要讀取的目錄,這里訪問收件箱
  9. my $folder= '($Inbox)';

  10. #創(chuàng)建 Notes Session
  11. my $Notes = Win32::OLE->new('Notes.NotesSession')
  12.     || warn "Cannot start Lotus Notes Session object: $!\n";

  13. # 登錄數(shù)據(jù)庫,如果你已經(jīng)使用 notes client 登錄,這一步可以不需要
  14. # 添加這一句,在沒有登錄時,可以彈出密碼輸入窗口
  15. $Notes->Initialize('yourpassword');

  16. # 以下演示一些常規(guī)獲取信息的方法
  17. printf "Lotus Notes 版本:%s\n",$Notes->{NotesVersion};
  18. printf "當前用戶 %s\n",$Notes->{UserName};
  19. printf "操作系統(tǒng) %s\n",$Notes->{Platform};

  20. # 連接數(shù)據(jù)庫
  21. my $Database = $Notes->GetDatabase($server, $database);

  22. # 查看當前有多少個視圖,這里只輸出目錄
  23. my $Views = $Database->{Views};
  24. foreach my $view(@$Views) {
  25.     printf "Folder --> %s \n" ,$view->{Name} if $view->IsFolder;
  26. }

  27. # 查看有多少個 form
  28. my $Forms = $Database->{Forms};
  29. foreach my $form(@$Forms) {
  30.     printf "Form --> %s \n" ,$form->{Name};
  31. }

  32. # 獲取所有文檔
  33. my $AllDocuments = $Database->AllDocuments;
  34. my $Count = $AllDocuments->Count;

  35. printf "數(shù)據(jù)庫中有 $Count 個文檔.\n";

  36. for (my $Index = 1 ; $Index <= $Count  ; $Index++ ) {
  37.     my $Document = $AllDocuments->GetNthDocument($Index);   
  38.    
  39.     printf "From: %s\n", $Document->GetFirstItem('From')->{Text}; # 發(fā)件人
  40.     printf "Send To: %s\n", $Document->GetFirstItem('SendTo')->{Text};    # 收件人
  41.     printf "CopyTo: %s\n", $Document->GetFirstItem('CopyTo')->{Text};  # 抄送
  42.     printf "$Index. %s\n", $Document->GetFirstItem('Subject')->{Text}; # 郵件標題
  43.    
  44.     printf "NoteID: %s\n", $Document->{'NoteID'}; # 郵件 NoteID,在同一數(shù)據(jù)庫中為唯一值
  45.     printf "UniversalID: %s\n", $Document->{'UniversalID'}; # 郵件 UUID,在不同數(shù)據(jù)庫間,也是唯一值
  46.     printf "Size: %s KB\n", $Document->{'Size'}/1024;    # 郵件大小
  47.     printf "正文內(nèi)容: \n%s\n", $Document->GetFirstItem('Body')->{Text};  # 正文內(nèi)容
  48.    
  49.     print Dumper($Document->{'Authors'});
  50.     print Dumper($Document->{'ColumnValues'});
  51.     print Dumper($Document->{'Created'});
  52.     print Dumper($Document->{'IsDeleted'});
  53.     print Dumper($Document->{'IsNewNote'}); # 是否為新郵件
  54.     print Dumper($Document->{'ParentDocumentUNID'}); # 如果是回復郵件,這里獲取其上級 UUID
  55.     # Set notesDocumentCollection = notesDocument.Responses
  56.     print Dumper($Document->{'Responses'});  
  57.     print Dumper($Document->{'Verifier'});     
  58.    
  59.     print Dumper($Document->{'Signer'});     
  60.     print Dumper($Document->GetItemValue('Topic'));
  61.    
  62.     foreach my $one ( @{$Document->{'Items'}} ) {
  63.         printf "--->%s \n",$one->{Text} if $one->{Text};        
  64.     }   
  65.       
  66.    
  67.     my $Values = $Document->GetItemValue('Index_Entries');
  68.     foreach my $Value (@$Values) {
  69.         print " Index: $Value\n";
  70.     }
  71.     #last unless $Index < 50;
  72. }


  73. =pod
  74. # 這里是抄襲別人的代碼,還沒有研究
  75. # folder = 'Main View';
  76. my $Response = $Database->GetView($folder);
  77. my $Count = $Response->TopLevelEntryCount;
  78. my $Index = $Count;

  79. open (OUT, ">$file");

  80. #loop through all emails
  81. for (1..$Count)
  82. {
  83.     my $Document = $Response->GetNthDocument($Index--);
  84.     #my $subject = $Document->GetFirstItem('Subject')->{Text};
  85.     #print OUT "Subject: $subject NoteID: %s\n",$Document->{NoteID};
  86. }

  87. #`start excel.exe $file`;


  88. =cut
復制代碼

論壇徽章:
1
雙子座
日期:2013-11-06 17:18:01
2 [報告]
發(fā)表于 2011-08-24 16:47 |只看該作者
回復 1# horsley


    請問LZ,可以在LINUX平臺上實現(xiàn)訪問notes數(shù)據(jù)庫嗎?謝謝

論壇徽章:
0
3 [報告]
發(fā)表于 2011-08-24 21:55 |只看該作者
謝謝分享,收了

論壇徽章:
0
4 [報告]
發(fā)表于 2011-08-26 20:31 |只看該作者
回復 2# seufy88

Win32::OLE 不能在 linux 平臺上運行哈。Lotus Notes 好像有 for linux 的 client,查查文檔可能有辦法。

論壇徽章:
0
5 [報告]
發(fā)表于 2012-07-25 17:58 |只看該作者
請問如何下載郵件里的附件?

論壇徽章:
0
6 [報告]
發(fā)表于 2012-07-25 18:00 |只看該作者
# This program extracts email messages from a
# Lotus Notes account.
#
# Email messages will be saved in directories
# named for the mail folder they're stored in.  
# All of these directories will be stored
# under a new top-level directory named
# "C:\temp\mail" by default, but this can be
# overridden with the -d flag.
#
# For each email message, a subdirectory will
# be created, containing the text and attachments
# for that message. These subdirectories are
# currently named by sequential numbers instead of
# by their subject titles. That's on my TODO list
# to fix; it shouldn't be too hard.
#
# Some folders in the Notes mail database are not
# really mail folders, so I try to skip them.
# Currently I skip all folders whose names are in
# parentheses (except for Inbox), and the folders
# in the array @badlist. You can customize @badlist
# as necessary.
#
# By default, Lotus Notes will open the email
# database for the PC's default user. To access
# the email for a different user: open Notes
# and switch to another userid first; then run
# this program while Notes is still open.

use strict;
use English;
use warnings;
use vars qw($opt_d $opt_v);
use Getopt::Std;
use Win32::OLE;
use Win32::OLE::Variant;
use vars qw($key $value);
require Data:umper;
use email::mailNotice;
use utils::dateUtil;

# Command-line options:
# -d dirname    Save everything under the directory "dirname"
# -v            Verbose reporting of progress
getopt("d";
my $startTime = time();

# Define a directory to store the results:C:/temp/AMT production logs archive/Downloading
my $dir = $opt_d || 'C:/temp/AMT production logs archive/Downloaded';

if (!(-e $dir))
{
        mkdir($dir) or die "Can't make $dir: $!";
}

# Define a list of "Normal" folders to skip
my @badlist = ('Drafts', 'Sent', 'Follow Up', 'Junk Mail', 'Trash');
               
# Auto-print carriage returns
$OUTPUT_RECORD_SEPARATOR = "\n";

# Open the email database in Lotus Notes
# (To use another person's email database, switch to
# their userid in Notes before running this program)
my $notes = Win32::OLE->new('Notes.NotesSession')
             or die "Can't open Lotus Notes";
my ($Version) = ($notes->{NotesVersion} =~ /\s*(.*\S)\s*$/);
            
my $database = $notes->GetDatabase("D03NM128/03/M/IBM", "d03nm128\\mail1\\igfsup.nsf" or die "Could not open database.\n";
#my $database = $notes->GetDatabase("D23M0013/23/M/IBM", "d23m0013\\mail6\\yuyb.nsf" or die "Could not open database.\n";
$database->OpenMail;

my $AllDocuments = $database->AllDocuments;
my $Count = $AllDocuments->Count;

print "The current user is $notes->{UserName}.\n";
print "Running Notes \"$Version\" on \"$notes->{Platform}\".\n";
print "There are $Count documents in the database.\n";

# Verify the server connection
print "Connected to ", $database->{Title},
      " on ", $database->{Server},"\n" ;

# Loop over all of the folders
foreach my $viewname (GetViews($database)) {

  # Get the object for this View
  print "Checking folder $viewname...";
  my $view = $database->GetView($viewname);
  # The view is: Win32::OLE=HASH(0x1831ec4)

  # Create a subdirectory to store the messages in
  $viewname =~ tr/()$//d;
  $viewname =~ s(\\)(.)g;
  my $path = "$dir";
  # mkdir ($path, 0755) or die "Can't make directory $path: $!";
  chdir ($path);

  # Get the last document in the folder
  my $num = 1;
  
  #my $doc = $view->GetFirstDocument;
  my $doc = $view->GetLastDocument;
  
  next unless $doc;   
  GetInfo($num, $path, $doc);

  # Get the remaining documents in the folder
  # while ($doc = $view->GetNextDocument($doc)) {
          while ($doc = $view->GetPrevDocument($doc)) {
    $num++;
    GetInfo($num, $path, $doc);
  }
}
print "Finished getting notes emails!";
#email::mailNotice->sendMail1();
print "Sent email notice!";
# print "Moving downloaded logs to backup folder...";
my $endTime = time();
print "rogram has been running for:",$endTime-$startTime," seconds";


sub GetInfo {
  my ($num, $path, $doc) = @_;
  print "rocessing message $num" if $opt_v;
         
  #Create a new subdirectory based on the message number
  #print STDERR "The env hash is ", Data:umper:umper(%ENV), "\n";
  #print STDERR "The doc hash is ", Data:umper:umper($doc), "\n";
  #The doc hash is $VAR1 = bless( {}, 'Win32::OLE' );
  
  my $createdDate = $doc->Created;
  my $dateFormat = utils::dateUtil->dateFormat($createdDate);
  
  my $parentDir=substr $dateFormat,0,10;
  my $subDir = substr( $dateFormat, 10, length($dateFormat)-10 );

  
  # if dateFormat same, put them into same dir, else new dateFormat dir
  if (-e $parentDir)
  {
          print $parentDir," is already exist, creating new dir under dateFormat.";
          $parentDir.="\/".$subDir;
          #$parentDir.="\/".$subDir.$emailFrom;
          mkdir($parentDir) or die "Can't make $parentDir : $!";
  }
  else
  {
    mkdir($parentDir) or die "Can't make $parentDir : $!";
    #chdir($parentDir);
    $parentDir.="\/".$subDir;
    #$parentDir.="\/".$subDir.$emailFrom;
    print "File doesn't exist subdir is: ",$parentDir;   
          mkdir($parentDir) or die "Can't make $parentDir : $!";       
  }
  
          # Write the contents of the message to a file
    open (TEXTFILE, ">$parentDir/messages.txt"
     or die "Can't create $parentDir message file: $!";
    print TEXTFILE "Form: ", $doc->{Form}->[0];
    print TEXTFILE "INetFrom: ", $doc->{INetFrom}->[0];
    print TEXTFILE "From: ", $doc->{From}->[0];  
    print TEXTFILE "To: ", $doc->{SendTo}->[0];
    print TEXTFILE "DateTime: ", $doc->Created;   
    print TEXTFILE "Subject: ", $doc->{Subject}->[0];   
    print TEXTFILE $doc->{Body};  
    close TEXTFILE;
    # Save attachments as files, if any
    my $array_ref = $doc->{'$FILE'};
    print "array_ref: ",$array_ref->[0];
    foreach my $attachment (@$array_ref) {
        if ($attachment) {
                    
          ExtractAttachment($doc, "$path/$parentDir", $attachment);     
        }
    }

}

sub ExtractAttachment {
        print "Enter ExtractAttachment";
  my ($doc, $path, $filename) = @_;

  print "Extracting attachment $filename" if $opt_v;

  # Get a Windows-friendly pathname for the file
  $path = "$path/$filename";
  $path =~ tr/\//\\/; # replace '/' with '\\'

  # Save the attachment to a file
  print "Saving attachment..";
  my $attachment = $doc->GetAttachment($filename);
  $attachment->ExtractFile($path);
}

sub GetViews {
  my ($database) = @_;
  my @views = ();

  # Loop through all of the views in this database
  my $array_ref = $database->{Views};
  foreach my $view (@$array_ref) {           
  my $name = $view->{Name};      
    # We only want folders if it's the Inbox
    # or a normal folder name with no parentheses
    # if (($name eq '($Inbox)') or ($name !~ /\(.+\)/)) {
    if (($name eq '($Inbox)')) {
      # Add the folder name to the @views list
      # if it's not in the @badlist      
      push(@views, $name) unless (grep { $name eq $_ } @badlist);
      last;# break out of the foreach loop
    }
  }

  print "Get Inbox view only: ",$views[0],"\n";

  return @views;
}

這是我的程序,經(jīng)過調(diào)試之后發(fā)現(xiàn)問題出在my $array_ref = $doc->{'$FILE'};這個地方,$doc->{'$FILE'}這個根本就沒有返回值,請問有辦法解決么?
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP