การนับรายการและทำงานกับหมวดหมู่
สองงานเล็ก ๆ แต่ต้องใช้บ่อยที่นี่: ตรวจสอบจำนวนรายการในอาโครไบฟหรือโฟลเดอร์ - สำหรับแถบความคืบหน้า, รายงาน หรือการตรวจสอบความถูกต้อง - และอ่านหมวดหมู่สีที่ Outlook for Mac บันทึกในไฟล์
ตัวอย่างด้านล่างใช้ส่วนหัวและเนมสเปซต่อไปนี้:
#include <Storage/Olm/OlmStorage.h>
#include <Storage/Olm/OlmFolder.h>
#include <Storage/Olm/OlmItemCategory.h>
#include <Mapi/MapiMessage.h>
#include <system/collections/list_ext.h>
#include <system/string_comparison.h>
#include <system/convert.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Storage::Olm;
ตรวจสอบและนับข้อความของโฟลเดอร์
HasMessages บอกว่าโฟลเดอร์มีอะไรหรือไม่; MessageCount ให้จำนวนที่แม่นยำ
SharedPtr<OlmStorage> olm = OlmStorage::FromFile(u"SampleOLM.olm");
SharedPtr<OlmFolder> folder = olm->GetFolder(u"Inbox", true);
if (folder->get_HasMessages())
{
Console::WriteLine(u"Message count: " + Convert::ToString(folder->get_MessageCount()));
}
olm->Dispose();
นับรายการต่อโฟลเดอร์และทั้งหมดของอาโครไบฟ
เดินต้นไม้และพิมพ์ MessageCount สำหรับแต่ละโหนดสร้างรายการสินค้าตัวอย่างของไฟล์ GetTotalItemsCount บน storage คืนค่าผลรวมทั้งหมดในคำสั่งเดียว
void PrintMessageCount(SharedPtr<Collections::Generic::ListExt<SharedPtr<OlmFolder>>> folders)
{
for (SharedPtr<OlmFolder> folder : folders)
{
Console::WriteLine(u"Message count [" + folder->get_Name() + u"]: " + Convert::ToString(folder->get_MessageCount()));
PrintMessageCount(folder->get_SubFolders());
}
}
SharedPtr<OlmStorage> storage = MakeObject<OlmStorage>(u"SampleOLM.olm");
PrintMessageCount(storage->get_FolderHierarchy());
// total across the whole storage
Console::WriteLine(u"Total items: " + Convert::ToString(storage->GetTotalItemsCount()));
storage->Dispose();
อ่านรายการหมวดหมู่
หมวดหมู่ Outlook ถูกเก็บในอาโครไบฟเป็นคู่ชื่อ/สี GetCategories คืนค่าเป็น OlmItemCategory อ็อบเจ็กต์; สี เป็นรูปแบบ HTML #rrggbb สตริง
SharedPtr<OlmStorage> olm = OlmStorage::FromFile(u"SampleOLM.olm");
auto categories = olm->GetCategories();
for (SharedPtr<OlmItemCategory> category : categories)
{
Console::WriteLine(u"Category name: " + category->get_Name());
// the color is a hexadecimal string: #rrggbb
Console::WriteLine(u"Category color: " + category->get_Color());
}
olm->Dispose();
แก้ไขสีของหมวดหมู่ในข้อความ
ข้อความจะเก็บเฉพาะ ชื่อ ของหมวดหมู่ (เช่น Categories อาเรย์ของ MapiMessage). เพื่อแสดงป้ายสี ให้จับคู่แต่ละชื่อกับรายการใน storage โดยไม่สนใจตัวพิมพ์:
SharedPtr<OlmStorage> olm = OlmStorage::FromFile(u"SampleOLM.olm");
auto categories = olm->GetCategories();
SharedPtr<OlmFolder> folder = olm->GetFolder(u"Inbox", true);
for (SharedPtr<MapiMessage> msg : folder->EnumerateMapiMessages())
{
ArrayPtr<String> msgCategories = msg->get_Categories();
if (msgCategories == nullptr)
{
continue;
}
for (String msgCategory : msgCategories)
{
Console::WriteLine(u"Category name: " + msgCategory);
// resolve the color by matching the name against the storage category list
String color = u"Not found";
for (SharedPtr<OlmItemCategory> category : categories)
{
if (category->get_Name().Equals(msgCategory, StringComparison::OrdinalIgnoreCase))
{
color = category->get_Color();
break;
}
}
Console::WriteLine(u"Category color: " + color);
}
}
olm->Dispose();