Scanning a Message

The PMX_ENGINE scans a PMX_MESSAGE object. The following code illustrates reading an email message from disk into a PMX_MESSAGE object, scanning it with a PMX_ENGINE, and then destroying the PMX_MESSAGE object.

for (i = 1; i < argc; i++) {
    PMX_MESSAGE msg;
    FILE *f = fopen(argv[i], "r");
    char buf[4096];
    size_t nread;
   
    if (!f)
        continue;
   
    e->vtbl->create_message(e, &msg);
    while (!feof(f) && !ferror(f)) {
        nread = fread(buf, 1, sizeof(buf), f);
        pmx_append_to_message(msg, buf, nread);
    }
    fclose(f);
   
    /* Perform actual scanning with scan_cb callback */
   
    e->vtbl->scan_message(e, msg, NULL, &scan_cb, NULL);
   
    msg->vtbl->destroy(msg);
}

Description:

  • For each filename specified on the command line, this program reads the file from disk into a PMX_MESSAGE object created by the engine's create_message method.
  • The PMX_MESSAGE object is then passed to the engine's scan_message method.
  • After the email message is scanned, it is then destroyed with its destroy method.