int main (int argc, char * argv []) { int c; mu_stream_t in, out; int reread_option = 0; mu_off_t reread_off; int skip_option = 0; mu_off_t skip_off; while ((c = getopt (argc, argv, "hs:r:")) != EOF) switch (c) { case 'r': reread_option = 1; reread_off = strtoul (optarg, NULL, 10); break; case 's': skip_option = 1; skip_off = strtoul (optarg, NULL, 10); break; case 'h': printf ("usage: cat [-s off]\n"); exit (0); default: exit (1); } MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, MU_STREAM_SEEK)); MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0)); if (skip_option) { mu_stream_printf (out, "skipping to %lu:\n", (unsigned long) skip_off); MU_ASSERT (mu_stream_seek (in, skip_off, MU_SEEK_SET, NULL)); } MU_ASSERT (mu_stream_copy (out, in, 0, NULL)); if (reread_option) { mu_stream_printf (out, "rereading from %lu:\n", (unsigned long) reread_off); MU_ASSERT (mu_stream_seek (in, reread_off, MU_SEEK_SET, NULL)); MU_ASSERT (mu_stream_copy (out, in, 0, NULL)); } mu_stream_close (in); mu_stream_destroy (&in); mu_stream_close (out); mu_stream_destroy (&out); return 0; }
int mu_message_save_attachment (mu_message_t msg, const char *filename, mu_mime_io_buffer_t info) { mu_stream_t istream; int ret; mu_header_t hdr; const char *fname = NULL; char *partname = NULL; if (msg == NULL) return EINVAL; if ((ret = _attachment_setup (&info, msg, &istream)) != 0) return ret; if (ret == 0 && (ret = mu_message_get_header (msg, &hdr)) == 0) { if (filename == NULL) { ret = mu_message_aget_decoded_attachment_name (msg, info->charset, &partname, NULL); if (partname) fname = partname; } else fname = filename; if (fname && (ret = mu_file_stream_create (&info->fstream, fname, MU_STREAM_WRITE | MU_STREAM_CREAT)) == 0) { const char *content_encoding; if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, &content_encoding)) content_encoding = "7bit"; ret = mu_filter_create (&info->stream, istream, content_encoding, MU_FILTER_DECODE, MU_STREAM_READ); } } if (info->stream && istream) ret = mu_stream_copy (info->fstream, info->stream, 0, NULL); if (ret != EAGAIN && info) { mu_stream_close (info->fstream); mu_stream_destroy (&info->stream); mu_stream_destroy (&info->fstream); } mu_stream_destroy (&istream); _attachment_free (info, ret); /* FIXME: or 0? */ /* Free fname if we allocated it. */ if (partname) free (partname); return ret; }
int main (int argc, char **argv) { int i; mu_stream_t in, out; mu_stream_t cvt; const char *args[5] = { "iconv" }; if (argc < 3 || argc > 4) { fprintf (stderr, "usage: %s from-code to-code [err]\n", argv[0]); return 1; } MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0)); args[1] = argv[1]; args[2] = argv[2]; i = 3; if (argc == 4) args[i++] = argv[3]; args[i] = NULL; MU_ASSERT (mu_filter_create_args (&cvt, in, args[0], i, args, MU_FILTER_DECODE, MU_FILTER_READ)); mu_stream_unref (in); MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0)); MU_ASSERT (mu_stream_copy (out, cvt, 0, NULL)); mu_stream_unref (cvt); mu_stream_flush (out); return 0; }
static int _smtp_data_send (mu_smtp_t smtp, mu_stream_t stream) { int status = _mu_smtp_data_begin (smtp); if (status) return status; status = mu_stream_copy (smtp->carrier, stream, 0, NULL); _mu_smtp_data_end (smtp); return status; }
int mu_message_encapsulate (mu_message_t msg, mu_message_t *newmsg, mu_mime_io_buffer_t info) { mu_stream_t istream, ostream; int ret = 0; mu_message_t tmsg = NULL; if (newmsg == NULL) return MU_ERR_OUT_PTR_NULL; if (msg == NULL) { mu_header_t hdr; ret = mu_message_create (&tmsg, NULL); if (ret) return ret; msg = tmsg; #define MSG822_HEADER "Content-Type: message/rfc822\n" \ "Content-Transfer-Encoding: 7bit\n\n" if ((ret = mu_header_create (&hdr, MSG822_HEADER, sizeof (MSG822_HEADER) - 1)) == 0) ret = mu_message_set_header (msg, hdr, NULL); #undef MSG822_HEADER if (ret) { mu_message_destroy (&msg, NULL); return ret; } } if ((ret = _attachment_setup (&info, msg, &ostream)) != 0) { mu_message_destroy (&tmsg, NULL); return ret; } info->msg = msg; if (ret == 0 && (ret = mu_message_get_streamref (msg, &istream)) == 0) { mu_stream_seek (istream, 0, MU_SEEK_SET, NULL); ret = mu_stream_copy (ostream, istream, 0, NULL); mu_stream_destroy (&istream); } if (ret == 0) *newmsg = info->msg; mu_stream_destroy (&ostream); _attachment_free (info, ret && ret != EAGAIN); return ret; }
static int _mh_prop_write_stream (mu_header_t header, struct mu_mh_prop *mhprop, mu_stream_t stream) { int rc; mu_stream_t instream; mu_off_t size; mu_header_get_streamref (header, &instream); rc = mu_stream_copy (stream, instream, 0, &size); if (rc) { mu_error (_("error writing to context file %s: %s"), mhprop->filename, mu_strerror (rc)); return rc; } else rc = mu_stream_truncate (stream, size); mu_stream_destroy (&instream); return rc; }
static void c_copy (mu_stream_t out, mu_stream_t in) { if (verbose) { mu_stream_set_stat (in, MU_STREAM_STAT_MASK_ALL, instat); mu_stream_set_stat (out, MU_STREAM_STAT_MASK_ALL, outstat); } if (printable) { char c; size_t size; while (mu_stream_read (in, &c, 1, &size) == 0 && size > 0) { int rc; if (printable && !ISPRINT (c)) { char outbuf[24]; sprintf (outbuf, "\\%03o", (unsigned char) c); rc = mu_stream_write (out, outbuf, strlen (outbuf), NULL); } else rc = mu_stream_write (out, &c, 1, NULL); } } else MU_ASSERT (mu_stream_copy (out, in, 0, NULL)); }
/* Build a mime response message from original message MSG. TEXT is the message text. */ static int build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, mu_message_t msg, const char *text) { mu_mime_t mime = NULL; mu_message_t newmsg; mu_stream_t stream, input; mu_header_t hdr; mu_body_t body; const char *header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n" "Content-Transfer-Encoding: 8bit\n\n"; int rc; mu_mime_create (&mime, NULL, 0); mu_message_create (&newmsg, NULL); mu_message_get_body (newmsg, &body); if ((rc = mu_static_memory_stream_create (&input, text, strlen (text)))) { mu_sieve_error (mach, _("cannot create temporary stream: %s"), mu_strerror (rc)); mu_mime_destroy (&mime); mu_message_destroy (&newmsg, NULL); return 1; } if (mu_sieve_tag_lookup (tags, "mime", NULL)) { mu_stream_t fstr; rc = mu_filter_create (&fstr, input, "base64", MU_FILTER_ENCODE, MU_STREAM_READ); mu_stream_unref (input); if (rc == 0) { header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n" "Content-Transfer-Encoding: base64\n\n"; input = fstr; } } rc = mu_body_get_streamref (body, &stream); if (rc) { mu_sieve_error (mach, _("cannot get input body stream: %s"), mu_strerror (rc)); mu_mime_destroy (&mime); mu_message_destroy (&newmsg, NULL); mu_stream_destroy (&input); return 1; } rc = mu_stream_copy (stream, input, 0, NULL); if (rc) { mu_sieve_error (mach, _("stream copy failed: %s"), mu_strerror (rc)); mu_mime_destroy (&mime); mu_message_destroy (&newmsg, NULL); mu_stream_destroy (&input); mu_stream_destroy (&stream); return 1; } mu_stream_destroy (&input); mu_header_create (&hdr, header, strlen (header)); mu_message_set_header (newmsg, hdr, NULL); mu_mime_add_part (mime, newmsg); mu_message_unref (newmsg); *pmime = mime; return 0; }
static int _pop_message_get_stream (struct _pop3_message *mpm, mu_stream_t *pstr) { int status; struct _pop3_mailbox *mpd = mpm->mpd; if (!(mpm->flags & _POP3_MSG_CACHED)) { mu_stream_t stream; mu_off_t size; status = mu_pop3_retr (mpd->pop3, mpm->num, &stream); if (status) return status; do { mu_stream_t flt; if (!mpd->cache) { status = mu_temp_file_stream_create (&mpd->cache, NULL, 0); if (status) /* FIXME: Try to recover first */ break; mu_stream_set_buffer (mpd->cache, mu_buffer_full, 8192); } status = mu_stream_size (mpd->cache, &mpm->offset); if (status) break; status = mu_filter_create (&flt, stream, "CRLF", MU_FILTER_DECODE, MU_STREAM_READ); if (status) break; status = mu_stream_copy (mpd->cache, flt, 0, &size); mu_stream_destroy (&flt); } while (0); if (status) { pop_stream_drain (stream); mu_stream_unref (stream); return status; } mu_stream_unref (stream); mpm->message_size = size; /* FIXME: Possible overflow. */ mpm->flags |= _POP3_MSG_CACHED | _POP3_MSG_SIZE; } return mu_streamref_create_abridged (pstr, mpd->cache, mpm->offset, mpm->offset + mpm->message_size - 1); }
int main (int argc, char **argv) { int i; char *host = NULL; char *infile = NULL; char *port = NULL; int tls = 0; int raw = 1; int flags = 0; mu_stream_t stream; mu_smtp_t smtp; mu_stream_t instr; char *from = NULL; mu_list_t rcpt_list = NULL; mu_list_t meth_list = NULL; mu_list_t skiphdr_list = NULL; struct mu_sockaddr *sa; struct mu_sockaddr_hints hints; mu_set_program_name (argv[0]); mu_stdstream_setup (MU_STDSTREAM_RESET_NONE); if (argc < 2) usage (); memset (&hints, 0, sizeof (hints)); hints.flags = MU_AH_DETECT_FAMILY; hints.port = 25; hints.protocol = IPPROTO_TCP; hints.socktype = SOCK_STREAM; MU_ASSERT (mu_smtp_create (&smtp)); for (i = 1; i < argc; i++) { if (strncmp (argv[i], "port=", 5) == 0) port = argv[i] + 5; else if (strncmp (argv[i], "family=", 7) == 0) { hints.flags &= ~MU_AH_DETECT_FAMILY; switch (argv[i][7]) { case '4': hints.family = AF_INET; break; case '6': hints.family = AF_INET6; break; default: mu_error ("invalid family name: %s", argv[i]+7); exit (1); } } else if (strncmp (argv[i], "trace=", 6) == 0) { char *arg = argv[i] + 6; if (mu_isdigit (arg[0])) mu_smtp_trace (smtp, atoi (argv[i] + 6) ? MU_SMTP_TRACE_SET : MU_SMTP_TRACE_CLR); else { mu_smtp_trace (smtp, MU_SMTP_TRACE_SET); if (strcmp (arg, "secure") == 0) mu_smtp_trace_mask (smtp, MU_SMTP_TRACE_SET, MU_XSCRIPT_SECURE); else if (strcmp (arg, "payload") == 0) mu_smtp_trace_mask (smtp, MU_SMTP_TRACE_SET, MU_XSCRIPT_PAYLOAD); } } else if (strncmp (argv[i], "tls=", 4) == 0) tls = atoi (argv[i] + 4); else if (strncmp (argv[i], "domain=", 7) == 0) MU_ASSERT (mu_smtp_set_param (smtp, MU_SMTP_PARAM_DOMAIN, argv[i] + 7)); else if (strncmp (argv[i], "user="******"pass="******"service=", 8) == 0) MU_ASSERT (mu_smtp_set_param (smtp, MU_SMTP_PARAM_SERVICE, argv[i] + 8)); else if (strncmp (argv[i], "realm=", 6) == 0) MU_ASSERT (mu_smtp_set_param (smtp, MU_SMTP_PARAM_REALM, argv[i] + 6)); else if (strncmp (argv[i], "host=", 5) == 0) MU_ASSERT (mu_smtp_set_param (smtp, MU_SMTP_PARAM_HOST, argv[i] + 5)); else if (strncmp (argv[i], "url=", 4) == 0) MU_ASSERT (mu_smtp_set_param (smtp, MU_SMTP_PARAM_URL, argv[i] + 4)); else if (strncmp (argv[i], "input=", 6) == 0) infile = argv[i] + 6; else if (strncmp (argv[i], "raw=", 4) == 0) raw = atoi (argv[i] + 4); else if (strncmp (argv[i], "rcpt=", 5) == 0) { if (!rcpt_list) MU_ASSERT (mu_list_create (&rcpt_list)); MU_ASSERT (mu_list_append (rcpt_list, argv[i] + 5)); } else if (strncmp (argv[i], "from=", 5) == 0) from = argv[i] + 5; else if (strncmp (argv[i], "auth=", 5) == 0) update_list (&meth_list, argv[i] + 5); else if (strncmp (argv[i], "skiphdr=", 8) == 0) { update_list (&skiphdr_list, argv[i] + 8); raw = 0; } else if (host) { mu_error ("server name already given: %s, new name %s?", host, argv[i]); exit (1); } else host = argv[i]; } if (!host) usage (); if (!raw) flags = MU_STREAM_SEEK; if (infile) MU_ASSERT (mu_file_stream_create (&instr, infile, MU_STREAM_READ|flags)); else MU_ASSERT (mu_stdio_stream_create (&instr, MU_STDIN_FD, flags)); host = argv[1]; MU_ASSERT (mu_sockaddr_from_node (&sa, host, port, &hints)); MU_ASSERT (mu_tcp_stream_create_from_sa (&stream, sa, NULL, MU_STREAM_RDWR)); mu_smtp_set_carrier (smtp, stream); mu_stream_unref (stream); if (!from) { from = getenv ("USER"); if (!from) { mu_error ("cannot determine sender name"); exit (1); } } if (raw && !rcpt_list) { mu_error ("no recipients"); exit (1); } MU_ASSERT (mu_smtp_open (smtp)); MU_ASSERT (mu_smtp_ehlo (smtp)); if (tls && mu_smtp_capa_test (smtp, "STARTTLS", NULL) == 0) { MU_ASSERT (mu_smtp_starttls (smtp)); MU_ASSERT (mu_smtp_ehlo (smtp)); } if (meth_list) { int status; MU_ASSERT (mu_smtp_add_auth_mech_list (smtp, meth_list)); status = mu_smtp_auth (smtp); switch (status) { case 0: MU_ASSERT (mu_smtp_ehlo (smtp)); break; case ENOSYS: case MU_ERR_NOENT: /* Ok, skip it */ break; default: mu_error ("authentication failed: %s", mu_strerror (status)); exit (1); } } MU_ASSERT (mu_smtp_mail_basic (smtp, from, NULL)); mu_list_foreach (rcpt_list, send_rcpt_command, smtp); if (raw) { /* Raw sending mode: send from the stream directly */ MU_ASSERT (mu_smtp_send_stream (smtp, instr)); } else { /* Message (standard) sending mode: send a MU message. */ mu_message_t msg; mu_stream_t ostr, bstr; mu_header_t hdr; mu_iterator_t itr; mu_body_t body; if (skiphdr_list) mu_list_set_comparator (skiphdr_list, headercmp); MU_ASSERT (mu_stream_to_message (instr, &msg)); mu_stream_unref (instr); MU_ASSERT (mu_smtp_data (smtp, &ostr)); MU_ASSERT (mu_message_get_header (msg, &hdr)); MU_ASSERT (mu_header_get_iterator (hdr, &itr)); for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) { const char *name; void *value; mu_iterator_current_kv (itr, (void*) &name, &value); if (mu_list_locate (skiphdr_list, (void*) name, NULL) == 0) continue; mu_stream_printf (ostr, "%s: %s\n", name, (char*)value); } mu_iterator_destroy (&itr); MU_ASSERT (mu_stream_write (ostr, "\n", 1, NULL)); MU_ASSERT (mu_message_get_body (msg, &body)); MU_ASSERT (mu_body_get_streamref (body, &bstr)); MU_ASSERT (mu_stream_copy (ostr, bstr, 0, NULL)); mu_stream_destroy (&bstr); mu_stream_close (ostr); mu_stream_destroy (&ostr); } MU_ASSERT (mu_smtp_dot (smtp)); MU_ASSERT (mu_smtp_quit (smtp)); mu_smtp_destroy (&smtp); mu_stream_close (instr); mu_stream_destroy (&instr); return 0; }
oo\n\ "; int main (int argc, char **argv) { int i; char *p; mu_message_t msg; mu_stream_t stream = NULL; mu_header_t hdr; mu_body_t body; mu_set_program_name (argv[0]); mu_static_memory_stream_create (&stream, text, strlen (text)); assert (mu_stream_to_message (stream, &msg) == 0); mu_stream_unref (stream); assert (mu_message_get_header (msg, &hdr) == 0); assert (mu_message_get_body (msg, &body) == 0); assert (mu_body_get_streamref (body, &stream) == 0); assert (mu_stream_seek (stream, 0, MU_SEEK_END, NULL) == 0); for (i = 1; i < argc; i++) { if (strcmp (argv[i], "-h") == 0) { mu_printf ("usage: %s [-a HDR:VAL] [-t TEXT]\n", mu_program_name); return 0; } if (strcmp (argv[i], "-a") == 0) { i++; assert (argv[i] != NULL); p = strchr (argv[i], ':'); assert (p != NULL); *p++ = 0; while (*p && mu_isspace (*p)) p++; assert (mu_header_set_value (hdr, argv[i], p, 1) == 0); } else if (strcmp (argv[i], "-l") == 0) { mu_off_t off; int whence = MU_SEEK_SET; i++; assert (argv[i] != NULL); off = strtol (argv[i], &p, 10); assert (*p == 0); if (off < 0) whence = MU_SEEK_END; assert (mu_stream_seek (stream, off, whence, NULL) == 0); } else if (strcmp (argv[i], "-t") == 0) { mu_wordsplit_t ws; i++; assert (argv[i] != NULL); if (mu_wordsplit (argv[i], &ws, MU_WRDSF_NOSPLIT | MU_WRDSF_DEFFLAGS)) { mu_error ("mu_wordsplit: %s", mu_wordsplit_strerror (&ws)); exit (1); } else assert (mu_stream_write (stream, ws.ws_wordv[0], strlen (ws.ws_wordv[0]), NULL) == 0); mu_wordsplit_free (&ws); } else mu_error ("ignoring unknown argument %s", argv[i]); } mu_stream_unref (stream); assert (mu_message_get_streamref (msg, &stream) == 0); assert (mu_stream_copy (mu_strout, stream, 0, NULL) == 0); mu_stream_unref (stream); return 0; }
int mu_message_create_attachment (const char *content_type, const char *encoding, const char *filename, mu_message_t *newmsg) { mu_header_t hdr; mu_body_t body; mu_stream_t fstream = NULL, tstream = NULL; char *header = NULL, *name = NULL, *fname = NULL; int ret; if (newmsg == NULL) return MU_ERR_OUT_PTR_NULL; if (filename == NULL) return EINVAL; if ((ret = mu_message_create (newmsg, NULL)) == 0) { if (content_type == NULL) content_type = "text/plain"; if (encoding == NULL) encoding = "7bit"; if ((fname = strdup (filename)) != NULL) { name = strrchr (fname, '/'); if (name) name++; else name = fname; ret = mu_asprintf (&header, "Content-Type: %s; name=%s\n" "Content-Transfer-Encoding: %s\n" "Content-Disposition: attachment; filename=%s\n\n", content_type, name, encoding, name); if (ret == 0) { if ((ret = mu_header_create (&hdr, header, strlen (header))) == 0) { mu_stream_t bstr; mu_message_get_body (*newmsg, &body); mu_body_get_streamref (body, &bstr); if ((ret = mu_file_stream_create (&fstream, filename, MU_STREAM_READ)) == 0) { if ((ret = mu_filter_create (&tstream, fstream, encoding, MU_FILTER_ENCODE, MU_STREAM_READ)) == 0) { mu_stream_copy (bstr, tstream, 0, NULL); mu_stream_unref (tstream); mu_message_set_header (*newmsg, hdr, NULL); } } mu_stream_unref (bstr); free (header); } } } } if (ret) { if (*newmsg) mu_message_destroy (newmsg, NULL); if (hdr) mu_header_destroy (&hdr); if (fstream) mu_stream_destroy (&fstream); if (fname) free (fname); } return ret; }
int main (int argc, char **argv) { int index; int rc; mu_stream_t in, tmp; mu_message_t msg; mu_header_t hdr; mu_iterator_t itr; const char *file; char *newval; mu_off_t size; mu_body_t body; mu_stream_t bstr; MU_APP_INIT_NLS (); mh_argp_init (); mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, opt_handler, NULL, &index); if (index == argc) { mu_error (_("file name not given")); exit (1); } file = argv[index]; prompter_init (); if (erase_seq) prompter_set_erase (erase_seq); if (kill_seq) prompter_set_erase (kill_seq); if ((rc = mu_stdio_stream_create (&strout, MU_STDOUT_FD, MU_STREAM_WRITE))) { mu_error (_("cannot open stdout: %s"), mu_strerror (rc)); return 1; } if ((rc = mu_file_stream_create (&in, file, MU_STREAM_RDWR))) { mu_error (_("cannot open input file `%s': %s"), file, mu_strerror (rc)); return 1; } rc = mu_stream_to_message (in, &msg); mu_stream_unref (in); if (rc) { mu_error (_("input stream %s is not a message (%s)"), file, mu_strerror (rc)); return 1; } if ((rc = mu_temp_file_stream_create (&tmp, NULL, 0))) { mu_error (_("Cannot open temporary file: %s"), mu_strerror (rc)); return 1; } /* Copy headers */ mu_message_get_header (msg, &hdr); mu_header_get_iterator (hdr, &itr); for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) { const char *name, *val; mu_iterator_current_kv (itr, (const void **)&name, (void**)&val); if (!is_empty_string (val)) { mu_stream_printf (tmp, "%s: %s\n", name, val); mu_stream_printf (strout, "%s: %s\n", name, val); } else { int cont = 0; mu_opool_t opool; const char *prompt = name; mu_opool_create (&opool, 1); do { size_t len; char *p; p = prompter_get_value (prompt); if (!p) return 1; prompt = NULL; if (cont) { mu_opool_append_char (opool, '\n'); if (!mu_isspace (p[0])) mu_opool_append_char (opool, '\t'); } len = strlen (p); if (len > 0 && p[len-1] == '\\') { len--; cont = 1; } else cont = 0; mu_opool_append (opool, p, len); free (p); } while (cont); mu_opool_append_char (opool, 0); newval = mu_opool_finish (opool, NULL); if (!is_empty_string (newval)) mu_stream_printf (tmp, "%s: %s\n", name, newval); mu_opool_destroy (&opool); } } mu_iterator_destroy (&itr); mu_stream_printf (strout, "--------\n"); mu_stream_write (tmp, "\n", 1, NULL); /* Copy body */ if (prepend_option) { mu_stream_printf (strout, "\n--------%s\n\n", _("Enter initial text")); while ((newval = prompter_get_line ())) { mu_stream_write (tmp, newval, strlen (newval), NULL); free (newval); mu_stream_write (tmp, "\n", 1, NULL); } } mu_message_get_body (msg, &body); mu_body_get_streamref (body, &bstr); if (!prepend_option && !rapid_option) { mu_stream_copy (strout, bstr, 0, NULL); mu_stream_seek (bstr, 0, MU_SEEK_SET, NULL); } mu_stream_copy (tmp, bstr, 0, NULL); mu_stream_unref (bstr); if (!prepend_option && !rapid_option) { printf ("\n--------%s\n\n", _("Enter additional text")); while ((newval = prompter_get_line ())) { mu_stream_write (tmp, newval, strlen (newval), NULL); free (newval); mu_stream_write (tmp, "\n", 1, NULL); } } /* Destroy the message */ mu_message_destroy (&msg, mu_message_get_owner (msg)); /* Rewind the streams and copy data back to in. */ mu_stream_seek (in, 0, MU_SEEK_SET, NULL); mu_stream_seek (tmp, 0, MU_SEEK_SET, NULL); mu_stream_copy (in, tmp, 0, &size); mu_stream_truncate (in, size); mu_stream_destroy (&in); mu_stream_destroy (&tmp); mu_stream_destroy (&strout); prompter_done (); return 0; }
int mutool_filter (int argc, char **argv) { int rc, index; mu_stream_t flt, prev_stream; const char *fltname; int mode; if (argp_parse (&filter_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) return 1; argc -= index; argv += index; if (list_option) { if (argc) { mu_error (_("excess arguments")); return 1; } return list_filters (); } if (argc == 0) { mu_error (_("what filter do you want?")); return 1; } prev_stream = mu_strin; mu_stream_ref (mu_strin); do { int i; fltname = argv[0]; if (fltname[0] == '~') { mode = negate_filter_mode (filter_mode); fltname++; } else mode = filter_mode; for (i = 1; i < argc; i++) if (strcmp (argv[i], "+") == 0) break; rc = mu_filter_create_args (&flt, prev_stream, fltname, i, (const char **)argv, mode, MU_STREAM_READ); mu_stream_unref (prev_stream); if (rc) { mu_error (_("cannot open filter stream: %s"), mu_strerror (rc)); return 1; } prev_stream = flt; argc -= i; argv += i; if (argc) { argc--; argv++; } } while (argc); rc = mu_stream_copy (mu_strout, flt, 0, NULL); if (rc) { mu_error ("%s", mu_strerror (rc)); return 1; } if (newline_option) mu_stream_write (mu_strout, "\n", 1, NULL); mu_stream_destroy (&flt); mu_stream_flush (mu_strout); return 0; }
int io_copy_out (mu_stream_t str, size_t size) { return mu_stream_copy (iostream, str, size, NULL); }