1PublicInbox::Import(3)User Contributed Perl DocumentationPublicInbox::Import(3)
2
3
4
6 PublicInbox::Import - message importer for public-inbox v1 inboxes
7
9 version 1.0
10
12 use PublicInbox::Eml;
13 # PublicInbox::Eml exists as of public-inbox 1.5.0,
14 # Email::MIME was used in older versions
15
16 use PublicInbox::Git;
17 use PublicInbox::Import;
18
19 chomp(my $git_dir = `git rev-parse --git-dir`);
20 $git_dir or die "GIT_DIR= must be specified\n";
21 my $git = PublicInbox::Git->new($git_dir);
22 my @committer = ('inbox', 'inbox@example.org');
23 my $im = PublicInbox::Import->new($git, @committer);
24
25 # to add a message:
26 my $message = "From: <u\@example.org>\n".
27 "Subject: test message \n" .
28 "Date: Thu, 01 Jan 1970 00:00:00 +0000\n" .
29 "Message-ID: <m\@example.org>\n".
30 "\ntest message";
31 my $parsed = PublicInbox::Eml->new($message);
32 my $ret = $im->add($parsed);
33 if (!defined $ret) {
34 warn "duplicate: ", $parsed->header_raw('Message-ID'), "\n";
35 } else {
36 print "imported at mark $ret\n";
37 }
38 $im->done;
39
40 # to remove a message
41 my $junk = PublicInbox::Eml->new($message);
42 my ($mark, $orig) = $im->remove($junk);
43 if ($mark eq 'MISSING') {
44 print "not found\n";
45 } elsif ($mark eq 'MISMATCH') {
46 print "Message exists but does not match\n\n",
47 $orig->as_string, "\n",;
48 } else {
49 print "removed at mark $mark\n\n",
50 $orig->as_string, "\n";
51 }
52 $im->done;
53
55 An importer and remover for public-inboxes which takes
56 "PublicInbox::Eml" or Email::MIME messages as input and stores them in
57 a git repository as documented in
58 <https://public-inbox.org/public-inbox-v1-format.txt>, except it does
59 not allow duplicate Message-IDs.
60
61 It requires git(1) and git-fast-import(1) to be installed.
62
64 new
65 my $im = PublicInbox::Import->new($git, @committer);
66
67 Initialize a new PublicInbox::Import object.
68
69 add
70 my $parsed = PublicInbox::Eml->new($message);
71 $im->add($parsed);
72
73 Adds a message to to the git repository. This will acquire
74 "$GIT_DIR/ssoma.lock" and start git-fast-import(1) if necessary.
75
76 Messages added will not be visible to other processes until "done" is
77 called, but "remove" may be called on them.
78
79 remove
80 my $junk = PublicInbox::Eml->new($message);
81 my ($code, $orig) = $im->remove($junk);
82
83 Removes a message from the repository. On success, it returns a
84 ':'-prefixed numeric code representing the git-fast-import mark and the
85 original messages as a PublicInbox::Eml (or Email::MIME) object. If
86 the message could not be found, the code is "MISSING" and the original
87 message is undef. If there is a mismatch where the "Message-ID" is
88 matched but the subject and body do not match, the returned code is
89 "MISMATCH" and the conflicting message is returned as orig.
90
91 done
92 Finalizes the git-fast-import(1) and unlocks the repository. Calling
93 this is required to finalize changes to a repository.
94
96 Email::MIME
97
99 All feedback welcome via plain-text mail to
100 <mailto:meta@public-inbox.org>
101
102 The mail archives are hosted at <https://public-inbox.org/meta/>
103
105 Copyright (C) 2016-2020 all contributors <mailto:meta@public-inbox.org>
106
107 License: AGPL-3.0+ <http://www.gnu.org/licenses/agpl-3.0.txt>
108
109
110
111perl v5.38.0 2023-07-25 PublicInbox::Import(3)