Skip to content

Instantly share code, notes, and snippets.

@bmaupin
Last active May 2, 2024 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmaupin/7e34a9d1ec112db6e4bc3d4e4c50612d to your computer and use it in GitHub Desktop.
Save bmaupin/7e34a9d1ec112db6e4bc3d4e4c50612d to your computer and use it in GitHub Desktop.
Export feature phone SMS using Gammu/Wammu

General notes

SMS

Gammu/Wammu may not be able to retrieve dates for sent messages, only received messages.

MMS

MMS messages may not be able to be exported using Gammu/Wammu with some phones. If you don't see MMS in the exported messages, you may be able to save the message attachments to the phone's storage and copy them to a PC via a USB cable.

(Recommended) Export SMS from a feature phone using Wammu

ⓘ This generates an XML export file which differs from the Gammu export file format

ⓘ This method will appear to export a fewer number of messages, but that's because it combines multi-part messages when exporting

Prerequisites

  • Docker

  • Add the user to the dialout group

    sudo usermod -a -G dialout $USER
    newgrp dialout
    
  • (Optional) x11docker

Steps

  1. Set up the phone

    This will depend on the phone, e.g. for the LG 840G (https://www.howardforums.com/showthread.php/1843461-LG305C-LG306G-issues/page12):

    1. Go into the service mode of the phone

      In the phone dialer, dial 3845#*840#

    2. Scroll down to USB Connection Mode and select it

    3. Select Data Service

    ⓘ This will need to be done every time you wish to connect this particular phone to Gammu

  2. Plug the phone into a USB port of the PC

  3. (Optional) Create a temporary directory, e.g.

    mkdir tmp-wammu
    
  4. Open a terminal and go to the directory where you want to save the messages

  5. Open Wammu using Docker

    e.g. using x11docker:

    x11docker ghcr.io/bmaupin/wammu wammu --share /dev/ttyACM0 --share "$PWD" --user=RETAIN
    

    or from Docker Hub:

    x11docker bmaupin/wammu wammu --share /dev/ttyACM0 --share "$PWD" --user=RETAIN
    

    The Dockerfile used for this image is here for reference or if you'd prefer to build it locally:

    FROM ubuntu:18.04
    
    WORKDIR /workdir
    
    RUN apt update && \
      apt -y install python-six wammu
    
    RUN useradd -ms /bin/bash wammu && \
      usermod -a -G dialout wammu
    
    USER wammu
  6. Configure the phone

    1. Do you want to configure phone connection now? > Yes > Next

    2. Configure the phone as needed, e.g. for LG 840G:

      1. Configuration style > Guided configuration > Next
      2. Connection type > USB cable > Next
      3. Phone type > None of the above > Next
      4. Connection type > AT based > Next
      5. Driver to use > Generic AT over serial line or it's emulation > Next
      6. Please enter device where phone is accessible > select /dev/ttyACM0 from dropdown > Next > Next > Finish
  7. Connect the phone

    Phone > Connect

  8. Export SMS

    1. Retrieve > Messages

    2. Backups > Export messages to XML

    3. Browse to the directory where you opened Wammu from and give the file a name

Import Wammu-exported SMS into Android

(Gammu to Android SMS converter)

⚠️ The script won't work with sent messages that don't have a dateenc field

Prerequisites

  • Ruby

Steps

  1. Download and fix the script

    https://gist.githubusercontent.com/kares/1999289/raw/f84f964ef5036baecf9d0fe5144f13b1ebfcf1a9/gammusms2android.rb
    chmod +x gammusms2android.rb
    sed -i 's/evn/env/' gammusms2android.rb
    
  2. Run the conversion script, e.g.

    ./gammusms2android.rb wammu-sms-backup.xml > wammu-sms-converted.xml
    

    If you get an error, it may be because sent messages don't have a dateenc field.

  3. Import the messages to an Android phone using SMS Backup & Restore

Export SMS from a feature phone using Gammu

⚠️ Wammu is recommended instead of Gammu, because the script to convert Wammu messages is much more robust than the script to convert Gammu messages to a format that Android can use

Prerequisites

  • Gammu (e.g. sudo apt install gammu)
  • Add the user to the dialout group (see above)

Steps

  1. Follow the steps above under Set up the phone

  2. Plug the phone into a USB port of the PC

  3. Configure the Gammu connection to the phone

    gammu-detect > ~/.gammurc
    
  4. Make sure Gammu can connect to the phone

    gammu identify
    

    e.g.

    $ gammu identify
    Device               : /dev/ttyACM0
    Manufacturer         : LG ELECTRONICS
    Model                : unknown (LG840G)
    Firmware             : LG840G-....  1  [JUL 31 2012 22:00:00]
    IMEI                 : 873624396293243
    SIM IMSI             : 544948444768289
    
  5. Download SMS from the phone

    gammu backupsms gammu-sms-backup.txt
    

    e.g.

    $ gammu backupsms gammu-sms-backup.txt
    Delete each sms after backup? (yes/no/ALL/ONLY/NONE) no
    Backup sms from folder "Inbox" (SIM)? (yes/no/ALL/ONLY/NONE) yes
    Backup sms from folder "Outbox" (SIM)? (yes/no/ALL/ONLY/NONE) yes
    Backup sms from folder "Inbox"? (yes/no/ALL/ONLY/NONE) yes
    Backup sms from folder "Outbox"? (yes/no/ALL/ONLY/NONE) yes
    

Import Gammu-exported SMS into Android

(Transferring Text Messages (SMS) from Nokia to Android)

⚠️ The conversion script only seems to convert the first part of multi-part messages

⚠️ The conversion script doesn't seem to properly handle unicode encoding

Prerequisites

  • Perl

Steps

  1. Download and extract the conversion script

    wget http://web.archive.org/web/20150411011010if_/http://archive.ginkel.com/sms-gammu2android-0.1.tar.gz
    tar -xvf sms-gammu2android-0.1.tar.gz
    
  2. Fix date parsing

    After this section:

    	if (/^Sent = (.*)/) {
     	   $time = str2time($1);

    Add this section:

    	} elsif (/^DateTime = (.*)/) {
     	   $time = str2time($1);
  3. Run the script, e.g.

    ./sms-gammu2android-0.1/sms-gammu2android gammu-sms-backup.txt > gammu-sms-converted.xml
    
  4. Import the messages to an Android phone using SMS Backup & Restore

Get individual messages with Gammu

  1. List the SMS folders

    gammu getsmsfolders
    
  2. Get a message from a folder

    gammu getsms FOLDER_NUMBER MESSAGE_NUMBER
    
    • Use folder number from the previous step
    • Messages start at index 1

    ⓘ You may find that specifying a folder returns messages for another folder. E.g. if Outbox is folder 4, gammu getsms 4 1 may give you the first message from Inbox (folder 3). If this happens, getting messages from folder 3 or 4 will always return the same messages. The Outbox messages will be mixed in with the Inbox messages. For example:

    $ gammu getsmsfolders
    1. "                         Inbox", SIM memory, Inbox folder
    2. "                        Outbox", SIM memory, Outbox folder
    3. "                         Inbox", phone memory, Inbox folder
    4. "                        Outbox", phone memory, Outbox folder
    
    $ gammu getsms 3 1
    Location 100001, folder "Inbox", phone memory, Inbox folder
    SMS message
    ...
    
    $ gammu getsms 4 1
    Location 100001, folder "Inbox", phone memory, Inbox folder
    SMS message
    ...
    
    $ gammu getsms 4 3
    Location 100003, folder "Outbox", phone memory
    SMS message
    ...
    
    $ gammu getsms 4 10
    Location 100010, folder "Inbox", phone memory, Inbox folder
    SMS message
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment