Sun Java System Messaging Server 6 2005Q4 MTA Developer's Reference

Example 4 Using an Input Procedure to Generate the Message Body

The program shown in Example 7–4 uses an input procedure as the source for the body of a message to be sent. In the program, the input procedure msg_proc will read input until the runtime library routine fgets() signals an EOF condition, for example, a control-D has been input. The address of the procedure msg_proc is passed to mtaSend() using a MTA_MSG_PROC item code. The mtaSend() routine repeatedly calls the msg_proc procedure, until a negative value is returned by the procedure.

Example 7–4 Using an Input Procedure to Generate the Message Body

/* send_input.c -- Demonstrate the use of MTA_MSG_PROC */
#include <stdio.h\>
#include <stdlib.h\>
#include <string.h\>
#include "mtasdk.h"
#ifdef _WIN32
typedef long ssize_t;

/* Push an entry onto the item list */
#define ITEM(item,adr) item_list[index].item_code = item;\
item_list[index].item_address = adr;\
item_list[index].item_length  = 0;\
item_list[index].item_status  = 0;\
item_list[index++].item_smessage = NULL

ssize_t msg_proc(const char **bufadr)
  static char buf[1024];

  if (!bufadr)
      return(-2); /* Call error; abort */

  printf("input: ");
  if (fgets(buf, sizeof(buf), stdin))
    *bufadr = buf;
    buflen = strlen(buf);
    if (buf[buflen-1] == ’\n’)
      buflen -= 1;
    return(-1);  /* EOF */

main ()
  int istat, index = 0;
  mta_item_list_t item_list[4];

  STRITEM(MTA_SUBJECT, "send_input.c");
  STRITEM(MTA_TO, "root");
  ITEM(MTA_MSG_PROC, msg_proc);