void ProtocolAdmin::adminCommandSendMail(const std::string& xmlData) { OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if(output){ TRACK_MESSAGE(output); std::string name; uint32_t depotId; Item* mailItem = createMail(xmlData, name, depotId); if(mailItem){ if(Mailbox::sendItemTo(name, depotId, mailItem)){ output->AddByte(AP_MSG_COMMAND_OK); } else{ output->AddByte(AP_MSG_COMMAND_FAILED); output->AddString("Could not mail item"); } } else{ output->AddByte(AP_MSG_COMMAND_FAILED); output->AddString("Could not mail item"); } OutputMessagePool::getInstance()->send(output); } }
int main(int argc, char **argv) { int get; int opt_index = 0; /* for getopt */ char *cc_string = NULL; char *bcc_string = NULL; const char *opts = "f:n:a:p:oVedvtb?c:s:r:u:i:g:m:H:x:"; /* Set certian global options to NULL */ conf_file = NULL; memset(&Mopts, 0, sizeof(struct mailer_options)); Mopts.encoding = true; /* Check if they need help */ if ((argc > 1) && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-help") || !strcmp(argv[1], "--help"))) { if (argc == 3) { moduleUsage(argv[2]); } else if (argc == 2) { usage(); } else { fprintf(stderr, "Only specify one option with %s: \n", argv[1]); usage(); } } table = dhInit(28, defaultDestr); if (!table) { fprintf(stderr, "ERROR: Could not initialize Hash table.\n"); exit(0); } while ((get = getopt_long_only(argc, argv, opts, Gopts, &opt_index)) > EOF) { switch (get) { case 'n': setConfValue("MY_NAME", xstrdup(optarg)); break; case 'f': setConfValue("MY_EMAIL", xstrdup(optarg)); break; case 'a': if (!Mopts.attach) { Mopts.attach = dlInit(defaultDestr); } dlInsertTop(Mopts.attach, xstrdup(optarg)); break; case 'V': Mopts.verbose = true; break; case 'p': setConfValue("SMTP_PORT", xstrdup(optarg)); break; case 'o': Mopts.priority = 1; break; case 'e': Mopts.gpg_opts |= GPG_ENC; break; case 's': Mopts.subject = optarg; break; case 'r': setConfValue("SMTP_SERVER", xstrdup(optarg)); break; case 'c': conf_file = optarg; break; case 't': checkConfig(); printf("Configuration file is proper.\n"); dhDestroy(table); return (0); break; case 'v': printf("email - By Dean Jones; Version %s\n", EMAIL_VERSION); dhDestroy(table); exit(EXIT_SUCCESS); break; case 'b': Mopts.blank = 1; break; case 'u': setConfValue("SMTP_AUTH_USER", xstrdup(optarg)); break; case 'i': setConfValue("SMTP_AUTH_PASS", xstrdup(optarg)); break; case 'm': setConfValue("SMTP_AUTH", xstrdup(optarg)); break; case 'g': setConfValue("GPG_PASS", xstrdup(optarg)); break; case 'H': if (!Mopts.headers) { Mopts.headers = dlInit(defaultDestr); } dlInsertTop(Mopts.headers, xstrdup(optarg)); break; case 'x': setConfValue("TIMEOUT", xstrdup(optarg)); break; case '?': usage(); break; case 1: Mopts.html = 1; break; case 2: Mopts.gpg_opts |= GPG_SIG; break; case 3: cc_string = optarg; break; case 4: bcc_string = optarg; break; case 5: /* To name? */ break; case 6: setConfValue("USE_TLS", xstrdup("true")); break; case 7: Mopts.encoding = false; break; default: /* Print an error message here */ usage(); break; } } /* first let's check to make sure they specified some recipients */ if (optind == argc) { usage(); } configure(); /* Check to see if we need to attach a vcard. */ if (getConfValue("VCARD")) { dstrbuf *vcard = expandPath(getConfValue("VCARD")); if (!Mopts.attach) { Mopts.attach = dlInit(defaultDestr); } dlInsertTop(Mopts.attach, xstrdup(vcard->str)); dsbDestroy(vcard); } /* set to addresses if argc is > 1 */ if (!(Mopts.to = getNames(argv[optind]))) { fatal("You must specify at least one recipient!\n"); properExit(ERROR); } /* Set CC and BCC addresses */ if (cc_string) { Mopts.cc = getNames(cc_string); } if (bcc_string) { Mopts.bcc = getNames(bcc_string); } signal(SIGTERM, properExit); signal(SIGINT, properExit); signal(SIGPIPE, properExit); signal(SIGHUP, properExit); signal(SIGQUIT, properExit); createMail(); properExit(0); /* We never get here, but gcc will whine if i don't return something */ return 0; }