Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
imap-clean
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
tools
imap-clean
Commits
a9d33696
Commit
a9d33696
authored
2 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add a move-to-trash option for GMail compat
parent
07bc4fe8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
imap_clean.go
+24
-6
24 additions, 6 deletions
imap_clean.go
with
24 additions
and
6 deletions
imap_clean.go
+
24
−
6
View file @
a9d33696
...
...
@@ -27,6 +27,7 @@ var (
folder
=
flag
.
String
(
"folder"
,
"INBOX"
,
"remote IMAP folder"
)
verbose
=
flag
.
Bool
(
"verbose"
,
false
,
"print additional debug messages"
)
batchSize
=
flag
.
Int
(
"batch-size"
,
100
,
"deletion batch size"
)
moveToTrash
=
flag
.
Bool
(
"move-to-gmail-trash"
,
false
,
"move messages to Trash folder before deleting them (GMail workaround)"
)
)
func
vlog
(
fmt
string
,
args
...
interface
{})
{
...
...
@@ -106,6 +107,28 @@ func uidBatch(c *client.Client, uids []uint32, f func([]uint32) error) error {
return
nil
}
func
actuallyDelete
(
c
*
client
.
Client
,
uids
*
imap
.
SeqSet
)
error
{
// Do the GMail move-to-Trash dance.
if
*
moveToTrash
{
if
err
:=
c
.
UidStore
(
uids
,
"+X-GM-LABELS"
,
[]
interface
{}{
"
\\
Trash"
},
nil
,
);
err
!=
nil
{
return
err
}
}
// Just set the \\Deleted flag as one normally would.
return
c
.
UidStore
(
uids
,
imap
.
FormatFlagsOp
(
imap
.
AddFlags
,
true
),
[]
interface
{}{
imap
.
DeletedFlag
},
nil
,
)
}
func
main
()
{
log
.
SetFlags
(
0
)
flag
.
Parse
()
...
...
@@ -146,12 +169,7 @@ func main() {
}
vlog
(
"deleting %d messages..."
,
len
(
uids
))
return
c
.
UidStore
(
set
,
imap
.
FormatFlagsOp
(
imap
.
AddFlags
,
true
),
[]
interface
{}{
imap
.
DeletedFlag
},
nil
,
)
return
actuallyDelete
(
c
,
set
)
})
if
err
!=
nil
{
log
.
Fatalf
(
"delete error: %v"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment