fix and recompile
This commit is contained in:
332
README.md
332
README.md
@@ -11,6 +11,9 @@ Email migration tools untuk memindahkan mailbox IMAP antar server dengan dukunga
|
||||
- ✅ **Mailbox Detection**: Otomatis detect dan migrate semua mailbox/folder
|
||||
- ✅ **Batch Processing**: Proses message dalam batch untuk efisiensi
|
||||
- ✅ **Error Handling**: Robust error handling dengan retry logic
|
||||
- ✅ **Authentication Support**: LOGIN dan AUTHENTICATE PLAIN methods
|
||||
- ✅ **Special Characters**: Support password dengan karakter khusus
|
||||
- ✅ **Debug Mode**: Detailed logging untuk troubleshooting
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -33,207 +36,222 @@ Download binary dari releases page atau build sendiri.
|
||||
|
||||
```bash
|
||||
# Basic migration
|
||||
./mail-migrator --src "user1:pass1@imap.old.com:993" \
|
||||
--dst "user1:pass1@imap.new.com:993"
|
||||
./mail-migrator --src "user@domain.com:password@imap.source.com:993" \
|
||||
--dst "user@domain.com:password@imap.dest.com:993" \
|
||||
--insecure
|
||||
|
||||
# With insecure mode (trust self-signed certs)
|
||||
./mail-migrator --src "user1:pass1@imap.old.com:993" \
|
||||
--dst "user1:pass1@imap.new.com:993" \
|
||||
--insecure
|
||||
# With logging
|
||||
./mail-migrator --src "user@domain.com:password@imap.source.com:993" \
|
||||
--dst "user@domain.com:password@imap.dest.com:993" \
|
||||
--insecure --log migration.log
|
||||
|
||||
# With resume support and logging
|
||||
./mail-migrator --src "user1:pass1@imap.old.com:993" \
|
||||
--dst "user1:pass1@imap.new.com:993" \
|
||||
--insecure \
|
||||
--resume \
|
||||
--log migration.log
|
||||
# With resume support
|
||||
./mail-migrator --src "user@domain.com:password@imap.source.com:993" \
|
||||
--dst "user@domain.com:password@imap.dest.com:993" \
|
||||
--insecure --resume --log migration.log
|
||||
```
|
||||
|
||||
### Batch Migration
|
||||
|
||||
Buat file CSV dengan format: `source,destination`
|
||||
|
||||
**accounts.csv:**
|
||||
1. **Buat file CSV** (contoh: `accounts.csv`):
|
||||
```csv
|
||||
user1:pass1@old.com:993,user1:newpass1@new.com:993
|
||||
user2:pass2@old.com:993,user2:newpass2@new.com:993
|
||||
user3:pass3@old.com:993,user3:newpass3@new.com:993
|
||||
user1@domain.com:password1@imap.source.com:993,user1@domain.com:password1@imap.dest.com:993
|
||||
user2@domain.com:password2@imap.source.com:993,user2@domain.com:password2@imap.dest.com:993
|
||||
info@trieltree.co.id:P@ssw0rd123@10.10.11.30:993,info@trieltree.co.id:P@ssw0rd123@10.10.11.24:993
|
||||
```
|
||||
|
||||
2. **Jalankan batch migration**:
|
||||
```bash
|
||||
# Batch migration
|
||||
./mail-migrator --batch accounts.csv --insecure --resume --log batch.log
|
||||
./mail-migrator --batch accounts.csv --insecure --resume --log migration.log
|
||||
```
|
||||
|
||||
## URL Format
|
||||
|
||||
Format URL untuk source dan destination:
|
||||
```
|
||||
username:password@hostname:port
|
||||
```
|
||||
|
||||
### Contoh:
|
||||
- `user@domain.com:mypassword@mail.server.com:993`
|
||||
- `info@trieltree.co.id:P@ssw0rd123@10.10.11.30:993`
|
||||
|
||||
### Password dengan Karakter Khusus
|
||||
|
||||
Jika password mengandung karakter khusus (`@`, `:`, `/`, dll), gunakan URL encoding:
|
||||
- `@` → `%40`
|
||||
- `:` → `%3A`
|
||||
- `/` → `%2F`
|
||||
- `%` → `%25`
|
||||
|
||||
**Contoh:**
|
||||
```bash
|
||||
# Password: P@ssw0rd:123/test
|
||||
# URL encoded: P%40ssw0rd%3A123%2Ftest
|
||||
./mail-migrator --src "user:P%40ssw0rd%3A123%2Ftest@server:993" \
|
||||
--dst "user:P%40ssw0rd%3A123%2Ftest@server:993" \
|
||||
--insecure
|
||||
```
|
||||
|
||||
## Command Line Options
|
||||
|
||||
| Flag | Description | Default |
|
||||
|------|-------------|---------|
|
||||
| `--src` | Source IMAP URL (user:pass@host:port) | - |
|
||||
| `--dst` | Destination IMAP URL (user:pass@host:port) | - |
|
||||
| `--batch` | CSV file with src,dst entries for batch migration | - |
|
||||
| `--insecure` | Allow insecure TLS (trust self-signed certs) | false |
|
||||
| `--resume` | Resume incomplete migrations | false |
|
||||
| `--state` | Path to state DB (Bolt) | state.db |
|
||||
| `--log` | Path to log file (optional) | - |
|
||||
|
||||
## URL Format
|
||||
|
||||
IMAP URL format: `username:password@hostname:port`
|
||||
|
||||
**Examples:**
|
||||
- `john:secret123@mail.example.com:993` (IMAPS)
|
||||
- `jane:mypass@imap.gmail.com:993` (Gmail)
|
||||
- `user@domain.com:password@mail.server.com:143` (IMAP plain)
|
||||
|
||||
**Port defaults:**
|
||||
- Port 993: IMAPS (TLS/SSL)
|
||||
- Port 143: IMAP (plain/STARTTLS)
|
||||
|
||||
## Resume Functionality
|
||||
|
||||
Aplikasi menggunakan BoltDB untuk menyimpan state migrasi:
|
||||
|
||||
- **State Key**: `source|destination|mailbox`
|
||||
- **Tracking**: Last migrated UID per mailbox
|
||||
- **Resume**: Otomatis lanjut dari UID terakhir yang sukses
|
||||
- **File**: Default `state.db` (bisa diubah dengan `--state`)
|
||||
|
||||
## Logging
|
||||
|
||||
- **Console**: Selalu aktif dengan timestamp
|
||||
- **File**: Optional dengan flag `--log filename.log`
|
||||
- **Format**: `[timestamp] [level] message`
|
||||
- **Levels**: INFO, WARN, ERROR, DEBUG
|
||||
|
||||
## Error Handling
|
||||
|
||||
- **Connection errors**: Retry dengan backoff
|
||||
- **Authentication**: Clear error message
|
||||
- **Mailbox errors**: Skip dan lanjut ke mailbox berikutnya
|
||||
- **Message errors**: Skip message yang corrupt, lanjut ke berikutnya
|
||||
- **Batch errors**: Error di satu akun tidak stop seluruh batch
|
||||
|
||||
## Performance
|
||||
|
||||
- **Batch size**: 50 messages per batch (configurable dalam code)
|
||||
- **Memory**: Efficient streaming untuk message besar
|
||||
- **Concurrent**: Single-threaded untuk stability
|
||||
- **Resume**: Minimal overhead dengan UID tracking
|
||||
| `--src` | Source IMAP URL | Required |
|
||||
| `--dst` | Destination IMAP URL | Required |
|
||||
| `--batch` | CSV file untuk batch migration | - |
|
||||
| `--insecure` | Skip SSL certificate verification | false |
|
||||
| `--resume` | Resume interrupted migration | false |
|
||||
| `--log` | Log file path | - |
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
### 1. Authentication Failed
|
||||
|
||||
**1. Certificate Errors**
|
||||
```
|
||||
x509: certificate signed by unknown authority
|
||||
```
|
||||
**Solution**: Gunakan flag `--insecure`
|
||||
**Error**: `LOGIN Authentication failed`
|
||||
|
||||
**2. Authentication Failed**
|
||||
```
|
||||
login failed: Invalid credentials
|
||||
```
|
||||
**Solution**:
|
||||
- Cek username/password
|
||||
- Untuk Gmail: gunakan App Password, bukan password biasa
|
||||
- Cek apakah IMAP enabled di server
|
||||
**Solusi**:
|
||||
1. **Pastikan credential benar**:
|
||||
```bash
|
||||
# Test dengan IMAP test tool
|
||||
cd tools
|
||||
go build -o imap-test.exe imap-test.go
|
||||
./imap-test.exe <host> <port> <username> <password>
|
||||
```
|
||||
|
||||
**3. Connection Timeout**
|
||||
```
|
||||
dial failed: i/o timeout
|
||||
```
|
||||
**Solution**:
|
||||
- Cek hostname dan port
|
||||
- Cek firewall/network connectivity
|
||||
- Cek apakah server support IMAP
|
||||
2. **Coba format username berbeda**:
|
||||
- `username` (tanpa domain)
|
||||
- `username@domain.com` (dengan domain)
|
||||
- `username@mail.domain.com` (dengan subdomain)
|
||||
|
||||
**4. Mailbox Not Found**
|
||||
```
|
||||
select source INBOX: Mailbox doesn't exist
|
||||
```
|
||||
**Solution**:
|
||||
- Cek apakah mailbox ada di source
|
||||
- Beberapa server case-sensitive untuk nama mailbox
|
||||
3. **Periksa server capabilities**:
|
||||
- Tool akan otomatis mencoba LOGIN dan AUTHENTICATE PLAIN
|
||||
- Check log untuk melihat supported authentication methods
|
||||
|
||||
### Debug Mode
|
||||
### 2. SSL Certificate Error
|
||||
|
||||
Untuk debug lebih detail, edit code dan set:
|
||||
```go
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
**Error**: `certificate verify failed`
|
||||
|
||||
**Solusi**:
|
||||
```bash
|
||||
# Gunakan flag --insecure untuk self-signed certificates
|
||||
./mail-migrator --src "..." --dst "..." --insecure
|
||||
```
|
||||
|
||||
### 3. Connection Timeout
|
||||
|
||||
**Error**: `connection timeout`
|
||||
|
||||
**Solusi**:
|
||||
1. **Test koneksi manual**:
|
||||
```bash
|
||||
telnet <hostname> <port>
|
||||
# atau
|
||||
openssl s_client -connect <hostname>:<port>
|
||||
```
|
||||
|
||||
2. **Periksa firewall dan network**
|
||||
3. **Pastikan port benar** (biasanya 993 untuk IMAPS, 143 untuk IMAP)
|
||||
|
||||
### 4. Resume Migration
|
||||
|
||||
Jika migration terputus, gunakan `--resume` untuk melanjutkan:
|
||||
```bash
|
||||
./mail-migrator --src "..." --dst "..." --resume --log migration.log
|
||||
```
|
||||
|
||||
State disimpan di file `state.db` menggunakan BoltDB.
|
||||
|
||||
### 5. Debug Mode
|
||||
|
||||
Untuk troubleshooting detail, check log file atau console output:
|
||||
```bash
|
||||
./mail-migrator --src "..." --dst "..." --log debug.log
|
||||
```
|
||||
|
||||
Log akan menampilkan:
|
||||
- Server capabilities
|
||||
- Authentication attempts
|
||||
- Message copy progress
|
||||
- Error details
|
||||
|
||||
## Tools
|
||||
|
||||
### IMAP Test Tool
|
||||
|
||||
Tool untuk test koneksi dan authentication IMAP:
|
||||
|
||||
```bash
|
||||
cd tools
|
||||
go build -o imap-test.exe imap-test.go
|
||||
./imap-test.exe <host> <port> <username> <password>
|
||||
```
|
||||
|
||||
**Contoh**:
|
||||
```bash
|
||||
./imap-test.exe 10.10.11.30 993 info@trieltree.co.id P@ssw0rd123
|
||||
```
|
||||
|
||||
Tool ini akan:
|
||||
- Test koneksi SSL/TLS
|
||||
- Tampilkan server capabilities
|
||||
- Test berbagai format username
|
||||
- Memberikan feedback detail untuk troubleshooting
|
||||
|
||||
## Examples
|
||||
|
||||
### Gmail to Gmail
|
||||
### Contoh Sukses Migration
|
||||
|
||||
```bash
|
||||
./mail-migrator --src "olduser@gmail.com:apppass1@imap.gmail.com:993" \
|
||||
--dst "newuser@gmail.com:apppass2@imap.gmail.com:993" \
|
||||
--insecure --resume --log gmail-migration.log
|
||||
# Single account
|
||||
./mail-migrator --src "info@trieltree.co.id:P@ssw0rd123@10.10.11.30:993" \
|
||||
--dst "info@trieltree.co.id:P@ssw0rd123@10.10.11.24:993" \
|
||||
--insecure --log migration.log
|
||||
|
||||
# Output:
|
||||
# ✓ Connected to 10.10.11.30:993 as info@trieltree.co.id
|
||||
# ✓ Connected to 10.10.11.24:993 as info@trieltree.co.id
|
||||
# ✓ Found 6 mailboxes to migrate
|
||||
# ✓ INBOX: 17 messages migrated
|
||||
# ✓ Migration completed successfully
|
||||
```
|
||||
|
||||
### Office365 Migration
|
||||
### Batch Migration
|
||||
|
||||
```bash
|
||||
./mail-migrator --src "user@old.com:password@outlook.office365.com:993" \
|
||||
--dst "user@new.com:password@outlook.office365.com:993" \
|
||||
--resume --log o365-migration.log
|
||||
# File: accounts.csv
|
||||
info@trieltree.co.id:P@ssw0rd123@10.10.11.30:993,info@trieltree.co.id:P@ssw0rd123@10.10.11.24:993
|
||||
user2@domain.com:password2@10.10.11.30:993,user2@domain.com:password2@10.10.11.24:993
|
||||
|
||||
# Command:
|
||||
./mail-migrator --batch accounts.csv --insecure --resume --log batch-migration.log
|
||||
```
|
||||
|
||||
### Self-hosted with Self-signed Cert
|
||||
```bash
|
||||
./mail-migrator --src "user:pass@mail.old.local:993" \
|
||||
--dst "user:pass@mail.new.local:993" \
|
||||
--insecure --resume
|
||||
```
|
||||
## Technical Details
|
||||
|
||||
## Development
|
||||
|
||||
### Project Structure
|
||||
```
|
||||
├── main.go # CLI interface dan orchestration
|
||||
├── imap.go # IMAP connection dan message copying
|
||||
├── state.go # BoltDB state persistence
|
||||
├── go.mod # Go module dependencies
|
||||
└── README.md # Documentation
|
||||
```
|
||||
|
||||
### Dependencies
|
||||
- `github.com/emersion/go-imap` - IMAP client library
|
||||
- `github.com/urfave/cli/v2` - CLI framework
|
||||
- `go.etcd.io/bbolt` - Embedded key-value database
|
||||
- `github.com/sirupsen/logrus` - Structured logging
|
||||
|
||||
### Building
|
||||
```bash
|
||||
# Development build
|
||||
go run . --help
|
||||
|
||||
# Production build
|
||||
go build -ldflags="-s -w" .
|
||||
|
||||
# Cross-compile for Linux
|
||||
GOOS=linux GOARCH=amd64 go build .
|
||||
```
|
||||
- **Language**: Go
|
||||
- **IMAP Library**: github.com/emersion/go-imap
|
||||
- **State Storage**: BoltDB
|
||||
- **Logging**: Logrus
|
||||
- **Authentication**: LOGIN, AUTHENTICATE PLAIN
|
||||
- **SSL/TLS**: Support dengan opsi insecure mode
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see LICENSE file for details.
|
||||
[Sesuai dengan license file]
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the repository
|
||||
1. Fork repository
|
||||
2. Create feature branch
|
||||
3. Make changes
|
||||
4. Add tests if applicable
|
||||
5. Submit pull request
|
||||
3. Commit changes
|
||||
4. Push to branch
|
||||
5. Create Pull Request
|
||||
|
||||
## Support
|
||||
|
||||
For issues and questions:
|
||||
Jika mengalami masalah:
|
||||
1. Check troubleshooting section
|
||||
2. Search existing issues
|
||||
3. Create new issue with:
|
||||
- Command used
|
||||
- Full error message
|
||||
- Log output (with sensitive info removed)
|
||||
2. Gunakan IMAP test tool untuk debug
|
||||
3. Enable debug logging
|
||||
4. Create issue dengan log detail
|
||||
Reference in New Issue
Block a user