| 538 | } |
| 539 | |
| 540 | func msgsAdd(be module.Storage, ctx *cli.Context) error { |
| 541 | username := ctx.Args().First() |
| 542 | if username == "" { |
| 543 | return cli.Exit("Error: USERNAME is required", 2) |
| 544 | } |
| 545 | name := ctx.Args().Get(1) |
| 546 | if name == "" { |
| 547 | return cli.Exit("Error: MAILBOX is required", 2) |
| 548 | } |
| 549 | |
| 550 | u, err := be.GetIMAPAcct(username) |
| 551 | if err != nil { |
| 552 | return err |
| 553 | } |
| 554 | |
| 555 | flags := ctx.StringSlice("flag") |
| 556 | if flags == nil { |
| 557 | flags = []string{} |
| 558 | } |
| 559 | |
| 560 | date := time.Now() |
| 561 | if ctx.IsSet("date") { |
| 562 | date = *ctx.Timestamp("date") |
| 563 | } |
| 564 | |
| 565 | buf := bytes.Buffer{} |
| 566 | if _, err := io.Copy(&buf, os.Stdin); err != nil { |
| 567 | return err |
| 568 | } |
| 569 | |
| 570 | if buf.Len() == 0 { |
| 571 | return cli.Exit("Error: Empty message, refusing to continue", 2) |
| 572 | } |
| 573 | |
| 574 | status, err := u.Status(name, []imap.StatusItem{imap.StatusUidNext}) |
| 575 | if err != nil { |
| 576 | return err |
| 577 | } |
| 578 | |
| 579 | if err := u.CreateMessage(name, flags, date, &buf, nil); err != nil { |
| 580 | return err |
| 581 | } |
| 582 | |
| 583 | // TODO: Use APPENDUID |
| 584 | fmt.Println(status.UidNext) |
| 585 | |
| 586 | return nil |
| 587 | } |
| 588 | |
| 589 | func msgsRemove(be module.Storage, ctx *cli.Context) error { |
| 590 | username := ctx.Args().First() |