SamplePlugin performs several operations:
Message recipients and the path to the post office directory into ituplugin.zip, that contains the sample plug-in file, sample.c, and the makefile for building the sample. wplugin.zip, that contains the sample plug-in file, sample.c. §msg4plugins.h header file and the standard input/output and allocation header files.
#include <stdio.h>If you do not have the Messaging Server plug-in header file yet, see "Where to Find the SMTP Plug-in Header File."
#include <malloc.h>
#include <string.h>
#include "msg4plugins.h"
SAMPLE_EXPORT int SamplePluginInit(pblock *Config)This is one of the two function prototypes that the SMTP plug-in must export in order to load. In this sample, the
{
return 1;
}
Config parameter is not referenced further.
SamplePlugin, loads the parameter block pointed to by the Config parameter and creates pointers to the input (InMessage) and output (OutMessage) messages. The output parameter represents the result of the execution of the plug-in code.
SAMPLE_EXPORT int SamplePlugin(pblock *Config,This is one of the two function prototypes that the SMTP plug-in must export in order to load. In this sample, the
Message **ppInMsg,
Message ***pppOutMsg)
Config and pppOutMsg parameters are not referenced further.
The SMTP plug-in code returns either MSG_CONTINUE or MSG_NOACTION to Messaging Server. MSG_CONTINUE indicates that the plug-in worked; message can go on to Messaging Server for further processing. MSG_NOACTION indicates that the plug-in did not do anything.
For information about defining this function, see "Writing the Plug-in Function."
{
char *bodyfile;
Recipient *pRecip;
Recipient new_rcpt;
FILE *f;
FILE *body;
char *ControlText;
char *PostOfficePath;
MSG_CONTINUE, which causes message processing to continue.
f = fopen ("log.out","w"); if (f == NULL) {
return MSG_CONTINUE;
}
GetFirstRecipient. The fprintf routine calls GetRecipientAddress to get the address for printing.
pRecip = GetFirstRecipient (ppInMsg[0]);
if (pRecip) {
fprintf (f,"Recip #1 is %s\n",GetRecipientAddress(pRecip));
}
ControlText = GetControlData(ppInMsg[0]);
if (ControlText) {
fprintf(f, "Control Data follows\n%s", ControlText);
}
FreeControlData(ControlText);
new_rcpt.Addr821 = (char*)malloc (strlen ("<testuser@test.com>") + 1);
strcpy(new_rcpt.Addr821, "<testuser@test.com>");
new_rcpt.Ext = NULL;
new_rcpt.flags = 0;
This is the tricky part - you must set this magic value.
new_rcpt.magic = 0xdeadbeef;Make the AddRecipient call.
AddRecipient(ppInMsg[0], &new_rcpt);
free (new_rcpt.Addr821);For more information, see "Add and remove recipients."
bodyfile = GetMessageFile (*ppInMsg);Then it opens the message body and adds text to the end:
fprintf (f,"GetMessageFile = %s\n", bodyfile);
body = fopen (bodyfile,"a");
if (body == NULL)
{
fprintf (f,"Couldn't append to body\n");
}
else{
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fprintf (body,"This is a new body line\n");
fclose (body);
}
PostOfficePath = GetPostOfficePath(*ppInMsg);
fprintf(f, "PostOffice = %s\n", PostOfficePath);
fclose(f);
MSG_CONTINUE, the message continues on its way. For other return messages, see "Result Codes."
return MSG_CONTINUE;
NOTE: You can find the code for this SMTP plug-in in "SMTP Plug-in Code." For information about building the plug-in, see "Building the SMTP Plug-in." §[Top]
Last Updated: 05/13/99 11:41:54