• This repository has been archived on 09/Nov/2017
  • Stars
    star
    616
  • Rank 72,837 (Top 2 %)
  • Language
    Ruby
  • License
    GNU General Publi...
  • Created over 15 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

💀 Larch copies messages from one IMAP server to another. No longer maintained.

Larch

Note: I no longer actively develop or use Larch, so it is effectively unmaintained. Many people claim it still works well for them, so feel free to use it, but please don’t expect support, bug fixes, or new features.

Larch is a tool to copy messages from one IMAP server to another quickly and safely. It’s smart enough not to copy messages that already exist on the destination and robust enough to deal with interruptions caused by flaky connections or misbehaving servers.

Larch is particularly well-suited for copying email to, from, or between Gmail accounts.

Author

Ryan Grove ([email protected])

Version

1.1.2 (2013-01-24)

Copyright

Copyright © 2013 Ryan Grove. All rights reserved.

License

GPL 2.0 (opensource.org/licenses/gpl-2.0.php)

Website

github.com/rgrove/larch

Installation

Latest stable release:

gem install larch

Latest development version:

gem install larch --pre

Usage

larch [config section] [options]
larch --from <uri> --to <uri> [options]

Server Options:
         --from, -f <s>:   URI of the source IMAP server
  --from-folder, -F <s>:   Source folder to copy from (default: INBOX)
    --from-pass, -p <s>:   Source server password (default: prompt)
    --from-user, -u <s>:   Source server username (default: prompt)
           --to, -t <s>:   URI of the destination IMAP server
    --to-folder, -T <s>:   Destination folder to copy to (default: INBOX)
      --to-pass, -P <s>:   Destination server password (default: prompt)
      --to-user, -U <s>:   Destination server username (default: prompt)

Copy Options:
              --all, -a:   Copy all folders recursively
   --all-subscribed, -s:   Copy all subscribed folders recursively
           --delete, -d:   Delete messages from the source after copying
                           them, or if they already exist at the destination
         --exclude <s+>:   List of mailbox names/patterns that shouldn't be
                           copied
     --exclude-file <s>:   Filename containing mailbox names/patterns that
                           shouldn't be copied
          --expunge, -x:   Expunge deleted messages from the source
       --sync-flags, -S:   Sync message flags from the source to the
                           destination for messages that already exist at the
                           destination

General Options:
       --config, -c <s>:   Specify a non-default config file to use (default:
                           ~/.larch/config.yaml)
         --database <s>:   Specify a non-default message database to use
                           (default: ~/.larch/larch.db)
          --dry-run, -n:   Don't actually make any changes
      --max-retries <i>:   Maximum number of times to retry after a
                           recoverable error (default: 3)
     --no-create-folder:   Don't create destination folders that don't
                           already exist
        --ssl-certs <s>:   Path to a trusted certificate bundle to use to
                           verify server SSL certificates
           --ssl-verify:   Verify server SSL certificates
    --verbosity, -V <s>:   Output verbosity: debug, info, warn, error, or
                           fatal (default: info)
          --version, -v:   Print version and exit
             --help, -h:   Show this message

Usage Examples

Larch is run from the command line. The following examples demonstrate how to run Larch using only command line arguments, but you may also place these options in a config file and run Larch without any arguments if you prefer. See the “Configuration” section below for more details.

For an overview of all available options, run:

larch -h

At a minimum, you must specify a source server and a destination server in the form of IMAP URIs:

larch --from imap://mail.example.com --to imap://imap.gmail.com

Larch will prompt you for the necessary usernames and passwords, then sync the contents of the source’s INBOX folder to the destination’s INBOX folder.

To connect using SSL, specify a URI beginning with imaps://:

larch --from imaps://mail.example.com --to imaps://imap.gmail.com

If you’d like to sync a specific folder other than INBOX, specify the source and destination folders using --from-folder and --to-folder. Folder names containing spaces must be enclosed in quotes:

larch --from imaps://mail.example.com --to imaps://imap.gmail.com \
  --from-folder 'Sent Mail' --to-folder 'Sent Mail'

To sync all folders, use the --all option (or --all-subscribed if you only want to sync subscribed folders):

larch --from imaps://mail.example.com --to imaps://imap.gmail.com --all

By default Larch will create folders on the destination server if they don’t already exist. To prevent this, add the --no-create-folder option:

larch --from imaps://mail.example.com --to imaps://imap.gmail.com --all \
  --no-create-folder

You can prevent Larch from syncing one or more folders by using the --exclude option, which accepts multiple arguments:

larch --from imaps://mail.example.com --to imaps://imap.gmail.com --all \
  --exclude Spam Trash Drafts "[Gmail]/*"

If your exclusion list is long or complex, create a text file with one exclusion pattern per line and tell Larch to load it with the --exclude-file option:

larch --from imaps://mail.example.com --to imaps://imap.gmail.com --all \
  --exclude-file exclude.txt

The wildcard characters * and ? are supported in exclusion lists. You may also use a regular expression by enclosing a pattern in forward slashes, so the previous example could be achieved with the pattern /(Spam|Trash|Drafts|\[Gmail\]\/.*)/

Configuration

While it’s possible to control Larch entirely from the command line, this can be inconvenient if you need to specify a lot of options or if you run Larch frequently and can’t always remember which options to use. Using a configuration file can simplify things.

By default, Larch looks for a config file at ~/.larch/config.yaml and uses it if found. You may specify a custom config file using the --config command line option.

The Larch configuration file is a simple YAML file that may contain multiple sections, each with a different set of options, as well as a special default section. The options in the default section will be used unless they’re overridden either in another config section or on the command line.

Example

Here’s a sample Larch config file:

default:
  all-subscribed: true # Copy all subscribed folders by default

# Copy mail from Gmail to my server, excluding stuff I don't want.
gmail to my server:
  from: imaps://imap.gmail.com
  from-user: example
  from-pass: secret

  to: imaps://mail.example.com
  to-user: example
  to-pass: secret

  exclude:
    - "[Gmail]/Sent Mail"
    - "[Gmail]/Spam"
    - "[Gmail]/Trash"

# Copy mail from my INBOX to Gmail's INBOX
my inbox to gmail inbox:
  all-subscribed: false

  from: imaps://mail.example.com
  from-folder: INBOX
  from-user: example
  from-pass: secret

  to: imaps://imap.gmail.com
  to-folder: INBOX
  to-user: example
  to-pass: secret

This file contains three sections. The options from default will be used in all other sections as well unless they’re overridden.

To specify which config section you want Larch to use, just pass its name on the command line (use quotes if the name contains spaces):

larch 'gmail to my server'

If you specify additional command line options, they’ll override options in the config file:

larch 'gmail to my server' --from-user anotheruser

Running Larch with no command line arguments will cause the default section to be used. With the example above, this will result in an error since the default section doesn’t contain the required from and to options, but if you only need to use Larch with a single configuration, you could use the default section for everything and save yourself some typing on the command line.

Server Compatibility

Larch should work well with any server that properly supports IMAP4rev1, and does its best to get along with servers that have buggy, unreliable, or incomplete IMAP implementations.

Larch has been tested on and is known to work well with the following IMAP servers:

  • Dovecot

  • Gmail

  • Microsoft Exchange 2003

The following servers are known to work, but with caveats:

  • Yahoo! Mail

The following servers do not work well with Larch:

  • BlitzMail - Buggy server implementation; fails to properly quote or escape some IMAP responses, which can cause Net::IMAP to hang waiting for a terminating character that will never arrive.

Gmail Quirks

Gmail’s IMAP implementation is quirky. Larch does its best to work around these quirks whenever possible, but here are a few things to watch out for:

“Some messages could not be FETCHed” error

This error indicates that a message on Gmail is corrupt, and Gmail itself is unable to read it. The message will continue to show up in the mailbox, but all attempts to access it via IMAP, POP, or the Gmail web interface will result in errors. Larch will try to skip these messages and continue processing others if possible.

It’s not clear how this corruption occurs or exactly what kind of corruption causes these errors, although in every case I’m aware of, the corrupt message has originated outside of Gmail (Gmail itself does not corrupt the message). There is currently no known solution for this problem apart from deleting the corrupted messages.

Folder names cannot contain leading or trailing whitespace

Most IMAP servers allow folder names to contain leading and trailing whitespace, such as “ folder ”. Gmail does not. When copying folders to Gmail, Larch will automatically remove leading and trailing whitespace in folder names to prevent errors.

Yahoo! Mail Quirks

Yahoo! doesn’t officially support IMAP access for general usage, but Larch is able to connect to imap.mail.yahoo.com and imap-ssl.mail.yahoo.com by using a fairly well-known trick. That said, as with anything tricky, there are caveats.

No hierarchical folders

Similar to Gmail, Yahoo! Mail doesn’t allow hierarchical (nested) folders. If you try to copy a folder hierarchy to Yahoo!, it will work, but you’ll end up with a set of folders named “folder” and “folder.subfolder” rather than seeing “subfolder” as an actual subfolder of “folder”.

No custom flags

Yahoo! Mail IMAP doesn’t support custom message flags, such as the tags and junk/not junk flags used by Thunderbird. When transferring messages with custom flags to a Yahoo! Mail IMAP account, the custom flags will be lost.

Here there be dragons

Larch’s support for Yahoo! Mail is very new and very lightly tested. Given its newness and the fact that Yahoo!‘s IMAP gateway isn’t official, there are likely to be other quirks we’re not yet aware of. There’s also no guarantee that Yahoo! won’t shut down its IMAP gateway, deprecate the trick Larch uses to connect, or just outright block Larch. Use at your own risk.

Known Issues

  • Larch uses Ruby’s Net::IMAP standard library for all IMAP operations. While Net::IMAP is generally a very solid library, it contains a bug that can cause a deadlock to occur if a connection drops unexpectedly (either due to network issues or because the server closed the connection without warning) when the server has already begun sending a response and Net::IMAP is waiting to receive more data. If this happens, Net::IMAP will continue waiting forever without passing control back to Larch, and you will need to manually kill and restart Larch.

    Net::IMAP in Ruby 1.8 has also been known to hang when it can’t parse a server response, either because the response itself is malformed or because of a bug in Net::IMAP’s parser. This is rare, but it happens. Unfortunately there’s nothing Larch can do about this.

  • The Ruby package on Debian, Ubuntu, and some other Debian-based Linux distributions doesn’t include the OpenSSL standard library. If you see an error like uninitialized constant Larch::IMAP::OpenSSL (NameError) when running Larch, you may need to install the libopenssl-ruby package. Please feel free to complain to the maintainer of your distribution’s Ruby packages.

Support

The Larch mailing list is the best place for questions, comments, and discussion about Larch. You can join the list or view the archives at groups.google.com/group/larch

First-time senders to the list are moderated to prevent spam, so there may be a delay before your first message shows up.

Contributors

Larch was created and is maintained by Ryan Grove <[email protected]>.

The following lovely people have also contributed to Larch:

Credit

The Larch::IMAP class borrows heavily from Sup by William Morgan, the source code of which should be required reading if you’re doing anything with IMAP in Ruby.

Larch uses the excellent Trollop command-line option parser (also by William Morgan) and the HighLine command-line IO library (by James Edward Gray II).

License

Copyright © 2013 Ryan Grove <[email protected]>

Licensed under the GNU General Public License version 2.0.

This program is free software; you can redistribute it and/or modify it under the terms of version 2.0 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, visit www.gnu.org/licenses/old-licenses/gpl-2.0.txt or write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

More Repositories

1

rawgit

Served files from raw.githubusercontent.com, but with the correct content types. No longer actively developed.
JavaScript
2,390
star
2

sanitize

Ruby HTML and CSS sanitizer.
HTML
2,020
star
3

lazyload

💀 An ancient tiny JS and CSS loader from the days before everyone had written one. Unmaintained.
JavaScript
1,391
star
4

jsmin-php

💀 PHP port of Douglas Crockford's JSMin JavaScript minifier. No longer maintained.
PHP
423
star
5

parse-xml

A fast, safe, compliant XML parser for Node.js and browsers.
JavaScript
259
star
6

crass

A Ruby CSS parser that's fully compliant with the CSS Syntax Level 3 specification.
Ruby
139
star
7

combohandler

A simple Yahoo!-style combo handler in Node.js.
JavaScript
116
star
8

node-elastical

💀 Elastical has moved to https://github.com/ramv/node-elastical and this repo is no longer maintained. Please update your bookmarks!
JavaScript
101
star
9

thoth

💀 An unmaintained and probably broken Ruby blog engine.
Ruby
67
star
10

emergencykitten

Sometimes you just need a kitten.
JavaScript
66
star
11

jsmin

💀 Ruby library for minifying JavaScript. Based on Douglas Crockford's jsmin.c. Unmaintained.
JavaScript
51
star
12

textual-sulaco

Sulaco, a style for the Textual IRC client
HTML
44
star
13

synchrotron

Watches a local directory and syncs files to another directory or a remote destination using rsync whenever changes occur.
JavaScript
40
star
14

cssmin

💀 Ruby library for minifying CSS. Unmaintained.
Ruby
38
star
15

selleck

💀 Now maintained at https://github.com/yui/selleck
JavaScript
38
star
16

storage-lite

💀 Lightweight YUI 3 API for persistent cross-browser key/value storage similar to the HTML5 localStorage API. Unmaintained.
JavaScript
29
star
17

pie.gd

Config files, scripts, and documentation for the pie.gd Mastodon instance.
Dockerfile
23
star
18

lectroid

💀 A really boring blog engine. Unmaintained.
JavaScript
17
star
19

cachetest

💀 A Sinatra app for testing browser cache characteristics. Unmaintained.
Ruby
16
star
20

trogdor

💀 A fast, simple search-as-you-type implementation in JavaScript using the Yahoo! Search BOSS API. Unmaintained.
JavaScript
16
star
21

jslib-stats

💀 Node.js-based crawler that gathers JavaScript library usage stats by executing and inspecting JS. Unmaintained.
JavaScript
12
star
22

vim-yui3

💀 Vim syntax for YUI3. Unmaintained.
JavaScript
11
star
23

yuitweets

💀 A Bayesian tweet classifier that can learn the difference between tweets about the YUI Library and tweets about J-pop idols named Yui. Unmaintained.
Ruby
10
star
24

node-tokeninput

💀 YUI 3 Node plugin that turns a text input field into a tokenized input field similar to Cocoa's NSTokenField control. Unmaintained.
JavaScript
6
star
25

javascript-yui3.tmbundle

💀 TextMate bundle for YUI 3. Unmaintained.
JavaScript
6
star
26

denyssh

💀 Blocks SSH brute force attacks using PF. Unmaintained.
Ruby
5
star
27

tweetslurp

💀 Backs up tweets to a JSON file. Unmaintained.
JavaScript
4
star
28

jshint

💀 The Kinder, Gentler JavaScript Code Quality Tool
JavaScript
3
star
29

crackup

💀 Crappy remote backup. Unmaintained.
Ruby
3
star
30

sanitize-web

A super simple web interface to Sanitize, mostly for testing purposes.
HTML
3
star
31

sandbox

💀 YUI 3 module that simplifies the process of creating isolated iframe sandboxes in which to evaluate JavaScript code for tasks like profiling or unit testing. Unmaintained.
JavaScript
2
star
32

jetpants

💀
JavaScript
2
star
33

weld

💀 Combines and minifies CSS and JavaScript files at runtime and build time. Unmaintained.
Ruby
2
star
34

sniffle

💀 CLI app that learns and identifies user agent strings using a Redis-backed naive Bayes classifier. Just a silly experiment. Unmaintained.
JavaScript
2
star
35

denyspam

💀 Monitors a mail server log file and uses a firewall to temporarily block or redirect incoming packets from hosts that display spammer-like behavior. Unmaintained.
1
star
36

parse-xml-benchmark

Benchmarks for @rgrove/parse-xml
JavaScript
1
star