static void alias_print_group (const char *name, alias_t al) { mu_printf ("%s ", name); util_slist_print (al->list, 0); mu_printf ("\n"); }
static void com_rename (mu_folder_t folder, char **argv) { int rc; mu_printf ("renaming %s to %s\n", argv[0], argv[1]); rc = mu_folder_rename (folder, argv[0], argv[1]); if (rc) mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_rename", argv[0], rc); else mu_printf ("rename successful\n"); }
static void com_delete (mu_folder_t folder, char **argv) { int rc; mu_printf ("deleting %s\n", argv[0]); rc = mu_folder_delete (folder, argv[0]); if (rc) mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_lsub", argv[0], rc); else mu_printf ("delete successful\n"); }
static void usage () { struct command *cp; mu_printf ( "usage: %s [debug=SPEC] url=URL OP ARG [ARG...] [OP ARG [ARG...]...]\n", mu_program_name); mu_printf ("OPerations and corresponding ARGuments are:\n"); for (cp = comtab; cp->verb; cp++) mu_printf (" %s %s\n", cp->verb, cp->args); }
static void com_unsubscribe (mu_folder_t folder, char **argv) { int rc; mu_printf ("unsubscribing %s\n", argv[0]); rc = mu_folder_unsubscribe (folder, argv[0]); if (rc) mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_unsubscribe", argv[0], rc); else mu_printf ("unsubscribe successful\n"); }
static int top0 (msgset_t *mspec, mu_message_t msg, void *data) { mu_stream_t stream; char *buf = NULL; size_t size = 0, n; int lines; if (mailvar_get (&lines, "toplines", mailvar_type_number, 1) || lines < 0) return 1; mu_message_get_streamref (msg, &stream); for (; lines > 0; lines--) { int status = mu_stream_getline (stream, &buf, &size, &n); if (status != 0 || n == 0) break; mu_printf ("%s", buf); } free (buf); mu_stream_destroy (&stream); set_cursor (mspec->msg_part[0]); util_mark_read (msg); return 0; }
int mail_z (int argc, char **argv) { off_t count; int dir; unsigned int pagelines = util_screen_lines (); if (z_parse_args(argc, argv, &count, &dir)) return 1; count *= pagelines; switch (dir) { case D_BWD: if (page_move (-count) == 0) { mu_printf (_("On first screenful of messages\n")); return 0; } break; case D_FWD: if (page_move (count) == 0) { mu_printf (_("On last screenful of messages\n")); return 0; } break; case D_NONE: { /* z. is a GNU extension, so it will be more useful when we reach the last message to show a full screen of the last message. This behaviour is used on startup when displaying the summary and the headers, new messages are last but we want to display a screenful with the real crs set by summary() to the new message. FIXME: Basically it's the same as headers now. Do we need it still? */ break; } } page_do (mail_from0, NULL); return 0; }
int mutool_cflags (int argc, char **argv) { if (argp_parse (&cflags_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL)) return 1; mu_printf ("%s\n", COMPILE_FLAGS); return 0; }
static int _print_list_entry (void *item, void *data) { struct mu_list_response *resp = item; mu_printf ("%c%c %c %4d %s\n", (resp->type & MU_FOLDER_ATTRIBUTE_DIRECTORY) ? 'd' : '-', (resp->type & MU_FOLDER_ATTRIBUTE_FILE) ? 'f' : '-', resp->separator ? resp->separator : ' ', resp->level, resp->name); return 0; }
static int show_part (struct mime_descend_closure *closure, void *data) { size_t width; size_t size = 0; format_msgset (mu_strout, closure->msgset, &width); for (; width < 5; width++) mu_stream_write (mu_strout, " ", 1, NULL); mu_printf (" %-25s", closure->type); mu_message_size (closure->message, &size); if (size < 1024) mu_printf (" %4lu", (unsigned long) size); else if (size < 1024*1024) mu_printf ("%4luK", (unsigned long) size / 1024); else mu_printf ("%4luM", (unsigned long) size / 1024 / 1024); mu_printf ("\n"); return 0; }
int print_envelope (msgset_t *mspec, mu_message_t msg, void *data) { int status; mu_envelope_t env = NULL; const char *sender = NULL, *date = NULL; status = mu_message_get_envelope (msg, &env); if (status) { mu_error (_("%lu: Cannot get envelope"), (unsigned long) mspec->msg_part[0]); } else { mu_envelope_sget_sender (env, &sender); mu_envelope_sget_date (env, &date); if (data) mu_printf ("%s ", (char*) data); mu_printf ("%s %s", sender, date); } return 0; }
int mail_eq (int argc, char **argv) { msgset_t *list = NULL; size_t n; switch (argc) { case 1: n = get_cursor (); if (n == 0) mu_error (_("No applicable message")); else mu_printf ("%lu\n", (unsigned long) n); break; case 2: if (msgset_parse (argc, argv, MSG_NODELETED, &list) == 0) { if (list->msg_part[0] <= total) { set_cursor (list->msg_part[0]); mu_printf ("%lu\n", (unsigned long) list->msg_part[0]); } else util_error_range (list->msg_part[0]); msgset_free (list); } break; default: return 1; } return 0; }
static void com_lsub (mu_folder_t folder, char **argv) { int rc; mu_list_t list; mu_printf ("listing subscriptions for '%s' '%s'\n", argv[0], argv[1]); rc = mu_folder_lsub (folder, argv[0], argv[1], &list); if (rc) mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_lsub", argv[0], rc); else { mu_list_foreach (list, _print_list_entry, NULL); mu_list_destroy (&list); } }
int mutool_acl (int argc, char **argv) { int rc, index; mu_acl_result_t result; mu_cfg_tree_t *tree = NULL, *temp_tree = NULL; mu_cfg_node_t *node; if (argp_parse (&acl_argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) return 1; argc -= index; argv += index; if (argc == 0) { mu_error (_("not enough arguments")); return 1; } if (input_file_name) { mu_load_site_rcfile = 0; mu_load_user_rcfile = 0; mu_load_rcfile = input_file_name; } mu_acl_cfg_init (); if (mu_libcfg_parse_config (&tree)) return 1; if (!tree) return 0; if (mu_cfg_find_node (tree, path, &node)) { mu_error (_("cannot find node: %s"), path); return 1; } mu_cfg_tree_create (&temp_tree); mu_cfg_tree_add_node (temp_tree, node); rc = mu_cfg_tree_reduce (temp_tree, NULL, acl_cfg_param, NULL); if (rc) return 1; if (!acl) { mu_error (_("No ACL found in config")); return 1; } while (argc--) { const char *ap = *argv++; rc = mu_sockaddr_from_node (&target_sa, ap, NULL, NULL); if (rc) { mu_error ("mu_sockaddr_from_node: %s", mu_strerror (rc)); exit (1); } mu_printf ("Testing %s:\n", ap); rc = mu_acl_check_sockaddr (acl, target_sa->addr, target_sa->addrlen, &result); mu_sockaddr_free_list (target_sa); if (rc) { mu_error ("mu_acl_check_sockaddr failed: %s", mu_strerror (rc)); return 1; } switch (result) { case mu_acl_result_undefined: mu_printf ("%s: undefined\n", ap); break; case mu_acl_result_accept: mu_printf ("%s: accept\n", ap); break; case mu_acl_result_deny: mu_printf ("%s: deny\n", ap); break; } } mu_cfg_destroy_tree (&tree); mu_cfg_destroy_tree (&temp_tree); return 0; }
int reply0 (msgset_t *mspec, mu_message_t msg, void *data) { mu_header_t hdr; compose_env_t env; int status; char *str; set_cursor (mspec->msg_part[0]); compose_init (&env); mu_message_get_header (msg, &hdr); compose_header_set (&env, MU_HEADER_TO, util_get_sender (mspec->msg_part[0], 0), COMPOSE_SINGLE_LINE); if (*(int*) data) /* reply starts with a lowercase */ { /* Add all recepients of the originate letter */ mu_address_t addr = NULL; size_t i, count = 0; if (mu_header_aget_value (hdr, MU_HEADER_TO, &str) == 0) { mu_address_create (&addr, str); free (str); mu_address_get_count (addr, &count); } /* Make sure we do not include our alternate names */ for (i = 1; i <= count; i++) { const char *email; if (mu_address_sget_email (addr, i, &email) || email == NULL) continue; if ((mailvar_get (NULL, "metoo", mailvar_type_boolean, 0) == 0) || !mail_is_my_name (email)) compose_header_set (&env, MU_HEADER_TO, email, COMPOSE_SINGLE_LINE); } mu_address_destroy (&addr); /* Finally, add any Ccs */ if (mu_header_aget_value (hdr, MU_HEADER_CC, &str) == 0) compose_header_set (&env, MU_HEADER_TO, str, COMPOSE_SINGLE_LINE); } if (mu_header_aget_value (hdr, MU_HEADER_SUBJECT, &str) == 0) { char *p = NULL; if (mu_unre_subject (str, NULL)) util_strcat (&p, util_reply_prefix ()); util_strcat (&p, str); free (str); compose_header_set (&env, MU_HEADER_SUBJECT, p, COMPOSE_REPLACE); free (p); } else compose_header_set (&env, MU_HEADER_SUBJECT, "", COMPOSE_REPLACE); mu_printf ("To: %s\n", compose_header_get (&env, MU_HEADER_TO, "")); str = compose_header_get (&env, MU_HEADER_CC, NULL); if (str) mu_printf ("Cc: %s\n", str); mu_printf ("Subject: %s\n\n", compose_header_get (&env, MU_HEADER_SUBJECT, "")); make_in_reply_to (&env, msg); make_references (&env, msg); status = mail_send0 (&env, mailvar_get (NULL, "byname", mailvar_type_boolean, 0) == 0); compose_destroy (&env); return status; }
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; }