3 # Copyright (c) 2006, Nokia Corporation
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # * Neither the name of the Nokia Corporation nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 # Perl script to converts an Excel spreadsheet (arg 1)
34 # with provider information in a GKeyFile readable format
35 # for use in modest (see modest-presets.[ch] for details]
37 # The input is assumed to be MS-style UTF16-LE, and
38 # output will be UTF-8.
40 # Program requires Spreadsheet::ParseExcel, which does all
41 # the interesting stuff
43 # input columns are like this:
44 # 0: MCC (0 For Global Email)
47 # 3: OutgoingMailServer
48 # 4: Secure smtp: (0 = no\, 1=yes)
49 # 5: IncomingMailServer
50 # 6: SendMessage (0=Immediately; 1=During next conn.)
51 # 7: SendCopyToSelf (0=No; 1=Yes)
52 # 8: MailboxType (0=POP3; 1=IMAP4)
53 # 9: Security (0=Off; 1=On(143/110); 2=On(993/995);)
54 #10: APOPSecureLogin (0=Off; 1=On)
55 #11: RetrieveAttachment (0=No; 1=Yes)
56 #12: RetrieveHeaders (0=All; 1-99=User defined)
58 # some of these are properties of user-settings; however,
59 # we are only interested in server settings, so some
60 # of the data (6,7,11,12) will be ignored for our output.
63 use Spreadsheet::ParseExcel;
64 #use Unicode::String qw(utf8 utf16le);
65 #Unicode::String->stringify_as('utf8');
67 die "usage: xls2cvs <file.xls>\n" unless @ARGV == 1;
70 die "'$file' is not a readable file\n" unless -r $file;
73 my $xl = new Spreadsheet::ParseExcel;
74 my $data = $xl->Parse($file) or die "could not parse $file: $!";
76 my $sheet = $data->{Worksheet}[0];
81 print "# generated on $now from " . $data->{File} . "\n";
82 print "# keys and their meaning:\n";
83 print "# [MailboxName]: name of the provider (eg. Wanadoo, Gmail)\n" .
84 "# MCC: Mobile Country Code (Netherlands=204, France=208, ...\n" .
85 "# globals like GMail don't have one)\n" .
86 "# OutgoingMailServer: name of the smtp server (eg. smtp.foo.fi)\n" .
87 "# SecureSMTP: 'true' if there's secure SMTP\n" .
88 "# IncomingMailServer\n" .
89 "# MailboxType: 'pop' or 'imap'\n" .
90 "# SMTPSecurity: 'true' if SMTP is secure\n" .
91 "# APOPSecureLogin: 'true' if APOP is supported\n\n";
93 # ignore the first row
94 for (my $r = $sheet->{MinRow} + 1 ; defined $sheet->{MaxRow} && $r <= $sheet->{MaxRow}; ++$r) {
99 # 0: MCC (mobile country code, or 0 for Global)
102 # 3: OutgoingMailServer
104 # 5: IncomingMailServer
108 next unless ($sheet->{Cells}[$r][0] && $sheet->{Cells}[$r][0]->Value =~ /\d+/);
110 # name -> required, unique
111 $cell = $sheet->{Cells}[$r][1];
113 print "[" . $cell->Value . "]\n";
115 # MCC -> TODO: convert to normal country code
116 $cell = $sheet->{Cells}[$r][0];
117 if ($cell->Value > 0) {
118 print "MCC=" . $cell->Value . "\n";
121 # address -> required, unique
122 #$cell = $sheet->{Cells}[$r][2];
123 #print "EmailAddress=" . $cell->Value . "\n";
126 $cell = $sheet->{Cells}[$r][3];
127 print "OutgoingMailServer=" . $cell->Value . "\n" if ($cell);
130 $cell = $sheet->{Cells}[$r][4];
131 print "SecureSmtp=true\n" if ($cell && $cell->Value == 1);
134 $cell = $sheet->{Cells}[$r][5];
136 print "IncomingMailServer=" . $cell->Value;
138 my $type = $sheet->{Cells}[$r][8]->Value;
139 my $sec = $sheet->{Cells}[$r][9]->Value;
142 if ($type == 0) { print ":995";}
143 if ($type == 1) { print ":993";}
146 print "IncomingSecurity=$sec\n";
150 $cell = $sheet->{Cells}[$r][8];
152 print "MailboxType=";
153 if ($cell->Value == '0') {print "pop"} else {print "imap"};
157 $cell = $sheet->{Cells}[$r][10];
158 print "APOPSecureLogin=true\n" if ($cell && $cell->Value == 1);