mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +00:00
fix pagination
This commit is contained in:
parent
3d702677b5
commit
409e25fc4d
|
@ -39,7 +39,7 @@ fn reply_all_arg<'a>() -> Arg<'a, 'a> {
|
|||
}
|
||||
|
||||
fn page_size_arg<'a>() -> Arg<'a, 'a> {
|
||||
Arg::with_name("size")
|
||||
Arg::with_name("page-size")
|
||||
.help("Page size")
|
||||
.short("s")
|
||||
.long("size")
|
||||
|
@ -164,16 +164,15 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
let output_fmt = matches.value_of("output").unwrap();
|
||||
let mbox = matches.value_of("mailbox").unwrap();
|
||||
|
||||
loop {
|
||||
if let Some(matches) = matches.subcommand_matches("messages") {
|
||||
if let Some(matches) = matches.subcommand_matches("list") {
|
||||
let mut imap_conn = ImapConnector::new(&account)?;
|
||||
let page_size: usize = matches.value_of("size").unwrap().parse().unwrap();
|
||||
let page_size: usize = matches.value_of("page-size").unwrap().parse().unwrap();
|
||||
let page: usize = matches.value_of("page").unwrap().parse().unwrap();
|
||||
let msgs = imap_conn.list_msgs(&mbox, &page_size, &page)?;
|
||||
let msgs = Msgs::from(&msgs);
|
||||
print(&output_fmt, msgs)?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("search") {
|
||||
|
@ -208,7 +207,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
let msgs = Msgs::from(&msgs);
|
||||
print(&output_fmt, msgs)?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("read") {
|
||||
|
@ -219,7 +218,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
let msg = ReadableMsg::from_bytes(&mime, &msg)?;
|
||||
print(&output_fmt, msg)?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("attachments") {
|
||||
|
@ -256,7 +255,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
_ => (),
|
||||
}
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("write") {
|
||||
|
@ -298,7 +297,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
}
|
||||
}
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("template") {
|
||||
|
@ -329,7 +328,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
imap_conn.logout();
|
||||
}
|
||||
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("reply") {
|
||||
|
@ -378,8 +377,9 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
Err(err) => eprintln!("{}", err),
|
||||
}
|
||||
}
|
||||
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("forward") {
|
||||
|
@ -422,8 +422,9 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
Err(err) => eprintln!("{}", err),
|
||||
}
|
||||
}
|
||||
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("copy") {
|
||||
|
@ -435,7 +436,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
flags.push(Flag::Seen);
|
||||
imap_conn.append_msg(target, &msg.to_vec()?, &flags)?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("move") {
|
||||
|
@ -448,7 +449,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
imap_conn.append_msg(target, &msg.to_vec()?, msg.flags.deref())?;
|
||||
imap_conn.add_flags(mbox, uid, "\\Seen \\Deleted")?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("delete") {
|
||||
|
@ -456,7 +457,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
let uid = matches.value_of("uid").unwrap();
|
||||
imap_conn.add_flags(mbox, uid, "\\Seen \\Deleted")?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("send") {
|
||||
|
@ -467,7 +468,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
smtp::send(&account, &msg)?;
|
||||
imap_conn.append_msg("Sent", &msg.formatted(), &[Flag::Seen])?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("save") {
|
||||
|
@ -476,18 +477,14 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
|||
let msg = Msg::from(msg.to_string());
|
||||
imap_conn.append_msg(mbox, &msg.to_vec()?, &[Flag::Seen])?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Default case: list all messages
|
||||
|
||||
// Default case: list first page messages
|
||||
let mut imap_conn = ImapConnector::new(&account)?;
|
||||
let msgs = imap_conn.list_msgs(&mbox, &10, &0)?;
|
||||
let msgs = Msgs::from(&msgs);
|
||||
print(&output_fmt, msgs)?;
|
||||
imap_conn.logout();
|
||||
break;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ function! himalaya#msg#list()
|
|||
let buftype = stridx(bufname("%"), "Himalaya messages") == 0 ? "file" : "edit"
|
||||
execute printf("silent! %s Himalaya messages [%s] [page %d]", buftype, mbox, page + 1)
|
||||
setlocal modifiable
|
||||
execute "%d"
|
||||
silent execute "%d"
|
||||
call append(0, s:render("list", msgs))
|
||||
execute "$d"
|
||||
silent execute "$d"
|
||||
setlocal filetype=himalaya-msg-list
|
||||
let &modified = 0
|
||||
execute 0
|
||||
|
@ -48,9 +48,9 @@ function! himalaya#msg#read()
|
|||
let attachment = msg.hasAttachment ? " []" : ""
|
||||
execute printf("silent! edit Himalaya read message [%d]%s", s:msg_id, attachment)
|
||||
setlocal modifiable
|
||||
execute "%d"
|
||||
silent execute "%d"
|
||||
call append(0, split(substitute(msg.content, "\r", "", "g"), "\n"))
|
||||
execute "$d"
|
||||
silent execute "$d"
|
||||
setlocal filetype=himalaya-msg-read
|
||||
let &modified = 0
|
||||
execute 0
|
||||
|
@ -66,7 +66,7 @@ function! himalaya#msg#write()
|
|||
let msg = s:cli("template new", [], "Fetching new template")
|
||||
silent! edit Himalaya write
|
||||
call append(0, split(substitute(msg.template, "\r", "", "g"), "\n"))
|
||||
execute "$d"
|
||||
silent execute "$d"
|
||||
setlocal filetype=himalaya-msg-write
|
||||
let &modified = 0
|
||||
execute 0
|
||||
|
@ -84,7 +84,7 @@ function! himalaya#msg#reply()
|
|||
let msg = s:cli("--mailbox %s template reply %d", [shellescape(mbox), msg_id], "Fetching reply template")
|
||||
execute printf("silent! edit Himalaya reply [%d]", msg_id)
|
||||
call append(0, split(substitute(msg.template, "\r", "", "g"), "\n"))
|
||||
execute "$d"
|
||||
silent execute "$d"
|
||||
setlocal filetype=himalaya-msg-write
|
||||
let &modified = 0
|
||||
execute 0
|
||||
|
@ -102,7 +102,7 @@ function! himalaya#msg#reply_all()
|
|||
let msg = s:cli("--mailbox %s template reply %d --all", [shellescape(mbox), msg_id], "Fetching reply all template")
|
||||
execute printf("silent! edit Himalaya reply all [%d]", msg_id)
|
||||
call append(0, split(substitute(msg.template, "\r", "", "g"), "\n"))
|
||||
execute "$d"
|
||||
silent execute "$d"
|
||||
setlocal filetype=himalaya-msg-write
|
||||
let &modified = 0
|
||||
execute 0
|
||||
|
@ -120,7 +120,7 @@ function! himalaya#msg#forward()
|
|||
let msg = s:cli("--mailbox %s template forward %d", [shellescape(mbox), msg_id], "Fetching forward template")
|
||||
execute printf("silent! edit Himalaya forward [%d]", msg_id)
|
||||
call append(0, split(substitute(msg.template, "\r", "", "g"), "\n"))
|
||||
execute "$d"
|
||||
silent execute "$d"
|
||||
setlocal filetype=himalaya-msg-write
|
||||
let &modified = 0
|
||||
execute 0
|
||||
|
|
Loading…
Reference in a new issue