102 lines
2.3 KiB
Go
102 lines
2.3 KiB
Go
|
|
/*
|
||
|
|
* Copyright (c) 2026 Kaiy Ragur
|
||
|
|
*
|
||
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||
|
|
*/
|
||
|
|
package remote
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
pb "github.com/neilalexander/yggmail/internal/remote/types"
|
||
|
|
)
|
||
|
|
|
||
|
|
func (s *RemoteStorage) MailboxList(pk string, onlySubscribed bool) ([]string, error) {
|
||
|
|
resp, _, err := s.Call(&pb.Request{
|
||
|
|
Call: &pb.Request_MboxList{
|
||
|
|
MboxList: &pb.MailboxListRequest{OnlySubscribed: onlySubscribed},
|
||
|
|
},
|
||
|
|
}, nil, 0)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if !resp.Success {
|
||
|
|
return nil, fmt.Errorf(resp.Error)
|
||
|
|
}
|
||
|
|
return resp.GetMboxList().Names, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *RemoteStorage) MailboxSelect(pk string, mailbox string) (bool, error) {
|
||
|
|
resp, _, err := s.Call(&pb.Request{
|
||
|
|
Call: &pb.Request_MboxStatus{
|
||
|
|
MboxStatus: &pb.MailboxStatusRequest{Name: mailbox},
|
||
|
|
},
|
||
|
|
}, nil, 0)
|
||
|
|
if err != nil {
|
||
|
|
return false, err
|
||
|
|
}
|
||
|
|
return resp.Success, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *RemoteStorage) MailboxCreate(pk string, name string) error {
|
||
|
|
resp, _, err := s.Call(&pb.Request{
|
||
|
|
Call: &pb.Request_MboxCreate{
|
||
|
|
MboxCreate: &pb.MailboxCreateRequest{Name: name},
|
||
|
|
},
|
||
|
|
}, nil, 0)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
if !resp.Success {
|
||
|
|
return fmt.Errorf(resp.Error)
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *RemoteStorage) MailboxDelete(pk string, name string) error {
|
||
|
|
resp, _, err := s.Call(&pb.Request{
|
||
|
|
Call: &pb.Request_MboxDelete{
|
||
|
|
MboxDelete: &pb.MailboxDeleteRequest{Name: name},
|
||
|
|
},
|
||
|
|
}, nil, 0)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
if !resp.Success {
|
||
|
|
return fmt.Errorf(resp.Error)
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *RemoteStorage) MailboxRename(pk string, old, new string) error {
|
||
|
|
resp, _, err := s.Call(&pb.Request{
|
||
|
|
Call: &pb.Request_MboxRename{
|
||
|
|
MboxRename: &pb.MailboxRenameRequest{OldName: old, NewName: new},
|
||
|
|
},
|
||
|
|
}, nil, 0)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
if !resp.Success {
|
||
|
|
return fmt.Errorf(resp.Error)
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *RemoteStorage) MailboxSubscribe(pk string, name string, subscribed bool) error {
|
||
|
|
resp, _, err := s.Call(&pb.Request{
|
||
|
|
Call: &pb.Request_MboxSub{
|
||
|
|
MboxSub: &pb.MailboxSubscribeRequest{Name: name, Subscribed: subscribed},
|
||
|
|
},
|
||
|
|
}, nil, 0)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
if !resp.Success {
|
||
|
|
return fmt.Errorf(resp.Error)
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|