~rjarry/aerc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4 4

[PATCH aerc v3 1/2] import-mbox: enable url import

Details
Message ID
<20241102214228.850424-1-koni.marti@gmail.com>
DKIM signature
pass
Download raw message
Patch: +47 -18
Enable the :import-mbox command to also import data from an URL.

Changelog-added: Enable `:import-mbox` to import data from an URL.
Suggested-by: Matěj Cepl <mcepl@cepl.eu>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
---
 commands/account/import-mbox.go | 53 +++++++++++++++++++++++----------
 doc/aerc.1.scd                  | 12 ++++++--
 2 files changed, 47 insertions(+), 18 deletions(-)

diff --git a/commands/account/import-mbox.go b/commands/account/import-mbox.go
index 85101bc2..208dec44 100644
--- a/commands/account/import-mbox.go
+++ b/commands/account/import-mbox.go
@@ -5,7 +5,9 @@ import (
	"errors"
	"fmt"
	"io"
	"net/http"
	"os"
	"regexp"
	"sync/atomic"
	"time"

@@ -19,7 +21,7 @@ import (
)

type ImportMbox struct {
	Filename string `opt:"filename" complete:"CompleteFilename" desc:"Input file path."`
	Path string `opt:"path" complete:"CompleteFilename" desc:"Input file path or URL."`
}

func init() {
@@ -57,21 +59,11 @@ func (i ImportMbox) Execute(args []string) error {
		return errors.New("No directory selected")
	}

	i.Filename = xdg.ExpandHome(i.Filename)

	importFolder := func() {
	importFolder := func(r io.ReadCloser) {
		defer log.PanicHandler()
		statusInfo := fmt.Sprintln("Importing", i.Filename, "to folder", folder)
		app.PushStatus(statusInfo, 10*time.Second)
		log.Debugf(statusInfo)
		f, err := os.Open(i.Filename)
		if err != nil {
			app.PushError(err.Error())
			return
		}
		defer f.Close()
		defer r.Close()

		messages, err := mboxer.Read(f)
		messages, err := mboxer.Read(r)
		if err != nil {
			app.PushError(err.Error())
			return
@@ -135,6 +127,33 @@ func (i ImportMbox) Execute(args []string) error {
		app.PushSuccess(infoStr)
	}

	var buf []byte

	path := i.Path
	if ok, err := regexp.MatchString("^(http[s]\\:|www\\.)", path); ok && err == nil {
		resp, err := http.Get(path)
		if err != nil {
			return err
		}
		buf, err = io.ReadAll(resp.Body)
		_ = resp.Body.Close()
		if err != nil {
			return err
		}
	} else {
		path = xdg.ExpandHome(path)
		buf, err = os.ReadFile(path)
		if err != nil {
			return err
		}
	}

	r := io.NopCloser(bytes.NewReader(buf))

	statusInfo := fmt.Sprintln("Importing", path, "to folder", folder)
	app.PushStatus(statusInfo, 10*time.Second)
	log.Debugf(statusInfo)

	if len(store.Uids()) > 0 {
		confirm := app.NewSelectorDialog(
			"Selected directory is not empty",
@@ -143,13 +162,15 @@ func (i ImportMbox) Execute(args []string) error {
			func(option string, err error) {
				app.CloseDialog()
				if option == "Yes" {
					go importFolder()
					go importFolder(r)
				} else {
					_ = r.Close()
				}
			},
		)
		app.AddDialog(confirm)
	} else {
		go importFolder()
		go importFolder(r)
	}

	return nil
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 575e2658..1facb0ea 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -656,8 +656,16 @@ message list, the message in the message viewer, etc).
	messages in the folder, only the marked ones are exported. Otherwise the
	whole folder is exported.

*:import-mbox* _<file>_
	Imports all messages from an mbox file to the current folder.
*:import-mbox* _<path>_
	Imports all messages from an mbox file to the current folder. _<path>_
	can either be a path to a file or an URL.

	Examples:

	```
	:import-mbox ~/messages.mbox
	:import-mbox https://lists.sr.ht/~rjarry/aerc-devel/patches/55634/mbox
	```

*:next-result*++
*:prev-result*
-- 
2.47.0

[PATCH aerc v3 2/2] import-mbox: unzip compressed mboxes

Details
Message ID
<20241102214228.850424-2-koni.marti@gmail.com>
In-Reply-To
<20241102214228.850424-1-koni.marti@gmail.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +17 -4
Unzip data when importing gzip compressed mbox files.

Suggested-by: diederich
Signed-off-by: Koni Marti <koni.marti@gmail.com>
---
 commands/account/import-mbox.go | 16 ++++++++++++++--
 doc/aerc.1.scd                  |  5 +++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/commands/account/import-mbox.go b/commands/account/import-mbox.go
index 208dec44..f2d6c3c5 100644
--- a/commands/account/import-mbox.go
+++ b/commands/account/import-mbox.go
@@ -2,6 +2,7 @@ package account

import (
	"bytes"
	"compress/gzip"
	"errors"
	"fmt"
	"io"
@@ -29,7 +30,7 @@ func init() {
}

func (ImportMbox) Description() string {
	return "Import all messages from an mbox file to the current folder."
	return "Import all messages from an (gzipped) mbox file to the current folder."
}

func (ImportMbox) Context() commands.CommandContext {
@@ -148,7 +149,18 @@ func (i ImportMbox) Execute(args []string) error {
		}
	}

	r := io.NopCloser(bytes.NewReader(buf))
	var r io.ReadCloser

	// detect gzip format compressed files as specified in RFC 1952
	if len(buf) >= 2 && buf[0] == 0x1f && buf[1] == 0x8b {
		var err error
		r, err = gzip.NewReader(bytes.NewReader(buf))
		if err != nil {
			return err
		}
	} else {
		r = io.NopCloser(bytes.NewReader(buf))
	}

	statusInfo := fmt.Sprintln("Importing", path, "to folder", folder)
	app.PushStatus(statusInfo, 10*time.Second)
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 1facb0ea..6de06175 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -657,14 +657,15 @@ message list, the message in the message viewer, etc).
	whole folder is exported.

*:import-mbox* _<path>_
	Imports all messages from an mbox file to the current folder. _<path>_
	can either be a path to a file or an URL.
	Imports all messages from an (gzipped) mbox file to the current folder.
	_<path>_ can either be a path to a file or an URL.

	Examples:

	```
	:import-mbox ~/messages.mbox
	:import-mbox https://lists.sr.ht/~rjarry/aerc-devel/patches/55634/mbox
	:import-mbox https://lore.kernel.org/all/20190807155524.5112-1-steve.capper@arm.com/t.mbox.gz
	```

*:next-result*++
-- 
2.47.0

[aerc/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D5C0SF64VR9X.QXEZMJ4I8YHG@fra01>
In-Reply-To
<20241102214228.850424-2-koni.marti@gmail.com> (view parent)
DKIM signature
missing
Download raw message
aerc/patches: SUCCESS in 2m13s

[import-mbox: enable url import][0] v3 from [Koni Marti][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/55781
[1]: koni.marti@gmail.com

✓ #1361453 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1361453
✓ #1361452 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1361452

Re: [PATCH aerc v3 2/2] import-mbox: unzip compressed mboxes

Details
Message ID
<D5EJGDBYKXHK.1PP69DC8MAE4G@ferdinandy.com>
In-Reply-To
<20241102214228.850424-2-koni.marti@gmail.com> (view parent)
DKIM signature
missing
Download raw message
On Sat Nov 02, 2024 at 22:40, Koni Marti <koni.marti@gmail.com> wrote:
> Unzip data when importing gzip compressed mbox files.
>
> Suggested-by: diederich
> Signed-off-by: Koni Marti <koni.marti@gmail.com>
> ---
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>



-- 
bence.ferdinandy.com

Applied: [PATCH aerc v3 1/2] import-mbox: enable url import

Details
Message ID
<173117445985.637400.17699541929992345674@ringo>
In-Reply-To
<20241102214228.850424-1-koni.marti@gmail.com> (view parent)
DKIM signature
pass
Download raw message
Koni Marti <koni.marti@gmail.com> wrote:
> Enable the :import-mbox command to also import data from an URL.
>
> Changelog-added: Enable `:import-mbox` to import data from an URL.
> Suggested-by: Matěj Cepl <mcepl@cepl.eu>
> Signed-off-by: Koni Marti <koni.marti@gmail.com>
> ---

Acked-by: Robin Jarry <robin@jarry.cc>

Applied, thanks.

To git@git.sr.ht:~rjarry/aerc
   434ca29c8f96..9039eba68d65  master -> master
Reply to thread Export thread (mbox)