Use mapi to read SMS content

Source: Internet
Author: User

When performing an SMS backup, we first consider reading the specific content of the SMS in the form of mapi and writing it back during restoration. It turns out that, this method is feasible but not desirable!
Here, let's take a look at how mapi reads data. In this process, we have referenced the things written by bored customers and obtained guidance from our old employees.
Define the following two macros for ease of use:
# Define exit_on_failed (_ hr )/
If (failed (_ hr ))/
{/
Goto funcexit ;/
}

# Define release_obj (s )/
If (s! = NULL )/
{/
S-> release ();/
S = NULL ;/
}
Initialize mapi:

Hresult initmapi ()
{
Coinitializeex (null, coinit_multithreaded );
Mapiinitialize (null );
// First logon to the store.
Mapilogonex (null, & m_psession );

If (! M_psession)
Return e_fail;

Return s_ OK;
}

// Get the message Stores Table
HR = m_psession-> getmsgstorestable (mapi_unicode, & pstorestable );

// Define ulong progcolumns [] = {2, pr_entryid, pr_display_name}; to get the property
HR = pstorestable-> setcolumns (lpsproptagarray) & progcolumns, 0 );
Exit_on_failed (HR );

The above initializes mapi and obtains store and table!
The queryrows method is used to obtain the required specific store.
While (succeeded (pstorestable-> queryrows (1, 0, & pstoresrows )))
{
If (pstoresrows-> crows! = 1)
Break;
Else if (pstoresrows-> Arow [0]. cvalues <1)
| (Pstoresrows-> Arow [0]. lpprops [0]. ulproptag! = Pr_entryid ))
Break;
Else
{
If (_ tcsicmp (pstoresrows-> Arow [0]. lpprops [1]. value. lpszw, _ T ("SMS") = 0)
// Here we get the SMS information, and others include activesyne, MMS (and so on, if there is a corresponding account ...)
{
Ulong ulmesagetype;
HR = m_psession-> openentry (pstoresrows-> Arow [0]. lpprops [0]. value. bin. CB,
(Lpentryid) pstoresrows-> Arow [0]. lpprops [0]. value. bin. LPB,
Null,
Null,
& Ulmesagetype,
(Lpunknown *) & psmsstore );
// Obtain the iMessage object after obtaining the store
Exit_on_failed (HR );
Break;
}

Freeprows (pstoresrows );
Pstoresrows = NULL;
}
}
If (pstoresrows)
{
Freeprows (pstoresrows );
Pstoresrows = NULL;
}
Release_obj (pstorestable );

Release the object as soon as possible. We will use the obtained SMS store to obtain the attributes of SMS and other SMS folder.
Ulong progcolumns_subtree [] = {1, pr_ipm_subtree_entryid };
Spropvalue * pprogvalue_subfolders = NULL;
// Get root folder
HR = psmsstore-> getprops (lpsproptagarray) progcolumns_subtree, mapi_unicode, & ulvalues, & pprogvalue_subtree );
Exit_on_failed (HR );

HR = psmsstore-> openentry (pprogvalue_subtree [0]. value. bin. CB, (lpentryid) pprogvalue_subtree [0]. value. bin. LPB,
Null,
Null,
Null,
(Lpunknown *) & psmsfolder );

Mapifreebuffer (pprogvalue_subtree );

// Has sub folder or not
HR = psmsfolder-> getprops (lpsproptagarray) progcolumns_subfolders, mapi_unicode, & ulvalues, & pprogvalue_subfolders );

If (pprogvalue_subfolders [0]. value. B> 0)
// Determine whether sub folder exists under the foler. If yes, obtain the message
HR = pfolder-> getcontentstable (0, & pcontentstable );
HR = pcontentstable-> setcolumns (lpsproptagarray) & progcolumns_contents, 0 );
// Basically the same as above. The method for obtaining the table is changed. The error checking step is omitted.
HR = pfolder-> openentry (prows-> Arow [0]. lpprops [0]. value. bin. CB,
(Lpentryid) prows-> Arow [0]. lpprops [0]. value. bin. LPB,
Null,
Mapi_best_access,
& Ulmesagetype,
(Lpunknown *) & pmessage );
// Obtain the message. You can perform the following operations on the message.
// In SMS, the message is read by mapi in two parts: the contact part and the content part. The content of SMS is stored in the subject attribute, while in the outlook information, the subject part stores the topic of the information, and the content must be read in istream mode. Because outlook is a little complex, the following is the read method of outlook, which is stored in the self-defined backuptemp struct.
HR = pmessage-> getprops (lpsproptagarray) progcolomns, mapi_unicode, & ulcount, & pprogvalue );
If (succeeded (HR ))
{
If (pprogvalue [0]. ulproptag = pr_sender_email_address)
Wcscpy (pbackuptemp-> bkupheader. szaddress, pprogvalue [0]. value. lpszw );

If (pprogvalue [1]. ulproptag = pr_subject)
Wcscpy (pbackuptemp-> bkupheader. szsubject, pprogvalue [1]. value. lpszw );
If (pprogvalue [2]. ulproptag = pr_message_delivery_time)
Pbackuptemp-> bkupheader. ftemailtime = pprogvalue [2]. value. FT;
Mapifreebuffer (pprogvalue );
}

HR = pmessage-> openproperty (pr_body, & iid_istream, mapi_best_access, null,
(Lpunknown *) & pstream );
If (hR = s_ OK)
{
Pstream-& gt; read (pbackuptemp-& gt; bkupheader. szbody, 1024 * sizeof (wchar), & ulnumchars );
}

In this method, the attachments and MMS content read to mail are complex, and the attributes of objects cannot be taken into account during restoration (more than 40 attributes of a PIM contact ), not suitable for backup!
Next, what I want to do is related to mapi. I will improve this article and constantly modify it.
In addition, I will also explain how to read Pim. Vol. However, for backups, the PIM file can be copied and restored directly, so it does not need to be so troublesome.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/leimiaomiao/archive/2007/05/31/1632897.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.