Webから未読文書数確認 -2-
<話題の履歴>
前回は、C-APIの関数とNotes/Domino 8で追加されたLotusScriptのMethodを紹介しました。
勿論、LotusScriptだけでなくJavaでも拡張が行われています。
今回は、まず、C-APIを使った場合を試してみることにしましょう。
前回紹介したC-APIの関数でUnread Tableの取得は行える訳ですが、Unread Tableを取得後、Unread Tableの中に含まれるNoteIDの数を数えなければなりません。
ここで、ちょっと解説しておきますが、以前Unreadの仕組みを「Notes/Dominoの未読文書管理の仕組」 で解説しましたが、Unread TableはUserID毎にTableを持ち、その中に未読文書のNoteIDを保持しているのです。
そのUnread Tableを取得するのが、NSFDbGetUnreadNoteTableですが、これはUnread Tableを取得するだけですので、それ以外のC-APIの関数を利用する必要があります。
今回は、以下の4つの関数を利用します。
NSFDbOpen
NSFDbGetUnreadNoteTable
IDEntries
IDDestroyTable
最初のNSFDbOpenはDBをOpenするための関数で、2番目は今回のUnread Tableを取得するための関数です。
更に、IDEntriesは取得したUnread Table内のNoteIDのEntryを扱うための関数で、最後のIDDestroyTableは利用したNoteID Tableを削除するための関数です。
これらを使ってAgentを作成します。
Agentは適当な名前を付け(今回は"UnreadCount"としました)、Action Menuから手動で実行するAgentとして作成し、Security設定で"Web Userで実行"を指定して、"制限された操作を許可する"も有効にしておきます。
AgentのCodeには以下を記述します。
今回は、LoginしたUserのMail DBの未読文書数を取得してWebに表示するようにしています。
以下の例ではStatusがIntegerで定義していますので、未読文書は32,000程度まで対応が可能です。
それ以上の未読文書数があることが想定される場合はLongで定義すると良いと思います。
(Declarations)
Declare Function NSFDbOpen Lib "nnotes.dll" ( _
Byval PathName As String, _
rethDB As Long ) As Integer
Declare Function NSFDbGetUnreadNoteTable Lib "nnotes.dll" ( _
Byval hDB As Long, _
Byval userName As String, _
Byval userNameLength As Integer, _
Byval fCreateIfNotAvailable As Boolean, _
IDtable As Long ) As Integer
Declare Function IDEntries Lib "nnotes.dll" ( _
Byval hTable As Long ) As Integer
Declare Function IDDestroyTable Lib "nnotes.dll" ( _
Byval hTable As Long ) As Integer
(Initialize)
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim STATUS As Integer
Dim DBPath As String
Dim hDb As Long
Dim userName As String
Dim hIDtable As Long
Dim num_entries As Long
Dim view As NotesView
Dim doc As NotesDocument
Dim mailserver As String
Dim mailfile As String
'UserのMail DB Pathを取得する
Set db = New NotesDatabase ("","names.nsf")
Set view = db.GetView ("($Users)" )
Set doc = view.GetDocumentByKey( session.EffectiveUserName, True )
mailserver = doc.MailServer(0)
mailfile = doc.MailFile(0)
'UserのMail DBを開く
Set db = New NotesDatabase (mailserver,mailfile)
If db.Server = "" Then
DBPath = db.FilePath
Else
DBPath = db.Server & "!!" & db.FilePath
End If
STATUS = NSFDbOpen( DBPath, hDb)
If ( STATUS ) Then
Print "NSFDbOpen Error"
Exit Sub
End If
'UserNameにWebからAgentを実行しているUserIDをSetして、Unread Tableを取得する
userName = session.EffectiveUserName
STATUS = NSFDbGetUnreadNoteTable(hDb, userName, Len(userName), True, hIDtable)
If ( STATUS ) Then
Print "NSFDbGetUnreadNoteTable Error"
Exit Sub
End If
'Unread TableのNoteID数をCountしてWebに表示する
num_entries = IDEntries(hIDtable)
Print "<a>貴方のMail DBの未読数: " & Cstr(num_entries) & "</a>"
STATUS = IDDestroyTable(hIDtable)
If ( STATUS ) Then
Print "IDDestroyTable Error"
Exit Sub
End If
End Sub
これでAgentの作成は完了です。
Agentを作成したDBのACLはLoginが必要なようにDefaultは無しに設定し、全てのUserに読者権限を与えます。
これでWeb Browserから、 http://Server_FQDN/DB_Path/DB_Filename/Agent_Name?OpenAgent を実行すると Loginが求められ、LoginしたUserのMail DBの未読文書数が表示されます。
複数のServerから構成された場合でも、Agentを実行するDBが存在するServer以外にUserのMail DBが配置されていても問題はありませんし、Domino 7.0.xでもこのCodeは実行することができます。
今回は、C-APIの関数を使ってMail DBの未読文書数を表示するAgentを作成してみました。
しかし、この場合、Notes ClientでDB ICONに表示されている未読文書数と同じ数が得られるだけとなっています。
次回は、Notes/Domino 8で拡張されたLotusScriptのMethodを使って同様のことを実現してみたいと思います。
Webから未読文書数確認 -1-
みなさん、Notes Clientの場合はDB ICONに未読文書数が表示され、どのDBに未読文書があるのかが直ぐに分かることはご存知の通りです。
でも、Webからの場合はDBの未読文書数を簡単に確認することができません。
DWA(Domino Web Access)でもMail DBの未読文書数を簡単に表示する方法は提供されていないのです。
では、Webから未読文書の数を確認することはできるのでしょうか?
実は、Domino 6.x/7でもC-APIで関数が用意されているのです。
以下の関数がそうです。
NSFDbGetUnreadNoteTable(
DBHANDLE hDB,
char far *UserName,
WORD UserNameLength,
BOOL fCreateIfNotAvailable,
HANDLE far *rethUnreadList)
これにより、Userを指定して、そのUserのUnread Tableの取得が行えるようになっています。
実は、この関数ですが、私はUnread Tableを取得するためには、本人のNotesIDが必要だと思い込んでいたのですが、User Nameを渡してやるだけで簡単に取得できてしまう事をとある方より教えて頂いたのです。
思い込みというのは良くないことです。
また、Notes/Domino 8からはC-APIを使わなくても、LotusScriptでMethodが提供されるようになったのは皆さんもご存知の通りです。
Notes/Domino 8のDesigner Helpを参照すると以下のUnread関係のMethodが追加されています。
NotesDatabase.GetAllReadDocuments method -- new method
NotesDatabase.GetAllUnreadDocuments method -- new method
NotesDocument.MarkRead method -- new method
NotesDocument.MarkUnread method -- new method
NotesDocumentCollection.MarkAllRead method -- new method
NotesDocumentCollection.MarkAllUnread method -- new method
NotesView.GetAllReadEntries method -- new method
NotesView.GetAllUnreadEntries method -- new method
NotesView.MarkAllRead method -- new method
NotesView.MarkAllUnread method -- new method
NotesViewEntryCollection.MarkAllRead method -- new method
NotesViewEntryCollection.MarkAllUnread method -- new method
NotesViewNavigator.MarkAllRead method -- new method
NotesViewNavigator.MarkAllUnread method -- new method
C-APIの場合と異なり、ViewのUnreadが扱えたりできますので、LotusScriptでUnread Tableを細かに操作できるようになっているのです。
今回は、概要だけ紹介しますが、次回以降、簡単に試してみて動きを検証してみます。
新年明けましておめでとうございます
新年明けましておめでとうございます。
本年も、このBlogをよろしくお願い致します。
また、今年はNotes/Domino 6.xから8へのMigrationが行われる年になると思います。
来年春にNotes/Domino 6.5もサポート切れになりますので。。。。
移行などのTipsも順次紹介して行けたらと思っておりますので、今年もご愛読の程、よろしくお願い致します。