void sort () { size_t *oldlist, i; oldlist = xmalloc (msgset.count * sizeof (*oldlist)); memcpy (oldlist, msgset.list, msgset.count * sizeof (*oldlist)); switch (algorithm) { case ARG_QUICKSORT: qsort(msgset.list, msgset.count, sizeof(msgset.list[0]), comp); break; case ARG_SHELL: shell_sort(); break; } switch (action) { case ACTION_LIST: for (i = 0; i < msgset.count; i++) list_message (msgset.list[i]); break; default: /* Install signal handlers */ signal (SIGINT, sighandler); signal (SIGQUIT, sighandler); signal (SIGTERM, sighandler); if (verbose) fprintf (stderr, _("Transpositions:\n")); for (i = 0, got_signal = 0; !got_signal && i < msgset.count; i++) { if (msgset.list[i] != oldlist[i]) { size_t old_num, new_num; mu_message_t msg; mu_mailbox_get_message (mbox, oldlist[i], &msg); mh_message_number (msg, &old_num); mu_mailbox_get_message (mbox, msgset.list[i], &msg); mh_message_number (msg, &new_num); transpose (i, oldlist[i]); if (verbose) fprintf (stderr, "{%s, %s}\n", mu_umaxtostr (0, old_num), mu_umaxtostr (1, new_num)); if (action == ACTION_REORDER) swap_message (old_num, new_num); } } } }
static int comp0 (size_t na, size_t nb) { mu_message_t a, b; if (mu_mailbox_get_message (mbox, na, &a) || mu_mailbox_get_message (mbox, nb, &b)) return 0; if (verbose > 1) fprintf (stderr, _("comparing messages %s and %s: "), mu_umaxtostr (0, na), mu_umaxtostr (1, nb)); return compare_messages (a, b, na, nb); }
void pop3d_session_init (struct pop3d_session *session) { if (mu_list_create (&session->capa)) mu_alloc_die (); mu_list_set_destroy_item (session->capa, capa_free); /* Initialize the capability list */ pop3d_append_capa_string (session, "TOP", NULL); pop3d_append_capa_string (session, "UIDL", NULL); pop3d_append_capa_string (session, "RESP-CODES", NULL); pop3d_append_capa_string (session, "PIPELINING", NULL); pop3d_append_capa_string (session, "AUTH-RESP-CODE", NULL); if (pop3d_xlines) pop3d_append_capa_string (session, "XLINES", NULL); pop3d_append_capa_func (session, "LOGIN-DELAY", login_delay_capa); /* This can be implemented by setting an header field on the message. */ pop3d_append_capa_string (session, "EXPIRE", (expire == EXPIRE_NEVER) ? "NEVER" : mu_umaxtostr (0, expire)); pop3d_append_capa_func (session, NULL, capa_user); pop3d_append_capa_func (session, "STLS", capa_stls); pop3d_append_capa_func (session, "IMPLEMENTATION", capa_implementation); }
void swap_message (size_t a, size_t b) { char *path_a, *path_b; char *tmp; asprintf (&path_a, "%s/%s", mbox_path, mu_umaxtostr (0, a)); asprintf (&path_b, "%s/%s", mbox_path, mu_umaxtostr (1, b)); tmp = mu_tempname (mbox_path); rename (path_a, tmp); unlink (path_a); rename (path_b, path_a); unlink (path_b); rename (tmp, path_b); free (tmp); }
int pop3d_uidl (char *arg, struct pop3d_session *sess) { size_t mesgno; char uidl[128]; mu_message_t msg; mu_attribute_t attr; if (state != TRANSACTION) return ERR_WRONG_STATE; if (strchr (arg, ' ') != NULL) return ERR_BAD_ARGS; if (strlen (arg) == 0) { size_t total = 0; pop3d_outf ("+OK\n"); mu_mailbox_messages_count (mbox, &total); for (mesgno = 1; mesgno <= total; mesgno++) { mu_mailbox_get_message (mbox, mesgno, &msg); mu_message_get_attribute (msg, &attr); if (!pop3d_is_deleted (attr)) { mu_message_get_uidl (msg, uidl, sizeof (uidl), NULL); pop3d_outf ("%s %s\n", mu_umaxtostr (0, mesgno), uidl); } } pop3d_outf (".\n"); } else { mesgno = strtoul (arg, NULL, 10); if (mu_mailbox_get_message (mbox, mesgno, &msg) != 0) return ERR_NO_MESG; mu_message_get_attribute (msg, &attr); if (pop3d_is_deleted (attr)) return ERR_MESG_DELE; mu_message_get_uidl (msg, uidl, sizeof (uidl), NULL); pop3d_outf ("+OK %s %s\n", mu_umaxtostr (0, mesgno), uidl); } return OK; }
void mh_global_save_state () { mh_context_set_value (sequences, "cur", mu_umaxtostr (0, current_message)); mh_context_write (sequences); mh_context_set_value (context, "Current-Folder", current_folder); mh_context_write (context); }
void login_delay_capa () { DBM_FILE db; if (login_delay && open_stat_db (&db, MU_STREAM_RDWR) == 0) { pop3d_outf ("LOGIN-DELAY %s\r\n", mu_umaxtostr (0, login_delay)); mu_dbm_close (db); } }
int pop3d_stat (char *arg) { size_t mesgno; size_t size = 0; size_t lines = 0; size_t total = 0; size_t num = 0; size_t tsize = 0; mu_message_t msg = NULL; mu_attribute_t attr = NULL; if (strlen (arg) != 0) return ERR_BAD_ARGS; if (state != TRANSACTION) return ERR_WRONG_STATE; /* rfc1939: if the POP3 server host internally represents end-of-line as a single character, then the POP3 server simply counts each occurrence of this character in a message as two octets. */ mu_mailbox_messages_count (mbox, &total); for (mesgno = 1; mesgno <= total; mesgno++) { mu_mailbox_get_message (mbox, mesgno, &msg); mu_message_get_attribute (msg, &attr); /* rfc1939: Note that messages marked as deleted are not counted in either total. */ if (!pop3d_is_deleted (attr)) { mu_message_size (msg, &size); mu_message_lines (msg, &lines); tsize += size + lines; num++; } } pop3d_outf ("+OK %s %s\r\n", mu_umaxtostr (0, num), mu_umaxtostr (1, tsize)); return OK; }
/* Preprocess a part of a complex message designation. Returns a pointer to the allocated memory containing expanded part of the designation. Pointer to the beginning of the not expanded part (in arg) is placed into *rest */ static char * msgset_preproc_part (mu_mailbox_t mbox, char *arg, char **rest) { struct msgset_keyword *p; char *cp; for (p = keywords; p->name; p++) if (strncmp (arg, p->name, strlen (p->name)) == 0) { int rc; size_t uid, num; mu_message_t msg; if (p->handler (mbox, &num)) msgset_abort (arg); rc = mu_mailbox_get_message (mbox, num, &msg); if (rc) { mu_error (_("cannot get message %lu: %s"), (unsigned long) num, mu_strerror (rc)); exit (1); } *rest = arg + strlen (p->name); mu_message_get_uid (msg, &uid); return xstrdup (mu_umaxtostr (0, uid)); } cp = strchr (arg, '-'); if (cp) { char *ret; *rest = cp; ret = xmalloc (cp - arg + 1); memcpy (ret, arg, cp - arg); ret[cp - arg] = 0; return ret; } *rest = arg + strlen (arg); return strdup (arg); }
int check_draft_disposition (struct mh_whatnow_env *wh, int use_draft) { struct stat st; int disp = DISP_REPLACE; /* First check if the draft exists */ if (stat (wh->draftfile, &st) == 0) { if (use_draft) disp = DISP_USE; else { printf (ngettext ("Draft \"%s\" exists (%s byte).\n", "Draft \"%s\" exists (%s bytes).\n", (unsigned long) st.st_size), wh->draftfile, mu_umaxtostr (0, st.st_size)); disp = mh_disposition (wh->draftfile); } } return disp; }