<html>

<head><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>read outlook express mail subjects into a file</title>
<style>
<!--
	table td.head{ 
		background-color: #3a6ba5;
		border: 1px #000000 solid;
		font-family: Verdana;
		font-weight: bold;
		font-size: 14px;
		color: #f79c19;
		padding: 6px;
	}

	table td.body{ 
		border-bottom: 1px #6699CC dotted;
		text-align: left;
		font-family: Verdana, sans-serif, Arial;
		font-weight: normal;
		font-size: 14px;
		color: #3A6BA5;
		background-color: #fafafa;
		padding: 6px;
	}
	
-->
</style>
</head>

<body>



<p align="left"><font size="6" color="#FF0000"><span lang="en-ca"><b>&nbsp; 
 
</b></span><b>&nbsp;&nbsp;&nbsp; <span lang="en-ca">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></b></font>
<span lang="en-ca"><font size="6" color="#FF0000"><b>Simple MAPI</b></font></span></p>

<div align="left">
  <pre><b><font color="#ff0000" size="5">A. <span lang="en-ca">First </span>Edition</font></b></pre>
</div>
<div align="left">
	<pre><span lang="en-ca"><b>This is just a joke! Wang Hui developed a software tool for managing Outlook Express and sold for some money. And I am not</b></span></pre>
</div>
<div align="left">
	<pre><span lang="en-ca"><b>very happy about this. Also to satisfy my heart, we have a bet. If I can just read a single message from local mail box, he</b></span></pre>
</div>
<div align="left">
	<pre><span lang="en-ca"><b>will eat up my keyboard or displayer, provided I give him some sauce to make things easier!</b></span></pre>
</div>
<div align="left">
	<pre><span lang="en-ca"><b>So, this is a simple program of reading OE and I only finished it within a couple of hours to win my bet. </b></span></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">B</span>.<span lang="en-ca"><a name="problem"></a>The problem</span></font></b></pre>
	<p>
    
  <span lang="en-ca"><font size="2"><b>The thing is like this. MAPI is a rather 
	general protocol not only for MS. Therefore you can find that MAPI.dll or </b></font></span></p>
	<p>
    
  <span lang="en-ca"><font size="2"><b>MAPI32.dll all support them. However, as 
	a free software, should Outlook Express support them? According to Wang Hui, </b></font></span></p>
	<p>
    
  <span lang="en-ca"><font size="2"><b>Microsoft hates OE because it is free 
	with windows and it already becomes the biggest competitor for its Outlook. 
	Hence,</b></font></span></p>
	<p>
    
  <span lang="en-ca"><font size="2"><b>MS even removes programmers from OE group 
	to stop upgrading it.</b></font></span></p>
	<p>
    
  <span lang="en-ca"><font size="2"><b>And the key of the all this is that OE 
	does support MAPI. However, MAPI doesn't specify how local mails should be 
	handled.</b></font></span></p>
	<p>
    
  <span lang="en-ca"><font size="2"><b>It is really up to mail client to handle. 
	And MS also doesn't like people to know the structure of storage. My 
	personal </b></font></span></p>
	<p>
    
  <span lang="en-ca"><font size="2"><b>opinion is that the best of what MS can 
	do is using OLE store. But it may not be efficient and MS doesn't like 
	people feel</b></font></span></p>
	<p>
    
  <span lang="en-ca"><font size="2"><b>too easy to develop application for OE. 
	Instead MS hopes programmer can work more for Outlook.</b></font></span></p>
	<p>
    
  <b><font color="#ff0000" size="5"><span lang="en-ca"><a name="explain"></a>C</span>.<span lang="en-ca">The
  </span></font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>idea of 
  program</b></font></span></p>
	<p><span lang="en-ca"><font size="2"><b>The above question has a bad 
	solution to do it. You can rename the &quot;Inbox.dbx&quot; file to some other name 
	and rename other </b></font></span></p>
	<p><span lang="en-ca"><font size="2"><b>mail box file to &quot;Inbox.dbx&quot;. Then 
	you can use the &quot;findnext&quot; and &quot;readmail&quot;, &quot;savemail&quot; etc. Later you can 
	change back </b></font></span></p>
	<p><span lang="en-ca"><font size="2"><b>their name.</b></font></span></p>
	<p><span lang="en-ca"><font size="2"><b>Another problem is that I directly 
	load library of &quot;msoe.dll&quot; instead of &quot;mapi32.dll&quot; or &quot;mapi.dll&quot;. Probably 
	this is not</b></font></span></p>
	<p><span lang="en-ca"><font size="2"><b>the best way if people are not 
	actually using OE. But as I explained above, this is just a joke.</b></font></span></div>
<pre><b><font color="#ff0000" size="5">D.<span lang="en-ca"><a name="Method"></a>The </span>major functions</font></b></pre>
<div align="left">
  <pre><span lang="en-ca"><b>I suspect the implementation of &quot;findnext&quot; is not implemented efficiently because it is like searching every time from </b></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><b>beginning link list or table.</b></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><b>Please note that in my project file, I output the executable file to the directory &quot;<a href="file:///C:/Program%20Files/Outlook%20Express">C:\Program Files\Outlook Express</a>&quot;.</b></span></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">E</span>.</font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>Further improvement</b></font></span></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">F</span>.</font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>File listing</b></font></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3" color="#FF0000"><b>1. mapi.cpp</b></font></span></pre>
</div>
<div align="left">
  <pre>กก</pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3" color="#FF0000"><b>file name: mapi.cpp</b></font></span></pre>
</div>
<pre>// mapi.cpp : Defines the entry point for the application.
//

#include &lt;basetsd.h&gt;
#include &lt;stdio.h&gt;
#include &lt;windows.h&gt;
#include &lt;mapi.h&gt;


//#define ULONG unsigned long;
//typedef unsigned long ULONG;

typedef ULONG (FAR PASCAL *MAPIFreeBufferType)(
  LPVOID pv  
);

typedef ULONG (FAR PASCAL *MAPILogonType)
( 
	ULONG ulUIParam, 
	LPTSTR lpszProfileName, 
	LPTSTR lpszPassword, 
	FLAGS flFlags,         
	ULONG ulReserved,      
	LPLHANDLE lplhSession  
);

typedef ULONG (FAR PASCAL *MAPIReadMailType)(
  LHANDLE lhSession,
  ULONG ulUIParam,
  LPTSTR lpszMessageID,
  FLAGS flFlags,
  ULONG ulReserved,
  lpMapiMessage FAR * lppMessage  
);
 
typedef ULONG (FAR PASCAL *MAPIFindNextType)(
  LHANDLE lhSession,
  ULONG ulUIParam,
  LPTSTR lpszMessageType,
  LPTSTR lpszSeedMessageID,
  FLAGS flFlags,
  ULONG ulReserved,
  LPTSTR lpszMessageID      
);

typedef ULONG (FAR PASCAL *MAPILogoffType) (
  LHANDLE lhSession,   
  ULONG ulUIParam,     
  FLAGS flFlags,       
  ULONG ulReserved     
);
 




int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	FILE* stream;
	MAPILogonType mapiLogon;
	MAPIReadMailType mapiReadMail;
	MAPIFindNextType mapiFindNext;
	MAPIFreeBufferType mapiFreeBuffer;
	MAPILogoffType mapiLogoff;
	ULONG result;
	ULONG session;
	HMODULE hmodule;
	lpMapiMessage mapiMsg;
	char buffer[512];

	if ((hmodule=LoadLibrary(&quot;msoe.dll&quot;))==NULL)
	{
		printf(&quot;failed\n&quot;);
		exit(1);
	}
	if ((mapiLogon=(MAPILogonType)(GetProcAddress(hmodule, &quot;MAPILogon&quot;)))==NULL)
	{
		printf(&quot;failed getprocaddress\n&quot;);
		exit(2);
	}

	if ((mapiReadMail=(MAPIReadMailType)(GetProcAddress(hmodule, &quot;MAPIReadMail&quot;)))==NULL)
	{
		printf(&quot;failed getprocaddress\n&quot;);
		exit(2);
	}

	if ((mapiFindNext=(MAPIFindNextType)(GetProcAddress(hmodule, &quot;MAPIFindNext&quot;)))==NULL)
	{
		printf(&quot;failed getprocaddress\n&quot;);
		exit(2);
	}
	if ((mapiFreeBuffer=(MAPIFreeBufferType)(GetProcAddress(hmodule, &quot;MAPIFreeBuffer&quot;)))==NULL)
	{
		printf(&quot;failed getprocaddress\n&quot;);
		exit(2);
	}

	if ((mapiLogoff=(MAPILogoffType)(GetProcAddress(hmodule, &quot;MAPILogoff&quot;)))==NULL)
	{
		printf(&quot;failed getprocaddress\n&quot;);
		exit(2);
	}


	if ((result=mapiLogon((ULONG)hInstance, NULL, NULL, MAPI_NEW_SESSION|MAPI_LOGON_UI, 0, &amp;session))
		!=SUCCESS_SUCCESS)
	{
		switch (result)
		{
		case MAPI_E_FAILURE:
			printf(&quot;One or more unspecified errors occurred during logon. No session handle was returned.&quot;);
			break;
		case MAPI_E_INSUFFICIENT_MEMORY:
			printf(&quot;There was insufficient memory to proceed. No session handle was returned. &quot;);
			break;
		case MAPI_E_LOGIN_FAILURE:
			printf(&quot;There was no default logon, and the user failed to log on successfully\
				when the logon dialog box was displayed. No session handle was returned. &quot;);
			break;
		case MAPI_E_TOO_MANY_SESSIONS:
			printf(&quot;The user had too many sessions open simultaneously. No session handle was returned. &quot;);
			break;
		case MAPI_E_USER_ABORT:
			printf(&quot;The user canceled the logon dialog box. No session handle was returned. &quot;);
			break;
		}
		exit(3);
	}

	bool stop=false;
	stream=fopen(&quot;subject.txt&quot;, &quot;w&quot;);
	char* ptr=NULL;
	char* msgType=&quot;anything&quot;;
	while (true)
	{
		if ((result=mapiFindNext(session, (ULONG)hInstance, msgType, ptr, 
			MAPI_LONG_MSGID|MAPI_GUARANTEE_FIFO, 0, buffer))!=SUCCESS_SUCCESS)
		{
			switch (result)
			{
			case MAPI_E_FAILURE:
				printf(&quot;One or more unspecified errors occurred while matching the message type. \
					The call failed before message type matching could take place. &quot;);
				break;
			case MAPI_E_INSUFFICIENT_MEMORY :
				printf(&quot;There was insufficient memory to proceed. No message was found. &quot;);
				break;
			case MAPI_E_INVALID_MESSAGE :
				printf(&quot;An invalid message identifier was passed in the lpszSeedMessageID parameter.\
					No message was found. &quot;);
				break;
			case MAPI_E_INVALID_SESSION :
				printf(&quot;An invalid session handle was passed in the lhSession parameter. No message was found. &quot;);
				break;
			case MAPI_E_NO_MESSAGES :
				printf(&quot;A matching message could not be found. &quot;);
				stop=true;
				break;
			}
		}
		ptr=buffer;
		if (stop)
		{
			fclose(stream);
			if ((result=mapiLogoff(session, (ULONG)hInstance, 0, 0))!=SUCCESS_SUCCESS)
			{
				switch (result)
				{
				case MAPI_E_FAILURE :
					printf(&quot;The flFlags parameter is invalid or one or more unspecified \
						errors occurred. &quot;);
					break;
				case MAPI_E_INSUFFICIENT_MEMORY :
					printf(&quot;There was insufficient memory to proceed. \
						The session was not terminated. &quot;);
					break;
				case MAPI_E_INVALID_SESSION :
					printf(&quot;An invalid session handle was used for the lhSession parameter. \
						The session was not terminated.&quot;);
					break;
				}
				exit(6);
			}
			break;			
		}


		if ((result=mapiReadMail(session, (ULONG)hInstance, buffer, MAPI_ENVELOPE_ONLY, 0, &amp;mapiMsg))
			!=SUCCESS_SUCCESS)
		{
			switch (result)
			{
			case MAPI_E_ATTACHMENT_WRITE_FAILURE :
				printf(&quot;An attachment could not be written to a temporary file. Check directory permissions. &quot;);
				break;
			case MAPI_E_DISK_FULL :
				printf(&quot;An attachment could not be written to a temporary file because there was not \
					enough space on the disk. &quot;);
				break;
			case MAPI_E_FAILURE:
				printf(&quot;One or more unspecified errors occurred while reading the message. &quot;);
				break;
			case MAPI_E_INSUFFICIENT_MEMORY :
				printf(&quot;There was insufficient memory to read the message. &quot;);
				break;
			case MAPI_E_INVALID_MESSAGE :
				printf(&quot;An invalid message identifier was passed in the lpszMessageID parameter. &quot;);
				break;
			case MAPI_E_INVALID_SESSION :
				printf(&quot;An invalid session handle was passed in the lhSession parameter. No message was retrieved. &quot;);
				break;
			case MAPI_E_TOO_MANY_FILES :
				printf(&quot;There were too many file attachments in the message. The message could not be read. &quot;);
				break;
			case MAPI_E_TOO_MANY_RECIPIENTS :
				printf(&quot;There were too many recipients of the message. The message could not be read. &quot;);
				break;
			}

		}


		fprintf(stream, &quot;id: %s; subject:%s\n&quot;, buffer,  mapiMsg-&gt;lpszSubject);
		if ((result=mapiFreeBuffer((void*)mapiMsg))!=SUCCESS_SUCCESS)
		{
			if (result==MAPI_E_FAILURE)
			{
				printf(&quot;One or more unspecified errors occurred. The memory could not be freed. &quot;);
				exit(4);
			}
		}
	}
	FreeLibrary(hmodule);

	return 0;
}


</pre>
<p>กก</p>
<p>กก</p>

<pre></pre>

<pre></pre>

<pre></pre>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                   
&nbsp;&nbsp;&nbsp; <a href="PocketRuler.htm">                  







                       <img src="picture/back.gif" style="border: medium none" alt="back.gif (341 bytes)" width="32" height="35"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<a href="index.htm">
<img src="picture/up.gif" style="border: medium none" alt="up.gif (335 bytes)" width="35" height="32"></a>       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                         
<img src="picture/next.gif" style="border: medium none" alt="next.gif (337 bytes)" width="32" height="35">          


</p>

</body>

</html>