summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--bin/kdepim/WhatsNew.txt7
-rw-r--r--kmicromail/libetpan/imap/mailimap_parser.c20
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp11
-rw-r--r--kmicromail/viewmailbase.cpp2
4 files changed, 35 insertions, 5 deletions
diff --git a/bin/kdepim/WhatsNew.txt b/bin/kdepim/WhatsNew.txt
index 5bfe1c8..cbed872 100644
--- a/bin/kdepim/WhatsNew.txt
+++ b/bin/kdepim/WhatsNew.txt
@@ -1,786 +1,793 @@
Info about the changes in new versions of KDE-Pim/Pi
********** VERSION 1.9.20 ************
KO/Pi:
Added for the "dislplay one day" agenda mode
info in the caption and in the day lables:
Now it is displayed, if the selected day is from "day before yesterday"
to "day after tomorrow".
Made it possible to delete a Todo, which has sub-todos.
Fixed two small problems in the todo view.
Added missing German translation for filter edit and print dialog.
Made search dialog closeable by cancel key.
Made it possible to select in the date picker the (ligt grey )
dates of the prev./next month with the mouse.
+OM/Pi:
+"Delete mail" icon in main window now deletes all selected mails.
+Fixed the problem, that the state flag of imap mails was ignored.
+Now mails with "FLAG_SEEN" on the imap server get no icon in the list view
+to idecate that they are already seen.
+Fixed the problem that the body of some mails was not displayed in the
+mail viewer when fetching them from the imap server directly to read them.
********** VERSION 1.9.19 ************
Added a lot of missing translations to KA/Pi,
Added some missing translations to KO/Pi and OM/Pi.
Fixed some minor problems in KA/Pi + KO/Pi.
Fixed a crash when closing PwM/Pi.
Added German translation for PwM/Pi.
Made view change and Month View update faster in KO/Pi.
********** VERSION 1.9.18 ************
FYI: The VERSION 1.9.17 was a testing release only.
Please read the changelog of VERSION 1.9.17 as well.
Cleaned up the syncing config dialog.
Added sync config options for date range for events.
Added sync config options for filters on incoming data.
Added sync config options for filters on outgoing data.
Please read the updated SyncHowTo about the new filter settings.
These filter settings make it now possible to sync with shared
calendars without writing back private or confidential data
(via the outgoing filters).
To sync only with particular parts of a shared calendar,
the incoming filter settings can be used.
An example can be found in the SyncHowTo.
Same for shared addressbooks.
Added a setting for the global kdepim data storage.
Usually the data is stored in (yourhomedir/kdepim).
Now you can set in the Global config dialog TAB, subTAB "Data storage path"
a directory where all the kdepim data is stored.
That makes it easy to save all kdepim data on a SD card on the Z, for example.
KO/Pi:
The timeedit input has a pulldown list for times.
If opened, this pulldown list should now has the right time highlighted.
Added the possibility to exclude events/todos/journals in a filter.
You should exclude journals, if you do not want them to sync with a public calendar.
KA/Pi:
Added the possibility to in/exclude public/private/confidential contacts to a filter.
If you have already defined filterrules in KA/Pi you have to adjust them all by setting the "include public/private/confidential" property manually. Sorry for that ...
Added printing of card view and details view on desktop.
Printing of list view is not working...
Added button for removing pictures in contact editor.
Parsing data fix of KA/Pi version 1.9.17.
Fixed the "parse name automatically" problem of KA/Pi version 1.9.17.
Fixed some syncing merging problems.
********** VERSION 1.9.17 ************
KO/Pi:
Fixed that tooltips were not updated after moving an item in agenda view.
Fixed a bug in sorting start date for recurring events in list view.
Changed the left button in todo viewer from "Agenda" to "Set completed".
This makes it possible to change a todo in the What's Next View quickly to the completed state without leaving the What's Next View.
Added more info in the todo viewer: Startdate, parent/sub todos.
KA/Pi:
All fields search does now actually search all the (possible) fields,
not only those listed in the contact list.
Made is possible to inline a picture in a vcard on the Z.
This was only possible on the desktop, now is it possible on the Z as well.
Fixed of missing save settings after filter configuration.
Made saving of addressbook much faster.
Fixed extension widget layout problem.
Fixed saving of default formatted name settings.
Fixed formatted name handling in edit dialog.
Added an option for changing formatted names of many contacts
(menu: File - Change - Set formatted name).
QWhatsThis was not working on the Z ( only black rectangle was shown).
This is Fixed.
KDE-Sync:
Now readonly KDE resources are synced as well.
(They are not changed in KDE itself, of course).
********** VERSION 1.9.16 ************
KO/Pi:
Fixed search dialog size on Z 6000 (480x640 display).
Added setting to hide/show time in agenda items.
Added setting to hide not running todos in todo view.
Added columns for start date/time in todo view.
Replaced the solid half-hour lines in agenda view by dot lines.
Added possibility of printing the What's Next View on the desktop
(i.e. Windows and Linux).
Fixed a crash in KO/Pi when starting KO/Pi with What's Next view.
Added tooltips in month view.(Tooltips only available on desktop)
Fixed a strange problem in KO/Pi alarm applet.
Did not find the actual problem,
such that now Qtopia reboots again if deinstalling the alarm applet.
But the alarm applet should work again.
KA/Pi:
Fixed the problem, that internal pictures were not saved.
Fixed a problem in the pi-sync mode by increasing the timeout for data transfer from 20 seconds to 5 minutes.
Fixed some minor problems. (Like word wrap in help text windows).
Fixed a compiling problem in microkde/kresources.
KO/Pi is using zdbat (renamed to db2file) for syncing with Sharp DTM.
This version now includes zdbat 1.0.0 (old version was zdbat 0.2.9)
such that now syncing KO/Pi with Sharp DTM should work on the
Zaurus C 3000 model.
********** VERSION 1.9.15 ************
Usebilty enhancements in KO/Pi:
When clicking on the date in a month view cell, the day view is shown.
Old behaviour was, that the "new event" dialog popped up.
Added a one step "undo delete" in KO/Pi (Accessable in the "Action" menu).
That means, you can restore the latest
event/todo/journal you have deleted.
A journal is deleted, if you clear all the text of the journal.
Fixed the bug of the editor dialogs in KO/Pi of version 1.9.14.
KA/Pi starting in 480x640 resolution:
Hide the filter action in toolbar
and added icons for undo/delete/redo in toolbar.
Change in OM/Pi ViewMail dialog:
When clicking on the "delete" icon the mail is deleted after confirmation as usual.
But the edit dialog is not closed as before, now the next mail in the folder is shown automatically (if there is any).
Fixed a crash when deleting mail-accounts in OM/Pi.
********** VERSION 1.9.14 ************
Fixed some problems with the dialog sizes when switching
portrait/landscape mode on 640x480 PDA display.
Fixed some other small bugs in KA/Pi KO/Pi and OM/Pi and PwM/Pi.
Fixed an ugly bug in KOpieMail:
KOpieMail was not able to write files (mails) to MSDOS file system,
like on an usual preformatted SD card. That should work now.
To save your mail data on the Sd card do the following:
Create a dir on the SD card:
mkdir /mnt/card/localmail
Go to your home dir:
cd
Go to kopiemail data storage dir:
cd kdepim/apps/kopiemail
Create a symlink to the SD card:
ls -s /mnt/card/localmail
Now KOpieMail will store all mails on the SD card.
KO/Pi Monthview:
Now "Go to Today" selects the current month from day 1-end,
not the current date + some days.
I.e. "Go to Today" shows now always
the current month with first day of month in the first row.
Added missing German translation.
Fixed icons of executeable on Wintendo.
Added a "Show next Mail" button to the OM/Pi
mail viewer such that the mail below the current mail
in the mail list view of the current folder
can be read with a single click.
********** VERSION 1.9.13 ************
Fixed nasty PwM/Pi file reading bug, when
the used hash algo of file is different then the global
hash algo.
Added KA/Pi support for opie mailit mailapplication.
Fixed some bugs in OM/Pi.
Now character conversion tables are available for the Zaurus
to make OM/Pi working properly.
To get the character conversion in OM/Pi working, please download
at the sourceforge project site the package
sr-character-conversion_SharpROM_arm.ipk.zip
(or oz-character-conversion_OZ-gcc3xx_arm.ipk.zip for OZ roms)
from the section "general files for KDE/Pim"
Instructions how to install this package are in a ReadMe in this file.
Fixed the orientation change problem in KA/Pi when switching
portrait/landscape mode.
French translation available for KA/Pi and OM/Pi.
Fixed some problems with categories in KO/Pi in DTM sync.
Added selection dialog for export to phone in KA/Pi.
If in KO/Pi is an attendee selected to add to a meeting and this
attendee is already in the list of attendees, this person is not added
again.
Some menu cleanup in KA/Pi.
********** VERSION 1.9.12 ************
Fix for the bug in KO/Pi What's Next view of version 1.9.11.
Bugfix: Licence file is now shown again.
OM/Pi now supports Unicode (utf8 charset).
Fixed some bugs in OM/Pi.
KA/Pi has more German translation.
********** VERSION 1.9.11 ************
Fixed several problems in PWM/Pi, like
asking the user, if unsaved changed are pending
when closing the app.
And PwM/Pi handles now different texts for the
fields Description, Username, Password, configurable per category.
Fixed a crash in KO/Pi , when importing/loading vcs files
which have an entry with an attendee with state:
NEEDS ACTION
Fixed some problems in the German translation of OM/Pi,
which makes some dialogs not fitting on the screen
of the Z 5500.
Fixed Qtopia crash, when disabling/deinstalling
KO/Pi alarm applet.
Implemented direct KDE<->KA/Pi sync for KA/Pi running
on Linux desktop.
Added feature "remove sync info" to sync menu.
Tweaked the KO/Pi What's next view a bit, added
setting to hide events that are done.
Disabled "beam receive enabled" on startup to
avoid problems if Fastload is enabled.
Please set "beam receive enabled",
if you want to receive data via IR.
Fixed bug in direct KDE<->KO/Pi sync for KO/Pi running
on Linux desktop.
Made in KA/Pi scrolling possible, if details view is selected.
(The keyboard focus is set automatically to the search line)
Fixed a bug in DMT sync, that a new entry in DTM was added
on every sync to Kx/Pi.
Fixed missing writing of KA/Pi categories to DMT entries when syncing.
Fixed a bug in DMT sync with todos created in KO/Pi containing
non-latin1 characters.
Rearranged package contents of Sharp-ipks and made all
packages installable on SD again.
Fixed the writing of addressbook data in DTM sync.
Empty fields in KA/Pi were not removed.
Added better category handling in KA/Pi:
Added item
Edit Categories and
Manage new categories
to the settings menu.
Possible to configure a view to display categories.
Added detailed "KDE Sync Howto" and "Multi Sync Howto" to Help menu.
Fixed displaying of "free" days and time in KO Monthview and Agendaview.
... and many other bugfixes.
********** VERSION 1.9.10 ************
Many internal small bugfixes.
And fix of the "big" bug in KO/Pi,
that after Syncing the appointments had an offset by several hours.
That was a problem with the internal timezone setting,
introduced by the changed timezone configuration settings.
German translation for OM/Pi is now available.
********** VERSION 1.9.9 ************
KDE-Pim/Pi has a new Member!
It is called PWM/Pi (Passwordmanager/platform-independent)
and it is available for the Zaurus.
It is planned, that it will be available later for Windows.
(And for Linux, of course).
It is a port of the Passwordmanager of KDE.
It will need the MicroKDElibs to run.
Made loading of addressbooks in KA/Pi up to 7 times faster!
The bigger your addressbook file, the more starting speed
will you gain. (relatively)
The Qtopia addressbook connector is now platform independend
as well and should work on any platform for importing/exporting
Qtopia and Opie XML files.
Added a +30min feature to the timezone settings to make
KDE-Pim/Pi useable in Australia and other parts on the
world with strange timezones ;-)
German "Umlaute" should now be sorted correctly on the Z in KA/Pi.
It is now possible to disable the
"receive data via infrared" feature, such that syncing with
Outlook is now possible again with Kx/Pi runing.
Please disable it, before syncing Sharp DTM with Outlook.
For your convenience, the "receive data via infrared" feature
is disabled automatically, if you sync Kx/Pi with DTM.
You have to enable it again manually after syncing.
Enabling this feature makes it impossible to start the
Sharp DTM apps. If this feature is enabled, you will only get the
alarm notification from KO/Pi and not from the Sharp calendar.
This is very useful if you sync KO/Pi with Sharp DTM,
because after syncing you usually would get notified about
an alarm by KO/Pi and the Sharp Calendar.
Together with the Linux desktop version of KO/Pi
it is now possible to sync KO/Pi on the Zaurus
with the complete KDE-desktop (3.3 or later)
calendar data easily.
That makes it possible to sync the Z with one
click of a mouse with the KDE-Desktop.
This feature it available for all Zaurus platforms KO/Pi
is running on.
The only thing needed is a running KO/Pi on Linux and
a compiled version of the small
KDE-Pim/Pi<->KDE-Desktop access command line program,
which is in the KDE-Pim/Pi sources available.
The "KDE-desktop" syncing feature for KA/Pi will follow
in the next releases.
Fixed the vcard export bug, which had the version 1.9.8.
Added missing GERMAN translation to KO/Pi.
Hi PsionX, could you add the missing french translation?Thx!
Translation files for KA/Pi are available as well.
GERMAN translation will be available in the next release.
PsionX ( yres, you again ;-) ), could you start translating
KA/Pi? Thx!
You can download the version 1.9.9 at
http://sourceforge.net/project/showfiles.php?group_id=104103&package_id=112604
Note:
To run the mail program OM/Pi you need libopenssl.
A link to a download loaction is available at
ZSI at www.killefiz.de
********** VERSION 1.9.8 ************
Fixed character decoding in OM/Pi.
(e.g. German "Umlaute" were not displayed properly.)
Made is possible to reparent todos in KO/Pi.
Use contextmenu or keys (look at Help-Keys + Colors) for that.
Added the missing Sync-Howto and WhatsNew to the packages.
KO/Pi on Linux desktop can now sync with KDE desktop.
That means: When using KO/Pi on Linux desktop for syncing with
KDE desktop and the Zaurus, the Zaurus can be synced now
with all KDE-Calendar resources, not only with one local file.
(That makes it possible to sync the Zaurus with the
calendar data on a Kolab server)
KA/Pi syncing with KDE desktop will be available in the next version.
********** VERSION 1.9.7 ************
KO/Pi - KA/Pi on Windows:
Now a directory can be defined by the user, where the
application/config data should be saved.
Define your desired path in the evironment variable
MICROKDEHOME
before starting KO/Pi or KA/Pi.
An easy Kx/Pi to Kx/Pi syncing is now possible
(it is called Pi-Sync) via network.
Please look at the Sync Howto.
Exporting of calendar data and contacts to mobile phones is now possible.
The SyncHowto is updated with information howto
access/sync mobile phones.
Please look at the Sync Howto.
Now KO/Pi and KA/Pi on the Zaurus can receive data via infrared directly.
Please disable Fastload for the original contact/calendar applications
and close them.
KO/Pi and KA/Pi must be running in order to receive the data.
(KO/Pi and KA/Pi are always running if Fastload for them is enabled!)
In the KA/Pi details view are now the preferred tel. numbers displayed on top
of the other data ( emails/tel.numbers/addresses)
Fixed some syncing problems in KA/Pi.
Added font settings for the KA/Pi details view.
Added fields "children's name" and "gender" to KA/Pi.
Made searching in KA/Pi better:
Now the first item in a view is selected after a search automatically and
the views can be scrolled up/down when the search input field has the keyboard focus.
And, of course, fixed a bunch of reported bugs in KO/Pi and KA/Pi.
********** VERSION 1.9.6 ************
Changes in the external application communication on the Zaurus
in order to use less RAM when the apps are running.
First syncing of addressbooks (KA/Pi) is possible.
********** VERSION 1.9.5a ************
Fixed a bug in KO/Pi in the SharpDTM sync of version 1.9.5.
Fixed some small bugs.
KA/Pi shows now the birthday in summary view.
Now OM/Pi and KA/Pi are using the date format defined in KO/Pi
for displaying dates.
********** VERSION 1.9.5 ************
There is still no Addressbook syncing!
New in 1.9.5:
Many bugfixes.
Better searching in KA/Pi.
You can configure in KA/Pi if you want to search only after
<return> key pressed.
Better mail downloading in OM/Pi.
First experimental alpha version of sync of KO/Pi with mobile phones.
See gammu documentation for supported phones.
You need to install the package kammu_1.9.5_arm.ipk for sync of KO/Pi with mobile phones. kammu_1.9.5_arm.ipk needs libbluetooth and libsdp.
Quick hint how to use:
NOTE: MOBILE PHONE SYNC IS EXPERIMENTAL!
Install kammu_1.9.5_arm.ipk , libbluetooth and libsdp.
Create syncprofile - mobile device
Remove entry for model. (Leave empty ).
Enable infrared on Zaurus and your Phone.
Sync.
To get a more detailed log, start kopi from konsole.
********** VERSION 1.9.4 ************
This is the version 1.9.4 of KDE-Pim/Pi for the Zaurus.
WARNING:
PLEASE BACKUP ALL YOUR DATA!
We have changed a lot and maybe there are some unknown problems.
SYNC HANDLING HAS CHANGED!
Such that, if you sync now with an already synded device, you will duplicated entries after the first sync.
(This change was introduced to make it possible to sync with mobile phones, which will be available later (maybe in 4 weeks).
You need the kmicrokdelibs_1.9.4_arm.ipk as a base for the other programs.
If you get the error: "Install only possible in main memory", just try it again to install it on SD card. That worked for me. And it was reported that rebooting Qtopia did help in this case as well.
As programs are available:
KO/Pi (korganizer ipk) - a calendar program.
KA/Pi (kaddressbook ipk ) - an addressbook
OM/Pi (kopiemail ipk ) an email program with pop/smtp and IMAP support.
An alarm notification program ( korganizer-alarm ipk ) for KO/Pi that notifies you about alarms, even if the Zaurus is in suspend mode.
(If you do not see an icon in the taskbar after installing korganizer-alarm, please restart Qtopia)
All the applications are installed in a "Pim" TAB.
If this TAB is new on your system, you can get an icon in this TAB by installing pim_TAB_icon_1.9.4_arm.ipk
All the application are integrated.
Such that you can choose in KO/Pi the attendees of a meeting from the addresses in KA/Pi. When you click in KA/Pi on the email address, OM/Pi is started to write the mail.
HINT:
If you install KPhone/Pi 0.9.7, it will be called, if you click in KA/Pi on a phone number.
What's new?
SYNC HANDLING HAS CHANGED!
Such that, if you sync now with an already synded device, you will duplicated entries after the first sync.
(This change was introduced to make it possible to sync with mobile phones, which will be available later (maybe in 4 weeks).
New in OM/Pi:
When copying(i.e. downloading mails) , you can specify, that only mails of a given size should be downloaded. Added mail copy possibility for selected mails.
New in KO/Pi:
French is now available for KO/Pi.
Choose menu:Actions - Configure:TAB locale
Syncing has changed.
Phone sync available soon.
Not much changes, I cannot remember them ...
New in KA/Pi:
Beaming possible.
Sharp DTM readonly access possible( create a new DTM resource );
Better searching possible.
Search is performed only after pressing the return key.
Use wildcard * to specify parts of a name.
Better name/email selection dialog (called from KO/Pi or OM/Pi). In this dialog, now searching is possible. Like in KA/Pi, use return key and wildcard * .
A big improvement is the new management of the contact access.
In version 1.9.3, every application was using their own addressbook access data.
That means, the addressbook was loaded up to three times in the memory, when accessed by KA/Pi, KO/Pi and OM/Pi.
That was wasting of memory, if you had several hundreds of contacts.
Now only KA/Pi accesses the addressbook.
If KO/Pi or OM/Pi want to get some name/email data, they request KA/Pi to open the name/email selection dialog and send it back to them.
If you click on an attendee in a meeting, its contact data is displayed in KA/Pi directly.
That means, if KO/Pi or OM/Pi want to access contact data, KA/Pi is started first.
New in the KO/Pi alarm applet:
Configure your own timer popup menu!
(Text and minutes for timer countdown)
Just edit the file
(yourhomedir)/.kopialarmtimerrc
and start/stop a timer to get a new menu with the data of this file.
********** VERSION 1.9.3 ************
1)
Now KO/Pi on Windows imports directly the calendar data of
an installed Outlook. Should work with OL version >= 2000.
********** VERSION 1.9.2 ************
1)
KDE-Pim/Pi has got a new member:
KmicroMail (KM/Pi) is a mail program,
which can handle IMAP and POP mail access.
It is based on Opie-Mail v3.
All dependencies to the Opie libraries ar removed,
such that no additional Opie lib is needed.
It is already integrated in KO/Pi and KA/Pi.
It it now available for the Zaurus,probably it
will be available for other platforms later.
Hint:
Create your own contact (name + email)
in KA/Pi, select this contact and choose menu:
Settings - Set Who Am I.
Now the settings of this contact are used as
the sender data in KM/Pi.
2)
KDE-Pim/Pi is split up in five different
packages now precompiled for Sharp Zaurus:
--kmicrokdelibs_1.9.2_arm.ipk
The libs are needed for any
of the following programs:
--kaddressbook_1.9.2_arm.ipk
--kmicromail_1.9.2_arm.ipk
--korganizer_1.9.2_arm.ipk
Independ from that, there is the alarm applet
available for KO/Pi, which also offers
quick access for a new mail or
showing the addressbook.:
--korganizer-alarm_1.9.2_arm.ipk
Independend means, that the alarm applet
does not need any of the libs or programs above to run.
But it would be quite useless without these programs.
NOTE:
If you get a
"This application depends on other programs"
during installation of
--kmicrokdelibs_1.9.2_arm.ipk
you probably do not have to care about that.
kmicrokdelibs_1.9.2 will come with some
resource plugins, which needs additional libraries.
(E.g. libopie1, if you want to use the
opie resource connector in KA/Pi).
If you do not have this libraries installed,
you simply cannot use the resource.
To make it clear:
If the libraries are missing, the applications
using kmicrokdelibs will start,
because the resources are plugins.
3)
KO/Pi and friends are now installable on SD-Card!
It is recommended to install all libs and apps
on the SD card or all in the internal storage.
There may be problems, if this is mixed.
4)
Fixed two bugs in the alarm notification on Windows.
5)
Great improvement!
KO/Pi uses now the latest version of libical.
Libical is the library which actually reads
the calendar files and extract the data from it.
With the old version, there were problems
(crashes or program hangs) when licical did read
files, which were not stored from KO/Pi.
I do not know, if the new libical works perfect,
but actually it works much better than
the old version.
There are no problems with compatibility with
old calendar files of KO/Pi, of course!
6)
New in KA/Pi:
Opie addressbook resource connector available!
You will need libopie1 and the opie addressbook,
of course.
With the Opie addressbook resource connector,
you can access the Opie addressbook readonly in KA/Pi.
If you want to edit or import the data into KA/Pi,
do this:
a) Create an Opie resource.
(Menu: Settings-Configure Resources).
After configuration and restarting KA/Pi you should see
the Opie contacts in KA/Pi.
b) Select some or all Opie contacts.
(NOTE: +++++
To know exactly, what contacts are Opie contacts,
do this: Choose menu:
View-Modify View - TAB Fields.
Select in the above list "Resource" and click
down arrow to add it to the "Selected fields".
Click OK.
Now you have a new column "Resource" in your list,
where you can see, what an Opie resource is.
++++ NOTE end.)
Ok, we do have now some Opie contacts seleted.
(Use SHIFT or CTRL key in order to multiple select).
c) Choose menu: Edit-Copy.
d) Choose menu: Edit-Paste.
e) Select the resource, you want to add the contacts to.
Congrats! Now you have read/write access to the copied
opie contacts as "real" KA/Pi contacts.
********** VERSION 1.9.1 ************
1)
+++ IMPORTANT 1 +++
The storing place of the default calendar
file has changed!
The default calendar file was
Applications/korganizer/mycalendar.ics
on Zaurus and
(yourHomeDir)/korganizer/mycalendar.ics
on Windows/Linux desktop. Now it is
(yourHomeDir)/kdepim/korganizer/mycalendar.ics
on Zaurus, Windows and Linux.
To load the old file, choose menu
File-Load calendar backup.
(It should be loaded automatically
at startup with a warning message displayed).
The place of the configuration file has changed too.
If you want to use your old KO/Pi config,
copy it to
(yourHomeDir)/kdepim/config/korganizerrc
Please read VERSION 1.9.0 - topic 3) as well!
+++ IMPORTANT 2 +++
Because of the new paths, you will need
a new version of the KO/Pi alarm applet
for Zaurus.
Use version >= 1.9.1
2)
Now the QWhat'sThis Icon works for items
in the month view as well.
(See VERSION 1.7.8 Topic 1) ).
3)
You can import birtsdays/anniversaries
from KA/Pi into KO/Pi.
Choose menu File-Import birthdays.
If you import twice, already imported items
will not be imported again, if they
have not been changed in KO/Pi.
4)
When syncing with sharp DTM, now a progress
is shown, when the data is written back.
If there is much data in KO/Pi and no data
in DTM, that can take a long time.
(But only for the first time ).
5)
In the search dialog, you can search
now for the name/email of an attendee
of an event/todo.
To get more space for displaying
search results, the buttons
for "search" and "close" on the
bottom are removed in the PDA version.
You have to click OK in the top right
corner to do a search.
6)
Now it is possible to disable the displaying
of todo items in the Allday part of the Agenda.
Choose Menu Action-Configure,
TAB Todo View, checkbox
"Allday Agenda view shows todos"
7)
If FastLoad is enabled, now the settings and the
calendar data are saved, when KO/Pi is closed.
(If no Fastload is enabled, KO/Pi saves
the data as well, of course)
8)
The Agenda View has a minimize-splitter now,
such that the height of the allday part can be
changed quickly.
********** VERSION 1.9.0 ************
1)
KO/Pi is now merged with the new microKDE from KA/Pi.
KO/Pi accesses now KA/Pi as the addressbook.
The other ddressbook-plugins are not working any longer.
(It is planned, that later KA/Pi itself uses these plugins)
New versions of KO/Pi are only available
together with KA/Pi as the KDE-Pim/Pi package.
2)
If you click on an attendee of a meeting in the
event viewer, a detailed summary of the
attendee is shown.
3)
The place of the configuration file has changed.
If you want to use your old KO/Pi config, copy
Applications/korganizer/config_korganizerrc
to
Applications/korganizer/config/korganizerrc
********** VERSION 1.7.8 ************
1)
Now the QWhat'sThis ist working.
Enable the QWhat'sThis icon in the toolbar.
(You have to restart to reload the changed toolbar config).
Now click on the QWhat'sThis Icon
in the top right corner of KO/Pi.
Then click on an item in the Agenda View:
You will get a detailed display of the items content.
2)
Some other very minor changes.
But I have forgotten the details ...
For that reason I start this log here:
To document my changes, when I am doing it.
********** VERSION 1.7.7 ************
Stable Version of KO/Pi
diff --git a/kmicromail/libetpan/imap/mailimap_parser.c b/kmicromail/libetpan/imap/mailimap_parser.c
index 1c2ecde..560e58a 100644
--- a/kmicromail/libetpan/imap/mailimap_parser.c
+++ b/kmicromail/libetpan/imap/mailimap_parser.c
@@ -1,5476 +1,5494 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2002 - DINH Viet Hoa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the libEtPan! project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Id$
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "mailstream.h"
#include "mailimap_keywords.h"
#include "mailimap_parser.h"
#include "mmapstring.h"
#include "mail.h"
#ifndef UNSTRICT_SYNTAX
#define UNSTRICT_SYNTAX
#endif
/*
Document: internet-drafts/draft-crispin-imapv-15.txt
RFC 2060 (IMAP but rather used draft)
RFC 2234 for all token that are not defined such as ALPHA
*/
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
static int mailimap_address_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_address ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_addr_adl_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_addr_host_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_addr_mailbox_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_addr_name_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_astring_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_atom_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_auth_type_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_base64_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_body_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_extension_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_extension ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_ext_1part_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_ext_1part ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_ext_mpart_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_ext_mpart ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_fields_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fields ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_body_fld_desc_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_fld_dsp_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fld_dsp ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_fld_enc_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fld_enc ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_body_fld_id_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_fld_lang_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fld_lang ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_body_fld_lines_parse(mailstream * fd,
MMAPString * buffer, size_t * index,
uint32_t * result);
static int mailimap_body_fld_md5_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_body_fld_octets_parse(mailstream * fd,
MMAPString * buffer, size_t * index,
uint32_t * result);
static int
mailimap_body_fld_param_parse(mailstream * fd,
MMAPString * buffer, size_t * index,
struct mailimap_body_fld_param ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_type_1part_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_type_1part ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_type_basic_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_type_basic ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_type_mpart_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
struct mailimap_body_type_mpart ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_type_msg_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_type_msg ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_body_type_text_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_type_text **
result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_capability_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_capability ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_capability_data_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_capability_data ** result,
size_t progr_rate,
progress_function * progr_fun);
/*
static gboolean mailimap_date_day_parse(mailstream * fd,
MMAPString * buffer,
guint32 * index,
gint * result);
*/
static int mailimap_date_day_fixed_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
int * result);
static int mailimap_date_month_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result);
/*
struct mailimap_date_text {
gint day;
gint month;
gint year;
};
static gboolean
mailimap_date_text_parse(mailstream * fd, MMAPString * buffer,
guint32 * index, struct mailimap_date_text ** result);
static void mailimap_date_text_free(struct mailimap_date_text * date_text);
*/
static int mailimap_date_year_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result);
static int mailimap_date_time_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_date_time ** t,
size_t progr_rate,
progress_function * progr_fun);
#ifndef UNSTRICT_SYNTAX
static int mailimap_digit_nz_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result);
#endif
static int mailimap_envelope_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_envelope ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_env_bcc_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_env_bcc ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_env_cc_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_env_cc ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_env_date_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_env_from_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_env_from ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_env_in_reply_to_parse(mailstream * fd,
MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_env_message_id_parse(mailstream * fd,
MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_env_reply_to_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_env_reply_to ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_env_sender_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_env_sender ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_env_subject_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_env_to_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_env_to ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_flag_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_flag_extension_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_flag_fetch_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag_fetch ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_flag_perm_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag_perm ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_flag_keyword_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_flag_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag_list ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_header_fld_name_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_header_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_header_list ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_literal_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t * result_len,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_mailbox_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_mailbox_data_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_mailbox_data ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_mbx_list_flags_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_mbx_list_flags ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_mbx_list_oflag_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_mbx_list_oflag ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_mbx_list_oflag_no_sflag_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_mbx_list_oflag ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_mbx_list_sflag_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
int * result);
static int
mailimap_mailbox_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_mailbox_list ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_media_basic_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_media_basic ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_media_message_parse(mailstream * fd, MMAPString * buffer,
size_t * index);
static int
mailimap_media_subtype_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_media_text_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_message_data_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_message_data ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_msg_att_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_msg_att ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_msg_att_dynamic_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_msg_att_dynamic ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_msg_att_static_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_msg_att_static ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_nil_parse(mailstream * fd, MMAPString * buffer,
size_t * index);
static int mailimap_nstring_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t * result_len,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_number_parse(mailstream * fd, MMAPString * buffer,
size_t * index, uint32_t * result);
static int
mailimap_nz_number_parse(mailstream * fd, MMAPString * buffer,
size_t * index, uint32_t * result);
static int
mailimap_quoted_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_quoted_char_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char * result);
static int
mailimap_quoted_specials_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char * result);
static int
mailimap_response_data_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_response_data ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_response_done_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_response_done ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_response_fatal_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_response_fatal ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_response_tagged_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_response_tagged ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_resp_cond_auth_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_resp_cond_auth ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_resp_cond_bye_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_resp_cond_bye ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_resp_cond_state_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_resp_cond_state ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_resp_text_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_resp_text ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_resp_text_code_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_resp_text_code ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_section_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_section ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_section_msgtext_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_section_msgtext ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_section_part_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_section_part ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_section_spec_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_section_spec ** result,
size_t progr_rate,
progress_function * progr_fun);
static int
mailimap_section_text_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_section_text ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_status_att_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result);
static int
mailimap_string_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t * result_len,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_tag_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_text_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun);
static int mailimap_time_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
int * phour, int * pmin, int * psec);
static int mailimap_uniqueid_parse(mailstream * fd, MMAPString * buffer,
size_t * index, uint32_t * result);
static int mailimap_zone_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result);
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ******************** TOOLS **************************** */
static int mailimap_unstrict_char_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char token)
{
size_t cur_token;
int r;
cur_token = * index;
#ifdef UNSTRICT_SYNTAX
/* can accept unstrict syntax */
mailimap_space_parse(fd, buffer, &cur_token);
if (token == ' ') {
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
#endif
r = mailimap_char_parse(fd, buffer, &cur_token, token);
if (r != MAILIMAP_NO_ERROR)
return r;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
static int mailimap_oparenth_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '(');
}
static int mailimap_cparenth_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, ')');
}
static int mailimap_oaccolade_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '{');
}
static int mailimap_caccolade_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '}');
}
static int mailimap_plus_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '+');
}
static int mailimap_minus_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '-');
}
static int mailimap_star_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '*');
}
static int mailimap_dot_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '.');
}
static int mailimap_colon_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, ':');
}
static int mailimap_lower_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '<');
}
static int mailimap_greater_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '>');
}
static int mailimap_obracket_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, '[');
}
static int mailimap_cbracket_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_unstrict_char_parse(fd, buffer, index, ']');
}
static int mailimap_dquote_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
return mailimap_char_parse(fd, buffer, index, '\"');
}
static int mailimap_crlf_parse(mailstream * fd, MMAPString * buffer,
size_t * index)
{
size_t cur_token = * index;
#ifdef UNSTRICT_SYNTAX
mailimap_space_parse(fd, buffer, &cur_token);
#endif
if (mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "\r\n")) {
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
#ifdef UNSTRICT_SYNTAX
else if (mailimap_unstrict_char_parse(fd, buffer, &cur_token, '\n')) {
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
#endif
else
return MAILIMAP_ERROR_PARSE;
}
typedef int mailimap_struct_parser(mailstream * fd, MMAPString * buffer,
size_t * index, void * result,
size_t progr_rate,
progress_function * progr_fun);
typedef int mailimap_struct_destructor(void * result);
static int
mailimap_struct_multiple_parse(mailstream * fd, MMAPString * buffer,
size_t * index, clist ** result,
mailimap_struct_parser * parser,
mailimap_struct_destructor * destructor,
size_t progr_rate,
progress_function * progr_fun)
{
clist * struct_list;
size_t cur_token;
void * value;
int r;
int res;
cur_token = * index;
r = parser(fd, buffer, &cur_token, &value, progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
struct_list = clist_new();
if (struct_list == NULL) {
destructor(value);
res = MAILIMAP_ERROR_MEMORY;
goto err;
}
r = clist_append(struct_list, value);
if (r < 0) {
destructor(value);
res = MAILIMAP_ERROR_MEMORY;
goto free_list;
}
while (1) {
r = parser(fd, buffer, &cur_token, &value, progr_rate, progr_fun);
if (r == MAILIMAP_ERROR_PARSE)
break;
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_list;
}
r = clist_append(struct_list, value);
if (r < 0) {
destructor(value);
res = MAILIMAP_ERROR_MEMORY;
goto free_list;
}
}
* result = struct_list;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free_list:
clist_foreach(struct_list, (clist_func) destructor, NULL);
clist_free(struct_list);
err:
return res;
}
static int
mailimap_struct_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index, clist ** result,
char symbol,
mailimap_struct_parser * parser,
mailimap_struct_destructor * destructor,
size_t progr_rate,
progress_function * progr_fun)
{
clist * struct_list;
size_t cur_token;
void * value;
size_t final_token;
int r;
int res;
cur_token = * index;
struct_list = NULL;
r = parser(fd, buffer, &cur_token, &value, progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
struct_list = clist_new();
if (struct_list == NULL) {
destructor(value);
res = MAILIMAP_ERROR_MEMORY;
goto err;
}
r = clist_append(struct_list, value);
if (r < 0) {
destructor(value);
res = MAILIMAP_ERROR_MEMORY;
goto free_list;
}
final_token = cur_token;
while (1) {
r = mailimap_unstrict_char_parse(fd, buffer, &cur_token, symbol);
if (r == MAILIMAP_ERROR_PARSE)
break;
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_list;
}
r = parser(fd, buffer, &cur_token, &value, progr_rate, progr_fun);
if (r == MAILIMAP_ERROR_PARSE)
break;
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_list;
}
r = clist_append(struct_list, value);
if (r < 0) {
destructor(value);
res = MAILIMAP_ERROR_MEMORY;
goto free_list;
}
final_token = cur_token;
}
* result = struct_list;
* index = final_token;
return MAILIMAP_NO_ERROR;
free_list:
clist_foreach(struct_list, (clist_func) destructor, NULL);
clist_free(struct_list);
err:
return res;
}
static int
mailimap_struct_spaced_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index, clist ** result,
mailimap_struct_parser * parser,
mailimap_struct_destructor * destructor,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_struct_list_parse(fd, buffer, index, result,
' ', parser, destructor,
progr_rate, progr_fun);
}
static int
mailimap_custom_string_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
int (* is_custom_char)(char))
{
size_t begin;
size_t end;
char * gstr;
begin = * index;
#ifdef UNSTRICT_SYNTAX
mailimap_space_parse(fd, buffer, &begin);
#endif
end = begin;
while (is_custom_char(buffer->str[end]))
end ++;
if (end != begin) {
gstr = malloc(end - begin + 1);
if (gstr == NULL)
return MAILIMAP_ERROR_MEMORY;
strncpy(gstr, buffer->str + begin, end - begin);
gstr[end - begin] = '\0';
* index = end;
* result = gstr;
return MAILIMAP_NO_ERROR;
}
else
return MAILIMAP_ERROR_PARSE;
}
static int
mailimap_nz_number_alloc_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
uint32_t ** result,
size_t progr_rate,
progress_function * progr_fun)
{
uint32_t number;
uint32_t * number_alloc;
size_t cur_token;
int r;
cur_token = * index;
r = mailimap_nz_number_parse(fd, buffer, &cur_token, &number);
if (r != MAILIMAP_NO_ERROR)
return r;
number_alloc = mailimap_number_alloc_new(number);
if (number_alloc == NULL)
return MAILIMAP_ERROR_MEMORY;
* index = cur_token;
* result = number_alloc;
return MAILIMAP_NO_ERROR;
}
static int is_ctl(char ch)
{
unsigned char uch = (unsigned char) ch;
return (uch <= 0x1F);
}
static int is_char(char ch)
{
#ifdef UNSTRICT_SYNTAX
return (ch != 0);
#else
unsigned char uch = ch;
return (uch >= 0x01) && (uch <= 0x7f);
#endif
}
static int is_alpha(char ch)
{
return ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && (ch <= 'z')));
}
static int is_digit(char ch)
{
return (ch >= '0') && (ch <= '9');
}
static int mailimap_digit_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result)
{
size_t cur_token;
cur_token = * index;
if (is_digit(buffer->str[cur_token])) {
* result = buffer->str[cur_token] - '0';
cur_token ++;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
else
return MAILIMAP_ERROR_PARSE;
}
/* ******************** parser **************************** */
/*
address = "(" addr-name SP addr-adl SP addr-mailbox SP
addr-host ")"
*/
static int mailimap_address_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_address ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
char * addr_name;
char * addr_adl;
char * addr_mailbox;
char * addr_host;
struct mailimap_address * addr;
int r;
int res;
cur_token = * index;
addr_name = NULL;
addr_adl = NULL;
addr_mailbox = NULL;
addr_host = NULL;
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_addr_name_parse(fd, buffer, &cur_token, &addr_name,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto addr_name_free;
}
r = mailimap_addr_adl_parse(fd, buffer, &cur_token, &addr_adl,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto addr_name_free;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto addr_adl_free;
}
r = mailimap_addr_mailbox_parse(fd, buffer, &cur_token, &addr_mailbox,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto addr_adl_free;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto addr_mailbox_free;
}
r = mailimap_addr_host_parse(fd, buffer, &cur_token, &addr_host,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto addr_mailbox_free;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto addr_host_free;
}
addr = mailimap_address_new(addr_name, addr_adl, addr_mailbox, addr_host);
if (addr == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto addr_host_free;
}
* result = addr;
* index = cur_token;
return MAILIMAP_NO_ERROR;
addr_host_free:
mailimap_addr_host_free(addr_host);
addr_mailbox_free:
mailimap_addr_mailbox_free(addr_mailbox);
addr_adl_free:
mailimap_addr_adl_free(addr_adl);
addr_name_free:
mailimap_addr_name_free(addr_name);
err:
return res;
}
/*
addr-adl = nstring
; Holds route from [RFC-822] route-addr if
; non-NIL
*/
static int mailimap_addr_adl_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
addr-host = nstring
; NIL indicates [RFC-822] group syntax.
; Otherwise, holds [RFC-822] domain name
*/
static int mailimap_addr_host_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
addr-mailbox = nstring
; NIL indicates end of [RFC-822] group; if
; non-NIL and addr-host is NIL, holds
; [RFC-822] group name.
; Otherwise, holds [RFC-822] local-part
; after removing [RFC-822] quoting
*/
static int mailimap_addr_mailbox_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
addr-name = nstring
; If non-NIL, holds phrase from [RFC-822]
; mailbox after removing [RFC-822] quoting
*/
static int mailimap_addr_name_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
NOT IMPLEMENTED
append = "APPEND" SP mailbox [SP flag-list] [SP date-time] SP
literal
*/
/*
astring = 1*ASTRING-CHAR / string
*/
static int is_astring_char(char ch);
static int
mailimap_atom_astring_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_custom_string_parse(fd, buffer, index, result,
is_astring_char);
}
static int
mailimap_astring_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
char * astring;
int r;
cur_token = * index;
r = mailimap_atom_astring_parse(fd, buffer, &cur_token, &astring,
progr_rate, progr_fun);
switch (r) {
case MAILIMAP_NO_ERROR:
break;
case MAILIMAP_ERROR_PARSE:
r = mailimap_string_parse(fd, buffer, &cur_token, &astring, NULL,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
break;
default:
return r;
}
* result = astring;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
ASTRING-CHAR = ATOM-CHAR / resp-specials
*/
static int is_atom_char(char ch);
static int is_resp_specials(char ch);
static int is_astring_char(char ch)
{
if (is_atom_char(ch))
return TRUE;
if (is_resp_specials(ch))
return TRUE;
return FALSE;
}
/*
atom = 1*ATOM-CHAR
*/
static int mailimap_atom_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_custom_string_parse(fd, buffer, index, result,
is_atom_char);
}
/*
ATOM-CHAR = <any CHAR except atom-specials>
*/
static int is_atom_specials(char ch);
static int is_atom_char(char ch)
{
if (is_atom_specials(ch))
return FALSE;
return is_char(ch);
}
/*
atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards /
quoted-specials / resp-specials
no "}" because there is no need (Mark Crispin)
*/
static int is_quoted_specials(char ch);
static int is_list_wildcards(char ch);
static int is_atom_specials(char ch)
{
switch (ch) {
case '(':
case ')':
case '{':
case ' ':
return TRUE;
};
if (is_ctl(ch))
return TRUE;
if (is_list_wildcards(ch))
return TRUE;
if (is_resp_specials(ch))
return TRUE;
return is_quoted_specials(ch);
}
/*
NOT IMPLEMENTED
authenticate = "AUTHENTICATE" SP auth-type *(CRLF base64)
*/
/*
auth-type = atom
; Defined by [SASL]
*/
static int mailimap_auth_type_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_atom_parse(fd, buffer, index, result,
progr_rate, progr_fun);
}
/*
base64 = *(4base64-char) [base64-terminal]
*/
static int is_base64_4char(char * str);
static int is_base64_terminal(char * str);
static int mailimap_base64_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t begin;
size_t end;
char * gstr;
begin = * index;
end = begin;
while (is_base64_4char(buffer->str + end))
end += 4;
if (is_base64_terminal(buffer->str + end))
end += 4;
else
return MAILIMAP_ERROR_PARSE;
gstr = malloc(end - begin + 1);
if (gstr == NULL)
return MAILIMAP_ERROR_MEMORY;
strncpy(gstr, buffer->str + begin, end - begin);
gstr[end - begin] = '\0';
* result = gstr;
* index = end;
return MAILIMAP_NO_ERROR;
}
/*
base64-char = ALPHA / DIGIT / "+" / "/"
; Case-sensitive
*/
static int is_base64_char(char ch)
{
return (is_alpha(ch) || is_digit(ch) || ch == '+' || ch == '/');
}
static int is_base64_4char(char * str)
{
size_t i;
for (i = 0 ; i < 4 ; i++)
if (!is_base64_char(str[i]))
return FALSE;
return TRUE;
}
/*
base64-terminal = (2base64-char "==") / (3base64-char "=")
*/
static int is_base64_terminal(char * str)
{
if (str[0] == 0)
return FALSE;
if (str[1] == 0)
return FALSE;
if (str[2] == 0)
return FALSE;
if (str[3] == 0)
return FALSE;
if (is_base64_char(str[0]) || is_base64_char(str[1])
|| str[2] == '=' || str[3] == '=')
return TRUE;
if (is_base64_char(str[0]) || is_base64_char(str[1])
|| is_base64_char(str[2]) || str[3] == '=')
return TRUE;
return FALSE;
}
/*
body = "(" (body-type-1part / body-type-mpart) ")"
*/
static int mailimap_body_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body ** result,
size_t progr_rate,
progress_function * progr_fun)
{
struct mailimap_body_type_1part * body_type_1part;
struct mailimap_body_type_mpart * body_type_mpart;
struct mailimap_body * body;
size_t cur_token;
int type;
int r;
int res;
cur_token = * index;
body_type_1part = NULL;
body_type_mpart = NULL;
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
type = MAILIMAP_BODY_ERROR; /* XXX - removes a gcc warning */
r = mailimap_body_type_1part_parse(fd, buffer, &cur_token, &body_type_1part,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_1PART;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_body_type_mpart_parse(fd, buffer, &cur_token,
&body_type_mpart,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_MPART;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free;
}
body = mailimap_body_new(type, body_type_1part, body_type_mpart);
if (body == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = body;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (body_type_1part)
mailimap_body_type_1part_free(body_type_1part);
if (body_type_mpart)
mailimap_body_type_mpart_free(body_type_mpart);
err:
return res;
}
/*
body-extension = nstring / number /
"(" body-extension *(SP body-extension) ")"
; Future expansion. Client implementations
; MUST accept body-extension fields. Server
; implementations MUST NOT generate
; body-extension fields except as defined by
; future standard or standards-track
; revisions of this specification.
*/
/*
"(" body-extension *(SP body-extension) ")"
*/
static int
mailimap_body_ext_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
clist ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
clist * list;
int r;
int res;
cur_token = * index;
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_struct_spaced_list_parse(fd, buffer,
&cur_token, &list,
(mailimap_struct_parser * )
mailimap_body_extension_parse,
(mailimap_struct_destructor * )
mailimap_body_extension_free,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_list;
}
* index = cur_token;
* result = list;
return MAILIMAP_NO_ERROR;
free_list:
clist_foreach(list, (clist_func) mailimap_body_extension_free, NULL);
clist_free(list);
err:
return res;
}
/*
body-extension = nstring / number /
"(" body-extension *(SP body-extension) ")"
; Future expansion. Client implementations
; MUST accept body-extension fields. Server
; implementations MUST NOT generate
; body-extension fields except as defined by
; future standard or standards-track
; revisions of this specification.
*/
static int
mailimap_body_extension_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_extension ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
uint32_t number;
char * nstring;
clist * body_extension_list;
struct mailimap_body_extension * body_extension;
int type;
int r;
int res;
cur_token = * index;
nstring = NULL;
number = 0;
body_extension_list = NULL;
type = MAILIMAP_BODY_EXTENSION_ERROR; /* XXX - removes a gcc warning */
r = mailimap_nstring_parse(fd, buffer, &cur_token, &nstring, NULL,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_EXTENSION_NSTRING;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_number_parse(fd, buffer, &cur_token, &number);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_EXTENSION_NUMBER;
}
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_body_ext_list_parse(fd, buffer, &cur_token,
&body_extension_list,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_EXTENSION_LIST;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
body_extension = mailimap_body_extension_new(type, nstring, number,
body_extension_list);
if (body_extension == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = body_extension;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (nstring != NULL)
mailimap_nstring_free(nstring);
if (body_extension_list) {
clist_foreach(body_extension_list,
(clist_func) mailimap_body_extension_free,
NULL);
clist_free(body_extension_list);
}
err:
return res;
}
/*
body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
*(SP body-extension)]]
; MUST NOT be returned on non-extensible
; "BODY" fetch
*/
/*
*(SP body-extension)
*/
static int
mailimap_body_ext_1part_3_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
clist ** body_ext_list,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int r;
cur_token = * index;
* body_ext_list = NULL;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_struct_spaced_list_parse(fd, buffer, &cur_token,
body_ext_list,
(mailimap_struct_parser *)
mailimap_body_extension_parse,
(mailimap_struct_destructor *)
mailimap_body_extension_free,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
[SP body-fld-lang
*(SP body-extension)]]
*/
static int
mailimap_body_ext_1part_2_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fld_lang ** fld_lang,
clist ** body_ext_list,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int r;
cur_token = * index;
* fld_lang = NULL;
* body_ext_list = NULL;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_body_fld_lang_parse(fd, buffer, &cur_token, fld_lang,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_body_ext_1part_3_parse(fd, buffer, &cur_token,
body_ext_list, progr_rate, progr_fun);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
return r;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
SP body-fld-dsp [SP body-fld-lang
*(SP body-extension)]]
*/
static int
mailimap_body_ext_1part_1_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fld_dsp ** fld_dsp,
struct mailimap_body_fld_lang ** fld_lang,
clist ** body_ext_list,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int r;
cur_token = * index;
* fld_dsp = NULL;
* fld_lang = NULL;
* body_ext_list = NULL;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_body_fld_dsp_parse(fd, buffer, &cur_token, fld_dsp,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_body_ext_1part_2_parse(fd, buffer, &cur_token,
fld_lang, body_ext_list,
progr_rate, progr_fun);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
return r;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
body-ext-1part = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
*(SP body-extension)]]
; MUST NOT be returned on non-extensible
; "BODY" fetch
*/
static int
mailimap_body_ext_1part_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_ext_1part ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
char * fld_md5;
struct mailimap_body_fld_dsp * fld_dsp;
struct mailimap_body_fld_lang * fld_lang;
clist * body_ext_list;
int r;
int res;
struct mailimap_body_ext_1part * ext_1part;
cur_token = * index;
fld_md5 = NULL;
fld_dsp = NULL;
fld_lang = NULL;
body_ext_list = NULL;
r = mailimap_body_fld_md5_parse(fd, buffer, &cur_token, &fld_md5,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_body_ext_1part_1_parse(fd, buffer, &cur_token,
&fld_dsp,
&fld_lang,
&body_ext_list,
progr_rate, progr_fun);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) {
res = r;
goto free;
}
ext_1part = mailimap_body_ext_1part_new(fld_md5, fld_dsp, fld_lang,
body_ext_list);
if (ext_1part == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = ext_1part;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (body_ext_list) {
clist_foreach(body_ext_list, (clist_func) mailimap_body_extension_free,
NULL);
clist_free(body_ext_list);
}
if (fld_lang)
mailimap_body_fld_lang_free(fld_lang);
if (fld_dsp)
mailimap_body_fld_dsp_free(fld_dsp);
mailimap_body_fld_md5_free(fld_md5);
err:
return res;
}
/*
body-ext-mpart = body-fld-param [SP body-fld-dsp [SP body-fld-lang
*(SP body-extension)]]
; MUST NOT be returned on non-extensible
; "BODY" fetch
*/
static int
mailimap_body_ext_mpart_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_ext_mpart ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_body_fld_dsp * fld_dsp;
struct mailimap_body_fld_lang * fld_lang;
struct mailimap_body_fld_param * fld_param;
clist * body_ext_list;
struct mailimap_body_ext_mpart * ext_mpart;
int r;
int res;
cur_token = * index;
fld_param = NULL;
fld_dsp = NULL;
fld_lang = NULL;
body_ext_list = NULL;
r = mailimap_body_fld_param_parse(fd, buffer, &cur_token, &fld_param,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_body_ext_1part_1_parse(fd, buffer, &cur_token,
&fld_dsp,
&fld_lang,
&body_ext_list,
progr_rate, progr_fun);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) {
res = r;
goto free;
}
ext_mpart = mailimap_body_ext_mpart_new(fld_param, fld_dsp, fld_lang,
body_ext_list);
if (ext_mpart == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = ext_mpart;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (body_ext_list) {
clist_foreach(body_ext_list, (clist_func) mailimap_body_extension_free,
NULL);
clist_free(body_ext_list);
}
if (fld_lang)
mailimap_body_fld_lang_free(fld_lang);
if (fld_dsp)
mailimap_body_fld_dsp_free(fld_dsp);
if (fld_param != NULL)
mailimap_body_fld_param_free(fld_param);
err:
return res;
}
/*
body-fields = body-fld-param SP body-fld-id SP body-fld-desc SP
body-fld-enc SP body-fld-octets
*/
static int
mailimap_body_fields_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fields ** result,
size_t progr_rate,
progress_function * progr_fun)
{
struct mailimap_body_fields * body_fields;
size_t cur_token;
struct mailimap_body_fld_param * body_fld_param;
char * body_fld_id;
char * body_fld_desc;
struct mailimap_body_fld_enc * body_fld_enc;
size_t body_fld_octets;
int r;
int res;
body_fld_param = NULL;
body_fld_id = NULL;
body_fld_desc = NULL;
body_fld_enc = NULL;
body_fld_octets = 0;
cur_token = * index;
r = mailimap_body_fld_param_parse(fd, buffer, &cur_token, &body_fld_param,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto fld_param_free;
}
r = mailimap_body_fld_id_parse(fd, buffer, &cur_token, &body_fld_id,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto fld_param_free;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto fld_id_free;
}
r = mailimap_body_fld_desc_parse(fd, buffer, &cur_token, &body_fld_desc,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto fld_id_free;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto fld_desc_free;
}
r = mailimap_body_fld_enc_parse(fd, buffer, &cur_token, &body_fld_enc,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto fld_desc_free;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto fld_enc_free;
}
r = mailimap_body_fld_octets_parse(fd, buffer, &cur_token,
&body_fld_octets);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto fld_enc_free;
}
body_fields = mailimap_body_fields_new(body_fld_param,
body_fld_id,
body_fld_desc,
body_fld_enc,
body_fld_octets);
if (body_fields == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto fld_enc_free;
}
* result = body_fields;
* index = cur_token;
return MAILIMAP_NO_ERROR;
fld_enc_free:
mailimap_body_fld_enc_free(body_fld_enc);
fld_desc_free:
mailimap_body_fld_desc_free(body_fld_desc);
fld_id_free:
mailimap_body_fld_id_free(body_fld_id);
fld_param_free:
if (body_fld_param != NULL)
mailimap_body_fld_param_free(body_fld_param);
err:
return res;
}
/*
body-fld-desc = nstring
*/
static int mailimap_body_fld_desc_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
body-fld-dsp = "(" string SP body-fld-param ")" / nil
*/
static int
mailimap_body_fld_dsp_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fld_dsp ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
char * name;
struct mailimap_body_fld_param * body_fld_param;
struct mailimap_body_fld_dsp * body_fld_dsp;
int res;
int r;
cur_token = * index;
name = NULL;
body_fld_param = NULL;
r = mailimap_nil_parse(fd, buffer, &cur_token);
if (r == MAILIMAP_NO_ERROR) {
* result = NULL;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
if (r != MAILIMAP_ERROR_PARSE) {
res = r;
goto err;
}
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_string_parse(fd, buffer, &cur_token, &name, NULL,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto string_free;
}
r = mailimap_body_fld_param_parse(fd, buffer, &cur_token,
&body_fld_param,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto string_free;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto string_free;
}
body_fld_dsp = mailimap_body_fld_dsp_new(name, body_fld_param);
if (body_fld_dsp == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto fld_param_free;
}
* index = cur_token;
* result = body_fld_dsp;
return MAILIMAP_NO_ERROR;
fld_param_free:
if (body_fld_param != NULL)
mailimap_body_fld_param_free(body_fld_param);
string_free:
mailimap_string_free(name);
err:
return res;
}
/*
body-fld-enc = (DQUOTE ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
"QUOTED-PRINTABLE") DQUOTE) / string
*/
static inline int
mailimap_body_fld_known_enc_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
int * result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int type;
int r;
int res;
cur_token = * index;
r = mailimap_dquote_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
type = mailimap_encoding_get_token_value(fd, buffer, &cur_token);
if (type == -1) {
res = MAILIMAP_ERROR_PARSE;
goto err;
}
r = mailimap_dquote_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
* result = type;
* index = cur_token;
return MAILIMAP_NO_ERROR;
err:
return res;
}
static int
mailimap_body_fld_enc_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fld_enc ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int type;
char * value;
struct mailimap_body_fld_enc * body_fld_enc;
int r;
int res;
cur_token = * index;
r = mailimap_body_fld_known_enc_parse(fd, buffer, &cur_token,
&type, progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR) {
value = NULL;
}
else if (r == MAILIMAP_ERROR_PARSE) {
type = MAILIMAP_BODY_FLD_ENC_OTHER;
r = mailimap_string_parse(fd, buffer, &cur_token, &value, NULL,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
- res = r;
+ // LR start
+ // accept NIL and set type to utf8
+ int ret = r;
+ r = mailimap_char_parse(fd, buffer, &cur_token, 'N');
+ if (r == MAILIMAP_NO_ERROR) {
+ r = mailimap_char_parse(fd, buffer, &cur_token, 'I');
+ if (r == MAILIMAP_NO_ERROR) {
+ r = mailimap_char_parse(fd, buffer, &cur_token, 'L');
+ if (r == MAILIMAP_NO_ERROR) {
+ type = 4;
+ ret = MAILIMAP_NO_ERROR;
+ value = NULL;
+ }
+ }
+ }
+ if ( ret != MAILIMAP_NO_ERROR ) {
+ res = ret;
goto err;
}
+ // LR end
+ }
}
else {
res = r;
goto err;
}
body_fld_enc = mailimap_body_fld_enc_new(type, value);
if (body_fld_enc == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto value_free;
}
* result = body_fld_enc;
* index = cur_token;
return MAILIMAP_NO_ERROR;
value_free:
if (value)
mailimap_string_free(value);
err:
return res;
}
/*
body-fld-id = nstring
*/
static int mailimap_body_fld_id_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
body-fld-lang = nstring / "(" string *(SP string) ")"
*/
/*
"(" string *(SP string) ")"
*/
static int
mailimap_body_fld_lang_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index, clist ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
clist * list;
int r;
int res;
cur_token = * index;
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
list = clist_new();
if (list == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto err;
}
while (1) {
char * elt;
r = mailimap_string_parse(fd, buffer, &cur_token, &elt, NULL,
progr_rate, progr_fun);
if (r != MAILIMAP_ERROR_PARSE)
break;
else if (r == MAILIMAP_NO_ERROR) {
r = clist_append(list, elt);
if (r < 0) {
mailimap_string_free(elt);
res = r;
goto list_free;
}
}
else {
res = r;
goto list_free;
}
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto list_free;
}
* index = cur_token;
* result = list;
return MAILIMAP_NO_ERROR;
list_free:
clist_foreach(list, (clist_func) mailimap_string_free, NULL);
clist_free(list);
err:
return res;
}
/*
body-fld-lang = nstring / "(" string *(SP string) ")"
*/
static int
mailimap_body_fld_lang_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_fld_lang ** result,
size_t progr_rate,
progress_function * progr_fun)
{
char * value;
clist * list;
struct mailimap_body_fld_lang * fld_lang;
int type;
int r;
int res;
size_t cur_token;
cur_token = * index;
value = NULL;
list = NULL;
type = MAILIMAP_BODY_FLD_LANG_ERROR; /* XXX - removes a gcc warning */
r = mailimap_nstring_parse(fd, buffer, &cur_token, &value, NULL,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_FLD_LANG_SINGLE;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_body_fld_lang_list_parse(fd, buffer, &cur_token, &list,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_FLD_LANG_LIST;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
fld_lang = mailimap_body_fld_lang_new(type, value, list);
if (fld_lang == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = fld_lang;
return MAILIMAP_NO_ERROR;
free:
if (value)
mailimap_nstring_free(value);
if (list) {
clist_foreach(list, (clist_func) mailimap_string_free, NULL);
clist_free(list);
}
err:
return res;
}
/*
body-fld-lines = number
*/
static int mailimap_body_fld_lines_parse(mailstream * fd,
MMAPString * buffer, size_t * index,
uint32_t * result)
{
return mailimap_number_parse(fd, buffer, index, result);
}
/*
body-fld-md5 = nstring
*/
static int mailimap_body_fld_md5_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
body-fld-octets = number
*/
static int mailimap_body_fld_octets_parse(mailstream * fd,
MMAPString * buffer, size_t * index,
uint32_t * result)
{
return mailimap_number_parse(fd, buffer, index, result);
}
/*
body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
*/
/*
string SP string
*/
static int
mailimap_single_body_fld_param_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_single_body_fld_param **
result,
size_t progr_rate,
progress_function * progr_fun)
{
struct mailimap_single_body_fld_param * param;
char * name;
char * value;
size_t cur_token;
int r;
int res;
cur_token = * index;
name = NULL;
value = NULL;
r = mailimap_string_parse(fd, buffer, &cur_token, &name, NULL,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_name;
}
r = mailimap_string_parse(fd, buffer, &cur_token, &value, NULL,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_name;
}
param = mailimap_single_body_fld_param_new(name, value);
if (param == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_value;
}
* result = param;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free_value:
mailimap_string_free(name);
free_name:
mailimap_string_free(value);
err:
return res;
}
/*
body-fld-param = "(" string SP string *(SP string SP string) ")" / nil
*/
static int
mailimap_body_fld_param_parse(mailstream * fd,
MMAPString * buffer, size_t * index,
struct mailimap_body_fld_param ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
clist * param_list;
struct mailimap_body_fld_param * fld_param;
int r;
int res;
param_list = NULL;
cur_token = * index;
r = mailimap_nil_parse(fd, buffer, &cur_token);
if (r == MAILIMAP_NO_ERROR) {
* result = NULL;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
if (r != MAILIMAP_ERROR_PARSE) {
res = r;
goto err;
}
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_struct_spaced_list_parse(fd, buffer, &cur_token, &param_list,
(mailimap_struct_parser *)
mailimap_single_body_fld_param_parse,
(mailimap_struct_destructor *)
mailimap_single_body_fld_param_free,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free;
}
fld_param = mailimap_body_fld_param_new(param_list);
if (fld_param == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = fld_param;
return MAILIMAP_NO_ERROR;
free:
clist_foreach(param_list,
(clist_func) mailimap_single_body_fld_param_free,
NULL);
clist_free(param_list);
err:
return res;
}
/*
body-type-1part = (body-type-basic / body-type-msg / body-type-text)
[SP body-ext-1part]
*/
static int
mailimap_body_type_1part_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_type_1part ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_body_type_1part * body_type_1part;
struct mailimap_body_type_basic * body_type_basic;
struct mailimap_body_type_msg * body_type_msg;
struct mailimap_body_type_text * body_type_text;
struct mailimap_body_ext_1part * body_ext_1part;
int type;
size_t final_token;
int r;
int res;
cur_token = * index;
body_type_basic = NULL;
body_type_msg = NULL;
body_type_text = NULL;
body_ext_1part = NULL;
type = MAILIMAP_BODY_TYPE_1PART_ERROR; /* XXX - removes a gcc warning */
r = mailimap_body_type_msg_parse(fd, buffer, &cur_token,
&body_type_msg,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_TYPE_1PART_MSG;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_body_type_text_parse(fd, buffer, &cur_token,
&body_type_text,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_TYPE_1PART_TEXT;
}
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_body_type_basic_parse(fd, buffer, &cur_token,
&body_type_basic,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_BODY_TYPE_1PART_BASIC;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
final_token = cur_token;
body_ext_1part = NULL;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r == MAILIMAP_NO_ERROR) {
r = mailimap_body_ext_1part_parse(fd, buffer, &cur_token, &body_ext_1part,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
final_token = cur_token;
else if (r == MAILIMAP_ERROR_PARSE) {
/* do nothing */
}
else {
res = r;
goto free;
}
}
else if (r == MAILIMAP_ERROR_PARSE) {
/* do nothing */
}
else {
res = r;
goto free;
}
body_type_1part = mailimap_body_type_1part_new(type, body_type_basic,
body_type_msg, body_type_text,
body_ext_1part);
if (body_type_1part == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = final_token;
* result = body_type_1part;
return MAILIMAP_NO_ERROR;
free:
if (body_type_basic)
mailimap_body_type_basic_free(body_type_basic);
if (body_type_msg)
mailimap_body_type_msg_free(body_type_msg);
if (body_type_text)
mailimap_body_type_text_free(body_type_text);
if (body_ext_1part)
mailimap_body_ext_1part_free(body_ext_1part);
err:
return res;
}
/*
body-type-basic = media-basic SP body-fields
; MESSAGE subtype MUST NOT be "RFC822"
*/
static int
mailimap_body_type_basic_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_type_basic ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_body_type_basic * body_type_basic;
struct mailimap_media_basic * media_basic;
struct mailimap_body_fields * body_fields;
int r;
int res;
cur_token = * index;
media_basic = NULL;
body_fields = NULL;
r = mailimap_media_basic_parse(fd, buffer, &cur_token, &media_basic,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_media_basic;
}
r = mailimap_body_fields_parse(fd, buffer, &cur_token, &body_fields,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_media_basic;
}
body_type_basic = mailimap_body_type_basic_new(media_basic, body_fields);
if (body_type_basic == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_body_fields;
}
* index = cur_token;
* result = body_type_basic;
return MAILIMAP_NO_ERROR;
free_body_fields:
mailimap_body_fields_free(body_fields);
free_media_basic:
mailimap_media_basic_free(media_basic);
err:
return res;
}
/*
body-type-mpart = 1*body SP media-subtype
[SP body-ext-mpart]
*/
static int
mailimap_body_type_mpart_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
struct mailimap_body_type_mpart ** result,
size_t progr_rate,
progress_function * progr_fun)
{
struct mailimap_body_type_mpart * body_type_mpart;
clist * body_list;
size_t cur_token;
size_t final_token;
char * media_subtype;
struct mailimap_body_ext_mpart * body_ext_mpart;
int r;
int res;
cur_token = * index;
body_list = NULL;
media_subtype = NULL;
body_ext_mpart = NULL;
r = mailimap_struct_multiple_parse(fd, buffer, &cur_token,
&body_list,
(mailimap_struct_parser *)
mailimap_body_parse,
(mailimap_struct_destructor *)
mailimap_body_free,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_body_list;
}
r = mailimap_media_subtype_parse(fd, buffer, &cur_token, &media_subtype,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_body_list;
}
final_token = cur_token;
body_ext_mpart = NULL;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r == MAILIMAP_NO_ERROR) {
r = mailimap_body_ext_mpart_parse(fd, buffer, &cur_token, &body_ext_mpart,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
final_token = cur_token;
else if (r == MAILIMAP_ERROR_PARSE) {
/* do nothing */
}
else {
res = r;
goto free_body_list;
}
}
else if (r == MAILIMAP_ERROR_PARSE) {
/* do nothing */
}
else {
res = r;
goto free_body_list;
}
body_type_mpart = mailimap_body_type_mpart_new(body_list, media_subtype,
body_ext_mpart);
if (body_type_mpart == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_body_ext_mpart;
}
* result = body_type_mpart;
* index = final_token;
return MAILIMAP_NO_ERROR;
free_body_ext_mpart:
if (body_ext_mpart)
mailimap_body_ext_mpart_free(body_ext_mpart);
mailimap_media_subtype_free(media_subtype);
free_body_list:
clist_foreach(body_list, (clist_func) mailimap_body_free, NULL);
clist_free(body_list);
err:
return res;
}
/*
body-type-msg = media-message SP body-fields SP envelope
SP body SP body-fld-lines
*/
static int
mailimap_body_type_msg_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_type_msg ** result,
size_t progr_rate,
progress_function * progr_fun)
{
struct mailimap_body_fields * body_fields;
struct mailimap_envelope * envelope;
struct mailimap_body * body;
uint32_t body_fld_lines;
struct mailimap_body_type_msg * body_type_msg;
size_t cur_token;
int r;
int res;
cur_token = * index;
body_fields = NULL;
envelope = NULL;
body = NULL;
body_fld_lines = 0;
r = mailimap_media_message_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_body_fields_parse(fd, buffer, &cur_token, &body_fields,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto body_fields;
}
r = mailimap_envelope_parse(fd, buffer, &cur_token, &envelope,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto body_fields;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto envelope;
}
r = mailimap_body_parse(fd, buffer, &cur_token, &body,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto envelope;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto body;
}
r = mailimap_body_fld_lines_parse(fd, buffer, &cur_token,
&body_fld_lines);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto body;
}
body_type_msg = mailimap_body_type_msg_new(body_fields, envelope,
body, body_fld_lines);
if (body_type_msg == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto body;
}
* result = body_type_msg;
* index = cur_token;
return MAILIMAP_NO_ERROR;
body:
mailimap_body_free(body);
envelope:
mailimap_envelope_free(envelope);
body_fields:
mailimap_body_fields_free(body_fields);
err:
return res;
}
/*
body-type-text = media-text SP body-fields SP body-fld-lines
*/
static int
mailimap_body_type_text_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_body_type_text **
result,
size_t progr_rate,
progress_function * progr_fun)
{
char * media_text;
struct mailimap_body_fields * body_fields;
uint32_t body_fld_lines;
struct mailimap_body_type_text * body_type_text;
size_t cur_token;
int r;
int res;
media_text = NULL;
body_fields = NULL;
body_fld_lines = 0;
cur_token = * index;
r = mailimap_media_text_parse(fd, buffer, &cur_token, &media_text,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_media_text;
}
r = mailimap_body_fields_parse(fd, buffer, &cur_token, &body_fields,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_media_text;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_body_fields;
}
r = mailimap_body_fld_lines_parse(fd, buffer, &cur_token, &body_fld_lines);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free_body_fields;
}
body_type_text = mailimap_body_type_text_new(media_text, body_fields,
body_fld_lines);
if (body_type_text == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_body_fields;
}
* result = body_type_text;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free_body_fields:
mailimap_body_fields_free(body_fields);
free_media_text:
mailimap_media_text_free(media_text);
err:
return res;
}
/*
capability = ("AUTH=" auth-type) / atom
; New capabilities MUST begin with "X" or be
; registered with IANA as standard or
; standards-track
*/
static int
mailimap_capability_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_capability ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int type;
char * auth_type;
char * atom;
struct mailimap_capability * cap;
int r;
int res;
cur_token = * index;
auth_type = NULL;
atom = NULL;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "AUTH=");
switch (r) {
case MAILIMAP_NO_ERROR:
type = MAILIMAP_CAPABILITY_AUTH_TYPE;
r = mailimap_auth_type_parse(fd, buffer, &cur_token, &auth_type,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
break;
case MAILIMAP_ERROR_PARSE:
r = mailimap_atom_parse(fd, buffer, &cur_token, &atom,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
type = MAILIMAP_CAPABILITY_NAME;
break;
default:
res = r;
goto err;
}
cap = mailimap_capability_new(type, auth_type, atom);
if (cap == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = cap;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (auth_type)
mailimap_auth_type_free(auth_type);
if (atom)
mailimap_atom_free(atom);
err:
return res;
}
/*
capability-data = "CAPABILITY" *(SP capability) SP "IMAP4rev1"
*(SP capability)
; IMAP4rev1 servers which offer RFC 1730
; compatibility MUST list "IMAP4" as the first
; capability.
*/
/*
SP capability *(SP capability)
*/
static int mailimap_capability_list_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
clist ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
clist * list;
int r;
cur_token = * index;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_struct_spaced_list_parse(fd, buffer, &cur_token, &list,
(mailimap_struct_parser *)
mailimap_capability_parse,
(mailimap_struct_destructor *)
mailimap_capability_free,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
* index = cur_token;
* result = list;
return MAILIMAP_NO_ERROR;
}
static int
mailimap_capability_data_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_capability_data ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
clist * cap_list;
#if 0
clist * cap_list_2;
#endif
struct mailimap_capability_data * cap_data;
int r;
int res;
cur_token = * index;
cap_list = NULL;
#if 0
cap_list_2 = NULL;
#endif
r = mailimap_token_case_insensitive_parse(fd, buffer,
&cur_token, "CAPABILITY");
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_capability_list_parse(fd, buffer, &cur_token,
&cap_list,
progr_rate, progr_fun);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) {
res = r;
goto err;
}
#if 0
if (!mailimap_space_parse(fd, buffer, &cur_token)) {
res = r;
goto free_list;
}
if (!mailimap_token_case_insensitive_parse(fd, buffer,
&cur_token, "IMAP4rev1"))
goto free_list;
r = mailimap_capability_list_parse(fd, buffer, &cur_token,
&cap_list_2,
progr_rate, progr_fun);
cap_list = g_list_concat(cap_list, cap_list_2);
#endif
cap_data = mailimap_capability_data_new(cap_list);
if (cap_data == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_list;
}
* result = cap_data;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free_list:
if (cap_list) {
clist_foreach(cap_list, (clist_func) mailimap_capability_free, NULL);
clist_free(cap_list);
}
err:
return res;
}
/*
UNIMPLEMENTED BECAUSE UNUSED (only in literal)
CHAR8 = %x01-ff
; any OCTET except NUL, %x00
*/
/*
static gboolean is_char8(gchar ch)
{
return (ch != 0x00);
}
*/
/*
UNIMPLEMENTED
command = tag SP (command-any / command-auth / command-nonauth /
command-select) CRLF
; Modal based on state
*/
/*
UNIMPLEMENTED
command-any = "CAPABILITY" / "LOGOUT" / "NOOP" / x-command
; Valid in all states
*/
/*
UNIMPLEMENTED
command-auth = append / create / delete / examine / list / lsub /
rename / select / status / subscribe / unsubscribe
; Valid only in Authenticated or Selected state
*/
/*
UNIMPLEMENTED
command-nonauth = login / authenticate
; Valid only when in Not Authenticated state
*/
/*
UNIMPLEMENTED
command-select = "CHECK" / "CLOSE" / "EXPUNGE" / copy / fetch / store /
uid / search
; Valid only when in Selected state
*/
/*
continue-req = "+" SP (resp-text / base64) CRLF
*/
int
mailimap_continue_req_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_continue_req ** result,
size_t progr_rate,
progress_function * progr_fun)
{
struct mailimap_resp_text * resp_text;
size_t cur_token;
struct mailimap_continue_req * cont_req;
char * base64;
int type;
int r;
int res;
cur_token = * index;
r = mailimap_plus_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
resp_text = NULL;
base64 = NULL;
type = MAILIMAP_CONTINUE_REQ_ERROR; /* XXX - removes a gcc warning */
r = mailimap_base64_parse(fd, buffer, &cur_token, &base64,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_CONTINUE_REQ_BASE64;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_resp_text_parse(fd, buffer, &cur_token, &resp_text,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_CONTINUE_REQ_TEXT;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_crlf_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free;
}
cont_req = mailimap_continue_req_new(type, resp_text, base64);
if (cont_req == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = cont_req;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (base64 != NULL)
mailimap_base64_free(base64);
if (resp_text != NULL)
mailimap_resp_text_free(resp_text);
err:
return res;
}
/*
UNIMPLEMENTED
copy = "COPY" SP set SP mailbox
*/
/*
UNIMPLEMENTED
create = "CREATE" SP mailbox
; Use of INBOX gives a NO error
*/
/*
UNIMPLEMENTED
date = date-text / DQUOTE date-text DQUOTE
*/
/*
UNIMPLEMENTED
date-day = 1*2DIGIT
; Day of month
*/
/*
static gboolean mailimap_date_day_parse(mailstream * fd,
MMAPString * buffer,
guint32 * index,
gint * result)
{
guint32 cur_token;
gint digit;
gint number;
cur_token = * index;
if (!mailimap_digit_parse(fd, buffer, &cur_token, &digit))
return FALSE;
number = digit;
if (mailimap_digit_parse(fd, buffer, &cur_token, &digit))
number = number * 10 + digit;
* result = number;
* index = cur_token;
return TRUE;
}
*/
/*
date-day-fixed = (SP DIGIT) / 2DIGIT
; Fixed-format version of date-day
*/
static int mailimap_date_day_fixed_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
int * result)
{
#ifdef UNSTRICT_SYNTAX
size_t cur_token;
uint32_t day;
int r;
cur_token = * index;
r = mailimap_number_parse(fd, buffer, &cur_token, &day);
if (r != MAILIMAP_NO_ERROR)
return r;
* index = cur_token;
* result = day;
return MAILIMAP_NO_ERROR;
#else
size_t cur_token;
int r;
cur_token = * index;
if (mailimap_space_parse(fd, buffer, &cur_token)) {
int digit;
r = mailimap_digit_parse(fd, buffer, &cur_token, &digit);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = digit;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
else {
int digit1;
int digit2;
r = mailimap_digit_parse(fd, buffer, &cur_token, &digit1);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_digit_parse(fd, buffer, &cur_token, &digit2);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = digit1 * 10 + digit2;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
#endif
}
/*
date-month = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" /
"Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec"
*/
static int mailimap_date_month_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result)
{
size_t cur_token;
int month;
cur_token = * index;
month = mailimap_month_get_token_value(fd, buffer, &cur_token);
if (month == -1)
return MAILIMAP_ERROR_PARSE;
* result = month;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
UNIMPLEMENTED
date-text = date-day "-" date-month "-" date-year
*/
/*
static struct mailimap_date_text *
mailimap_date_text_new(gint day, gint month, gint year)
{
struct mailimap_date_text * date_text;
date_text = g_new(struct mailimap_date_text, 1);
if (date_text == NULL)
return NULL;
date_text->day = day;
date_text->month = month;
date_text->year = year;
return date_text;
}
static void mailimap_date_text_free(struct mailimap_date_text * date_text)
{
g_free(date_text);
}
static gboolean
mailimap_date_text_parse(mailstream * fd, MMAPString * buffer,
guint32 * index, struct mailimap_date_text ** result)
{
struct mailimap_date_text * date_text;
gint day;
gint month;
gint year;
guint32 cur_token;
cur_token = * index;
if (!mailimap_date_day_parse(fd, buffer, &cur_token, &day))
return FALSE;
if (!mailimap_minus_parse(fd, buffer, &cur_token))
return FALSE;
if (!mailimap_date_month_parse(fd, buffer, &cur_token, &month))
return FALSE;
if (!mailimap_minus_parse(fd, buffer, &cur_token))
return FALSE;
if (!mailimap_date_year_parse(fd, buffer, &cur_token, &year))
return FALSE;
date_text = mailimap_date_text_new(day, month, year);
if (date_text == NULL)
return FALSE;
* result = date_text;
* index = cur_token;
return TRUE;
}
*/
/*
date-year = 4DIGIT
*/
static int mailimap_date_year_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result)
{
#ifdef UNSTRICT_SYNTAX
uint32_t year;
int r;
size_t cur_token;
cur_token = * index;
r = mailimap_number_parse(fd, buffer, &cur_token, &year);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = year;
* index = cur_token;
return MAILIMAP_NO_ERROR;
#else
int i;
size_t cur_token;
int year;
int digit;
int r;
cur_token = * index;
year = 0;
for(i = 0 ; i < 4 ; i ++) {
r = mailimap_digit_parse(fd, buffer, &cur_token, &digit);
if (r != MAILIMAP_NO_ERROR)
return r;
year = year * 10 + digit;
}
* result = year;
* index = cur_token;
return MAILIMAP_NO_ERROR;
#endif
}
/*
date-time = DQUOTE date-day-fixed "-" date-month "-" date-year
SP time SP zone DQUOTE
*/
static int mailimap_date_time_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_date_time ** result,
size_t progr_rate,
progress_function * progr_fun)
{
int day;
int month;
int year;
int hour;
int min;
int sec;
struct mailimap_date_time * date_time;
size_t cur_token;
int zone;
int r;
cur_token = * index;
r = mailimap_dquote_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_date_day_fixed_parse(fd, buffer, &cur_token, &day);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_minus_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_date_month_parse(fd, buffer, &cur_token, &month);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_minus_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_date_year_parse(fd, buffer, &cur_token, &year);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_time_parse(fd, buffer, &cur_token, &hour, &min, &sec);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_zone_parse(fd, buffer, &cur_token, &zone);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_dquote_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
date_time = mailimap_date_time_new(day, month, year, hour, min, sec, zone);
if (date_time == NULL)
return MAILIMAP_ERROR_MEMORY;
* result = date_time;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
UNIMPLEMENTED
delete = "DELETE" SP mailbox
; Use of INBOX gives a NO error
*/
/*
digit-nz = %x31-39
; 1-9
*/
#ifndef UNSTRICT_SYNTAX
static int is_digit_nz(char ch)
{
return (ch >= '1') && (ch <= '9');
}
static int mailimap_digit_nz_parse(mailstream * fd, MMAPString * buffer,
size_t * index, int * result)
{
size_t cur_token;
cur_token = * index;
if (is_digit_nz(buffer->str[cur_token])) {
* result = buffer->str[cur_token] - '0';
cur_token ++;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
else
return MAILIMAP_ERROR_PARSE;
}
#endif
/*
envelope = "(" env-date SP env-subject SP env-from SP env-sender SP
env-reply-to SP env-to SP env-cc SP env-bcc SP
env-in-reply-to SP env-message-id ")"
*/
static int mailimap_envelope_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_envelope ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
char * date;
char * subject;
struct mailimap_env_from * from;
struct mailimap_env_sender * sender;
struct mailimap_env_reply_to * reply_to;
struct mailimap_env_to * to;
struct mailimap_env_cc * cc;
struct mailimap_env_bcc * bcc;
char * in_reply_to;
char * message_id;
struct mailimap_envelope * envelope;
int r;
int res;
date = NULL;
subject = NULL;
from = NULL;
sender = NULL;
reply_to = NULL;
to = NULL;
cc = NULL;
bcc = NULL;
in_reply_to = NULL;
message_id = NULL;
cur_token = * index;
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_env_date_parse(fd, buffer, &cur_token, &date,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto date;
}
r = mailimap_env_subject_parse(fd, buffer, &cur_token, &subject,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto date;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto subject;
}
r = mailimap_env_from_parse(fd, buffer, &cur_token, &from,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto subject;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto from;
}
r = mailimap_env_sender_parse(fd, buffer, &cur_token, &sender,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto from;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto sender;
}
r = mailimap_env_reply_to_parse(fd, buffer, &cur_token, &reply_to,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto sender;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto reply_to;
}
r = mailimap_env_to_parse(fd, buffer, &cur_token, &to,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto reply_to;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto to;
}
r = mailimap_env_cc_parse(fd, buffer, &cur_token, &cc,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto to;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto cc;
}
r = mailimap_env_bcc_parse(fd, buffer, &cur_token, &bcc,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto cc;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto bcc;
}
r = mailimap_env_in_reply_to_parse(fd, buffer, &cur_token, &in_reply_to,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto bcc;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto in_reply_to;
}
r = mailimap_env_message_id_parse(fd, buffer, &cur_token, &message_id,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto in_reply_to;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto message_id;
}
envelope = mailimap_envelope_new(date, subject, from, sender, reply_to, to,
cc, bcc, in_reply_to, message_id);
if (envelope == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto message_id;
}
* result = envelope;
* index = cur_token;
return MAILIMAP_NO_ERROR;
message_id:
mailimap_env_message_id_free(message_id);
in_reply_to:
mailimap_env_in_reply_to_free(in_reply_to);
bcc:
mailimap_env_bcc_free(bcc);
cc:
mailimap_env_cc_free(cc);
to:
mailimap_env_to_free(to);
reply_to:
mailimap_env_reply_to_free(reply_to);
sender:
mailimap_env_sender_free(sender);
from:
mailimap_env_from_free(from);
subject:
mailimap_env_subject_free(date);
date:
mailimap_env_date_free(date);
err:
return res;
}
/*
"(" 1*address ")"
*/
static int mailimap_address_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
clist ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
clist * address_list;
int r;
int res;
cur_token = * index;
address_list = NULL;
r = mailimap_nil_parse(fd, buffer, &cur_token);
switch (r) {
case MAILIMAP_NO_ERROR:
address_list = NULL;
break;
case MAILIMAP_ERROR_PARSE:
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_struct_multiple_parse(fd, buffer, &cur_token, &address_list,
(mailimap_struct_parser *)
mailimap_address_parse,
(mailimap_struct_destructor *)
mailimap_address_free,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto address_list;
}
break;
default:
res = r;
goto err;
}
* result = address_list;
* index = cur_token;
return MAILIMAP_NO_ERROR;
address_list:
if (address_list) {
clist_foreach(address_list, (clist_func) mailimap_address_free, NULL);
clist_free(address_list);
}
err:
return res;
}
/*
env-bcc = "(" 1*address ")" / nil
*/
static int
mailimap_env_bcc_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_env_bcc ** result,
size_t progr_rate,
progress_function * progr_fun)
{
clist * list;
size_t cur_token;
struct mailimap_env_bcc * env_bcc;
int r;
int res;
cur_token = * index;
list = NULL;
r = mailimap_address_list_parse(fd, buffer, &cur_token, &list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
env_bcc = mailimap_env_bcc_new(list);
if (env_bcc == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = env_bcc;
return MAILIMAP_NO_ERROR;
free:
clist_foreach(list, (clist_func) mailimap_address_free, NULL);
clist_free(list);
err:
return res;
}
/*
env-cc = "(" 1*address ")" / nil
*/
static int
mailimap_env_cc_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_env_cc ** result,
size_t progr_rate,
progress_function * progr_fun)
{
clist * list;
size_t cur_token;
struct mailimap_env_cc * env_cc;
int r;
int res;
cur_token = * index;
list = NULL;
r = mailimap_address_list_parse(fd, buffer, &cur_token, &list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
env_cc = mailimap_env_cc_new(list);
if (env_cc == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = env_cc;
return MAILIMAP_NO_ERROR;
free:
clist_foreach(list, (clist_func) mailimap_address_free, NULL);
clist_free(list);
err:
return res;
}
/*
env-date = nstring
*/
static int mailimap_env_date_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
env-from = "(" 1*address ")" / nil
*/
static int
mailimap_env_from_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_env_from ** result,
size_t progr_rate,
progress_function * progr_fun)
{
clist * list;
size_t cur_token;
struct mailimap_env_from * env_from;
int r;
int res;
cur_token = * index;
list = NULL;
r = mailimap_address_list_parse(fd, buffer, &cur_token, &list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
env_from = mailimap_env_from_new(list);
if (env_from == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = env_from;
return MAILIMAP_NO_ERROR;
free:
clist_foreach(list, (clist_func) mailimap_address_free, NULL);
clist_free(list);
err:
return res;
}
/*
env-in-reply-to = nstring
*/
static int mailimap_env_in_reply_to_parse(mailstream * fd,
MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
env-message-id = nstring
*/
static int mailimap_env_message_id_parse(mailstream * fd,
MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
env-reply-to = "(" 1*address ")" / nil
*/
static int
mailimap_env_reply_to_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_env_reply_to ** result,
size_t progr_rate,
progress_function * progr_fun)
{
clist * list;
size_t cur_token;
struct mailimap_env_reply_to * env_reply_to;
int r;
int res;
cur_token = * index;
list = NULL;
r = mailimap_address_list_parse(fd, buffer, &cur_token, &list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
env_reply_to = mailimap_env_reply_to_new(list);
if (env_reply_to == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = env_reply_to;
return MAILIMAP_NO_ERROR;
free:
clist_foreach(list, (clist_func) mailimap_address_free, NULL);
clist_free(list);
err:
return res;
}
/*
env-sender = "(" 1*address ")" / nil
*/
static int
mailimap_env_sender_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct mailimap_env_sender ** result,
size_t progr_rate,
progress_function * progr_fun)
{
clist * list;
size_t cur_token;
struct mailimap_env_sender * env_sender;
int r;
int res;
cur_token = * index;
list = NULL;
r = mailimap_address_list_parse(fd, buffer, &cur_token, &list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
env_sender = mailimap_env_sender_new(list);
if (env_sender == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = env_sender;
return MAILIMAP_NO_ERROR;
free:
clist_foreach(list, (clist_func) mailimap_address_free, NULL);
clist_free(list);
err:
return res;
}
/*
env-subject = nstring
*/
static int mailimap_env_subject_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_nstring_parse(fd, buffer, index, result, NULL,
progr_rate, progr_fun);
}
/*
env-to = "(" 1*address ")" / nil
*/
static int mailimap_env_to_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_env_to ** result,
size_t progr_rate,
progress_function * progr_fun)
{
clist * list;
size_t cur_token;
struct mailimap_env_to * env_to;
int r;
int res;
cur_token = * index;
list = NULL;
r = mailimap_address_list_parse(fd, buffer, &cur_token, &list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
env_to = mailimap_env_to_new(list);
if (env_to == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = env_to;
return MAILIMAP_NO_ERROR;
free:
clist_foreach(list, (clist_func) mailimap_address_free, NULL);
clist_free(list);
err:
return res;
}
/*
UNIMPLEMENTED
examine = "EXAMINE" SP mailbox
*/
/*
UNIMPLEMENTED
fetch = "FETCH" SP set SP ("ALL" / "FULL" / "FAST" / fetch-att /
"(" fetch-att *(SP fetch-att) ")")
*/
/*
UNIMPLEMENTED
fetch-att = "ENVELOPE" / "FLAGS" / "INTERNALDATE" /
"RFC822" [".HEADER" / ".SIZE" / ".TEXT"] /
"BODY" ["STRUCTURE"] / "UID" /
"BODY" [".PEEK"] section ["<" number "." nz-number ">"]
*/
/*
flag = "\Answered" / "\Flagged" / "\Deleted" /
"\Seen" / "\Draft" / flag-keyword / flag-extension
; Does not include "\Recent"
*/
static int mailimap_flag_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag ** result,
size_t progr_rate,
progress_function * progr_fun)
{
struct mailimap_flag * flag;
size_t cur_token;
char * flag_keyword;
char * flag_extension;
int type;
int r;
int res;
cur_token = * index;
flag_keyword = NULL;
flag_extension = NULL;
type = mailimap_flag_get_token_value(fd, buffer, &cur_token);
if (type == -1) {
r = mailimap_flag_keyword_parse(fd, buffer, &cur_token, &flag_keyword,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_FLAG_KEYWORD;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_flag_extension_parse(fd, buffer, &cur_token,
&flag_extension,
progr_rate, progr_fun);
type = MAILIMAP_FLAG_EXTENSION;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
}
flag = mailimap_flag_new(type, flag_keyword, flag_extension);
if (flag == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = flag;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (flag_keyword != NULL)
mailimap_flag_keyword_free(flag_keyword);
if (flag_extension != NULL)
mailimap_flag_extension_free(flag_extension);
err:
return res;
}
/*
flag-extension = "\" atom
; Future expansion. Client implementations
; MUST accept flag-extension flags. Server
; implementations MUST NOT generate
; flag-extension flags except as defined by
; future standard or standards-track
; revisions of this specification.
*/
static int mailimap_flag_extension_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
char * atom;
int r;
cur_token = * index;
r = mailimap_char_parse(fd, buffer, &cur_token, '\\');
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_atom_parse(fd, buffer, &cur_token, &atom,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = atom;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
flag-fetch = flag / "\Recent"
*/
static int
mailimap_flag_fetch_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag_fetch ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_flag * flag;
struct mailimap_flag_fetch * flag_fetch;
int type;
int r;
int res;
cur_token = * index;
flag = NULL;
type = MAILIMAP_FLAG_FETCH_ERROR; /* XXX - removes a gcc warning */
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token,
"\\Recent");
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_FLAG_FETCH_RECENT;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_flag_parse(fd, buffer, &cur_token, &flag,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_FLAG_FETCH_OTHER;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
flag_fetch = mailimap_flag_fetch_new(type, flag);
if (flag_fetch == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* index = cur_token;
* result = flag_fetch;
return MAILIMAP_NO_ERROR;
free:
if (flag != NULL)
mailimap_flag_free(flag);
err:
return res;
}
/*
flag-keyword = atom
*/
static int mailimap_flag_keyword_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_atom_parse(fd, buffer, index, result,
progr_rate, progr_fun);
}
/*
flag-list = "(" [flag *(SP flag)] ")"
*/
static int mailimap_flag_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag_list ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
clist * list;
struct mailimap_flag_list * flag_list;
int r;
int res;
list = NULL;
cur_token = * index;
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_struct_spaced_list_parse(fd, buffer, &cur_token, &list,
(mailimap_struct_parser *)
mailimap_flag_parse,
(mailimap_struct_destructor *)
mailimap_flag_free,
progr_rate, progr_fun);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) {
res = r;
goto err;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free;
}
flag_list = mailimap_flag_list_new(list);
if (flag_list == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = flag_list;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (list != NULL) {
clist_foreach(list, (clist_func) mailimap_flag_free, NULL);
clist_free(list);
}
err:
return res;
}
/*
flag-perm = flag / "\*"
*/
static int
mailimap_flag_perm_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag_perm ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_flag_perm * flag_perm;
struct mailimap_flag * flag;
int type;
int r;
int res;
flag = NULL;
cur_token = * index;
type = MAILIMAP_FLAG_PERM_ERROR; /* XXX - removes a gcc warning */
r = mailimap_flag_parse(fd, buffer, &cur_token, &flag,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_FLAG_PERM_FLAG;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_token_case_insensitive_parse(fd, buffer,
&cur_token, "\\*");
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_FLAG_PERM_ALL;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
flag_perm = mailimap_flag_perm_new(type, flag);
if (flag_perm == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = flag_perm;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (flag != NULL)
mailimap_flag_free(flag);
err:
return res;
}
/*
greeting = "*" SP (resp-cond-auth / resp-cond-bye) CRLF
*/
int mailimap_greeting_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_greeting ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_resp_cond_auth * resp_cond_auth;
struct mailimap_resp_cond_bye * resp_cond_bye;
struct mailimap_greeting * greeting;
int type;
int r;
int res;
cur_token = * index;
resp_cond_bye = NULL;
resp_cond_auth = NULL;
r = mailimap_star_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
type = MAILIMAP_GREETING_RESP_COND_ERROR; /* XXX - removes a gcc warning */
r = mailimap_resp_cond_auth_parse(fd, buffer, &cur_token, &resp_cond_auth,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_GREETING_RESP_COND_AUTH;
if (r == MAILIMAP_ERROR_PARSE) {
r = mailimap_resp_cond_bye_parse(fd, buffer, &cur_token,
&resp_cond_bye,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
type = MAILIMAP_GREETING_RESP_COND_BYE;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_crlf_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free;
}
greeting = mailimap_greeting_new(type, resp_cond_auth, resp_cond_bye);
if (greeting == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = greeting;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
if (resp_cond_auth)
mailimap_resp_cond_auth_free(resp_cond_auth);
if (resp_cond_bye)
mailimap_resp_cond_bye_free(resp_cond_bye);
err:
return res;
}
/*
header-fld-name = astring
*/
static int
mailimap_header_fld_name_parse(mailstream * fd,
MMAPString * buffer,
size_t * index,
char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
return mailimap_astring_parse(fd, buffer, index, result,
progr_rate, progr_fun);
}
/*
header-list = "(" header-fld-name *(SP header-fld-name) ")"
*/
static int
mailimap_header_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_header_list ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_header_list * header_list;
clist * list;
int r;
int res;
cur_token = * index;
list = NULL;
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_struct_spaced_list_parse(fd, buffer, &cur_token, &list,
(mailimap_struct_parser *)
mailimap_header_fld_name_parse,
(mailimap_struct_destructor *)
mailimap_header_fld_name_free,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_cparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto free;
}
header_list = mailimap_header_list_new(list);
if (header_list == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
}
* result = header_list;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free:
clist_foreach(list, (clist_func) mailimap_header_fld_name_free, NULL);
clist_free(list);
err:
return res;
}
/*
UNIMPLEMENTED
list = "LIST" SP mailbox SP list-mailbox
UNIMPLEMENTED
list-mailbox = 1*list-char / string
UNIMPLEMENTED
list-char = ATOM-CHAR / list-wildcards / resp-specials
*/
/*
list-wildcards = "%" / "*"
*/
static int is_list_wildcards(char ch)
{
switch (ch) {
case '%':
case '*':
return TRUE;
}
return FALSE;
}
/*
literal = "{" number "}" CRLF *CHAR8
; Number represents the number of CHAR8s
*/
static int mailimap_literal_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t * result_len,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
uint32_t number;
MMAPString * literal;
char * literal_p;
uint32_t left;
int r;
int res;
size_t number_token;
cur_token = * index;
r = mailimap_oaccolade_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
number_token = cur_token;
r = mailimap_number_parse(fd, buffer, &cur_token, &number);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_caccolade_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_crlf_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
literal = mmap_string_sized_new(number);
/*
literal = g_new(char, number + 1);
*/
if (literal == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto err;
}
left = buffer->len - cur_token;
if (left >= number) {
/*
if (number > 0)
strncpy(literal, buffer->str + cur_token, number);
literal[number] = 0;
*/
if (number > 0)
if (mmap_string_append_len(literal, buffer->str + cur_token,
number) == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_literal;
}
if ((progr_fun != NULL) && (progr_rate != 0))
progr_fun(number, number);
cur_token = cur_token + number;
}
else {
uint32_t needed;
uint32_t current_prog = 0;
uint32_t last_prog = 0;
needed = number - left;
memcpy(literal->str, buffer->str + cur_token, left);
literal->len += left;
literal_p = literal->str + left;
current_prog = left;
while (needed > 0) {
ssize_t read_bytes;
read_bytes = mailstream_read(fd, literal_p, needed);
if (read_bytes == -1) {
res = MAILIMAP_ERROR_STREAM;
goto free_literal;
}
literal->len += read_bytes;
needed -= read_bytes;
literal_p += read_bytes;
current_prog += read_bytes;
if ((progr_fun != NULL) && (progr_rate != 0))
if (current_prog - last_prog > progr_rate) {
progr_fun(current_prog, number);
last_prog = current_prog;
}
}
literal->str[number] = 0;
#if 0
literal->str[number] = 0;
if (mmap_string_append_len(buffer, literal->str + left,
literal->len - left) == NULL) {
res = MAILIMAP_ERROR_STREAM;
goto free_literal;
}
#endif
if (mmap_string_truncate(buffer, number_token) == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_literal;
}
if (mmap_string_append(buffer, "0}\r\n") == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_literal;
}
cur_token = number_token + 4;
}
if ((progr_fun != NULL) && (progr_rate != 0))
progr_fun(number, number);
if (mailstream_read_line_append(fd, buffer) == NULL) {
res = MAILIMAP_ERROR_STREAM;
goto free_literal;
}
if (mmap_string_ref(literal) < 0) {
res = MAILIMAP_ERROR_MEMORY;
goto free_literal;
}
* result = literal->str;
if (result_len != NULL)
* result_len = literal->len;
* index = cur_token;
return MAILIMAP_NO_ERROR;
free_literal:
mmap_string_free(literal);
err:
return res;
}
/*
UNIMPLEMENTED
login = "LOGIN" SP userid SP password
UNIMPLEMENTED
lsub = "LSUB" SP mailbox SP list-mailbox
*/
/*
mailbox = "INBOX" / astring
; INBOX is case-insensitive. All case variants of
; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX
; not as an astring. An astring which consists of
; the case-insensitive sequence "I" "N" "B" "O" "X"
; is considered to be INBOX and not an astring.
; Refer to section 5.1 for further
; semantic details of mailbox names.
*/
static int
mailimap_mailbox_parse(mailstream * fd, MMAPString * buffer,
size_t * index, char ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
char * name;
int r;
cur_token = * index;
r = mailimap_astring_parse(fd, buffer, &cur_token, &name,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = name;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
mailbox-data = "FLAGS" SP flag-list / "LIST" SP mailbox-list /
"LSUB" SP mailbox-list / "SEARCH" *(SP nz-number) /
"STATUS" SP mailbox SP "("
[status-att SP number *(SP status-att SP number)] ")" /
number SP "EXISTS" / number SP "RECENT"
*/
/*
"FLAGS" SP flag-list
*/
static int
mailimap_mailbox_data_flags_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_flag_list ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_flag_list * flag_list;
int r;
cur_token = * index;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "FLAGS");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_flag_list_parse(fd, buffer, &cur_token, &flag_list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = flag_list;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
"LIST" SP mailbox-list
*/
static int
mailimap_mailbox_data_list_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_mailbox_list ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_mailbox_list * mb_list;
int r;
int res;
cur_token = * index;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "LIST");
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
}
r = mailimap_mailbox_list_parse(fd, buffer, &cur_token, &mb_list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
}
* result = mb_list;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
"LSUB" SP mailbox-list
*/
static int
mailimap_mailbox_data_lsub_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_mailbox_list ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
struct mailimap_mailbox_list * mb_list;
int r;
cur_token = * index;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "LSUB");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_mailbox_list_parse(fd, buffer, &cur_token, &mb_list,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR)
return r;
* result = mb_list;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
"SEARCH" *(SP nz-number)
*/
static int
mailimap_mailbox_data_search_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
clist ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
size_t final_token;
clist * number_list;
int r;
cur_token = * index;
r = mailimap_token_case_insensitive_parse(fd, buffer,
&cur_token, "SEARCH");
if (r != MAILIMAP_NO_ERROR)
return r;
final_token = cur_token;
number_list = NULL;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r == MAILIMAP_NO_ERROR) {
r = mailimap_struct_spaced_list_parse(fd, buffer, &cur_token, &number_list,
(mailimap_struct_parser *)
mailimap_nz_number_alloc_parse,
(mailimap_struct_destructor *)
mailimap_number_alloc_free,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
final_token = cur_token;
}
* result = number_list;
* index = final_token;
return MAILIMAP_NO_ERROR;
}
/*
"STATUS" SP mailbox SP "("
[status-att SP number *(SP status-att SP number)] ")"
*/
/*
status-att SP number
*/
static int
mailimap_status_info_parse(mailstream * fd, MMAPString * buffer,
size_t * index,
struct mailimap_status_info **
result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int status_att;
uint32_t value;
struct mailimap_status_info * info;
int r;
cur_token = * index;
value = 0;
r = mailimap_status_att_parse(fd, buffer, &cur_token, &status_att);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_number_parse(fd, buffer, &cur_token, &value);
if (r != MAILIMAP_NO_ERROR)
return r;
info = mailimap_status_info_new(status_att, value);
if (info == NULL)
return MAILIMAP_ERROR_MEMORY;
* result = info;
* index = cur_token;
return MAILIMAP_NO_ERROR;
}
/*
"STATUS" SP mailbox SP "("
[status-att SP number *(SP status-att SP number)] ")"
*/
static int
mailimap_mailbox_data_status_parse(mailstream * fd, MMAPString * buffer,
size_t * index, struct
mailimap_mailbox_data_status ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
char * mb;
clist * status_info_list;
struct mailimap_mailbox_data_status * data_status;
int r;
int res;
cur_token = * index;
mb = NULL;
status_info_list = NULL;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "STATUS");
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_mailbox_parse(fd, buffer, &cur_token, &mb,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto mailbox;
}
r = mailimap_oparenth_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto mailbox;
}
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index d9496af..93fb7de 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,1360 +1,1365 @@
// CHANGED 2004-09-31 Lutz Rogowski
#include <stdlib.h>
#include <libetpan/libetpan.h>
#include <qpe/global.h>
#include <qapplication.h>
#include "imapwrapper.h"
#include "mailtypes.h"
#include "logindialog.h"
#include <qprogressbar.h>
#include "genericwrapper.h"
#include <kglobal.h>
using namespace Opie::Core;
int IMAPwrapper::mMax = 0;
int IMAPwrapper::mCurrent = 0;
IMAPwrapper::IMAPwrapper( IMAPaccount *a )
: AbstractMail()
{
account = a;
m_imap = 0;
m_Lastmbox = "";
mCurrent = 0;
mMax = 0;
}
IMAPwrapper::~IMAPwrapper()
{
logout();
}
/* to avoid to often select statements in loops etc.
we trust that we are logged in and connection is established!*/
int IMAPwrapper::selectMbox(const QString&mbox)
{
if (mbox == m_Lastmbox) {
return MAILIMAP_NO_ERROR;
}
int err = mailimap_select( m_imap, (char*)mbox.latin1());
if ( err != MAILIMAP_NO_ERROR ) {
m_Lastmbox = "";
return err;
}
m_Lastmbox = mbox;
return err;
}
void IMAPwrapper::imap_progress( size_t current, size_t maximum )
{
qApp->processEvents();
return;
//qDebug("imap progress %d of %d ",current,maximum );
//Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum));
//qApp->processEvents()
static unsigned int last = 0;
if ( last != current )
IMAPwrapper::progress();
last = current;
}
void IMAPwrapper::progress( QString m )
{
static QString mProgrMess;
if ( m != QString::null ) {
mProgrMess = m;
mCurrent = 1;
return;
}
QString mess;
//qDebug("progress ");
if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax);
else mess = mProgrMess +i18n(" message %1").arg( mCurrent++);
Global::statusMessage(mess);
//qDebug("Progress %s %s", mess.latin1(), m.latin1());
qApp->processEvents();
}
bool IMAPwrapper::start_tls(bool force_tls)
{
int err;
bool try_tls = force_tls;
mailimap_capability_data * cap_data = 0;
err = mailimap_capability(m_imap,&cap_data);
if (err != MAILIMAP_NO_ERROR) {
Global::statusMessage("error getting capabilities!");
return false;
}
clistiter * cur;
for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
struct mailimap_capability * cap;
cap = (struct mailimap_capability *)clist_content(cur);
if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
try_tls = true;
break;
}
}
}
if (cap_data) {
mailimap_capability_data_free(cap_data);
}
if (try_tls) {
err = mailimap_starttls(m_imap);
if (err != MAILIMAP_NO_ERROR && force_tls) {
Global::statusMessage(i18n("Server has no TLS support!"));
try_tls = false;
} else {
mailstream_low * low;
mailstream_low * new_low;
low = mailstream_get_low(m_imap->imap_stream);
if (!low) {
try_tls = false;
} else {
int fd = mailstream_low_get_fd(low);
if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
mailstream_low_free(low);
mailstream_set_low(m_imap->imap_stream, new_low);
} else {
try_tls = false;
}
}
}
}
return try_tls;
}
void IMAPwrapper::login()
{
QString server, user, pass;
uint16_t port;
int err = MAILIMAP_NO_ERROR;
if (account->getOffline()) return;
/* we are connected this moment */
/* TODO: setup a timer holding the line or if connection closed - delete the value */
if (m_imap) {
err = mailimap_noop(m_imap);
if (err!=MAILIMAP_NO_ERROR) {
logout();
} else {
mailstream_flush(m_imap->imap_stream);
return;
}
}
server = account->getServer();
port = account->getPort().toUInt();
if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
login.show();
if ( QDialog::Accepted == login.exec() ) {
// ok
user = login.getUser();
pass = login.getPassword();
} else {
// cancel
return;
}
} else {
user = account->getUser();
pass = account->getPassword();
}
m_imap = mailimap_new( 20, &imap_progress );
/* connect */
bool ssl = false;
bool try_tls = false;
bool force_tls = false;
if ( account->ConnectionType() == 2 ) {
ssl = true;
}
if (account->ConnectionType()==1) {
force_tls = true;
}
if ( ssl ) {
qDebug("using ssl ");
err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
qDebug("back ");
} else {
err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
}
if ( err != MAILIMAP_NO_ERROR &&
err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
QString failure = "";
if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
failure="Connection refused";
} else {
failure="Unknown failure";
}
Global::statusMessage(i18n("error connecting imap server: %1").arg(failure));
mailimap_free( m_imap );
m_imap = 0;
return;
}
if (!ssl) {
try_tls = start_tls(force_tls);
}
bool ok = true;
if (force_tls && !try_tls) {
Global::statusMessage(i18n("Server has no TLS support!"));
ok = false;
}
/* login */
if (ok) {
err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
if ( err != MAILIMAP_NO_ERROR ) {
Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response));
ok = false;
}
}
if (!ok) {
err = mailimap_close( m_imap );
mailimap_free( m_imap );
m_imap = 0;
}
}
void IMAPwrapper::logout()
{
int err = MAILIMAP_NO_ERROR;
if (!m_imap) return;
err = mailimap_logout( m_imap );
err = mailimap_close( m_imap );
mailimap_free( m_imap );
m_imap = 0;
m_Lastmbox = "";
}
void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
{
int tryAgain = 1;
while ( tryAgain >= 0 ) {
int err = MAILIMAP_NO_ERROR;
clist *result = 0;
clistcell *current;
mailimap_fetch_type *fetchType = 0;
mailimap_set *set = 0;
login();
if (!m_imap) {
return;
}
/* select mailbox READONLY for operations */
err = selectMbox(mailbox);
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
int last = m_imap->imap_selection_info->sel_exists;
if (last == 0) {
Global::statusMessage(i18n("Mailbox has no mails"));
return;
} else {
}
progress( i18n("Fetch "));
mMax = last;
//qDebug("last %d ", last);
Global::statusMessage(i18n("Fetching header list"));
qApp->processEvents();
/* the range has to start at 1!!! not with 0!!!! */
//LR the access to web.de imap server is no working with value 1
//qDebug("interval %d - %d ", tryAgain, last-1+tryAgain );
set = mailimap_set_new_interval( tryAgain, last );
fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
err = mailimap_fetch( m_imap, set, fetchType, &result );
mailimap_set_free( set );
mailimap_fetch_type_free( fetchType );
QString date,subject,from;
if ( err == MAILIMAP_NO_ERROR ) {
tryAgain = -1;
mailimap_msg_att * msg_att;
int i = 0;
for (current = clist_begin(result); current != 0; current=clist_next(current)) {
++i;
//qDebug("iii %d ",i);
msg_att = (mailimap_msg_att*)current->data;
RecMail*m = parse_list_result(msg_att);
if (m) {
if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) {
m->setNumber(i);
m->setMbox(mailbox);
m->setWrapper(this);
target.append(m);
}
}
}
Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count()));
} else {
--tryAgain;
--tryAgain;//disabled tryagain by adding this line
if ( tryAgain < 0 )
Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response));
else
qDebug("try again... ");
}
if (result) mailimap_fetch_list_free(result);
}
}
QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
{
const char *path, *mask;
int err = MAILIMAP_NO_ERROR;
clist *result = 0;
clistcell *current = 0;
clistcell*cur_flag = 0;
mailimap_mbx_list_flags*bflags = 0;
QValueList<FolderP>* folders = new QValueList<FolderP>();
login();
if (!m_imap) {
return folders;
}
/*
* First we have to check for INBOX 'cause it sometimes it's not inside the path.
* We must not forget to filter them out in next loop!
* it seems like ugly code. and yes - it is ugly code. but the best way.
*/
Global::statusMessage(i18n("Fetching folder list"));
qApp->processEvents();
QString temp;
mask = "INBOX" ;
mailimap_mailbox_list *list;
err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
QString del;
bool selectable = true;
bool no_inferiors = false;
if ( err == MAILIMAP_NO_ERROR ) {
current = result->first;
for ( int i = result->count; i > 0; i-- ) {
list = (mailimap_mailbox_list *) current->data;
// it is better use the deep copy mechanism of qt itself
// instead of using strdup!
temp = list->mb_name;
del = list->mb_delimiter;
current = current->next;
if ( (bflags = list->mb_flag) ) {
selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
no_inferiors = true;
}
}
}
folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
}
} else {
qDebug("error fetching folders: ");
}
mailimap_list_result_free( result );
/*
* second stage - get the other then inbox folders
*/
mask = "*" ;
path = account->getPrefix().latin1();
if (!path) path = "";
err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
if ( err == MAILIMAP_NO_ERROR ) {
current = result->first;
for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
no_inferiors = false;
list = (mailimap_mailbox_list *) current->data;
// it is better use the deep copy mechanism of qt itself
// instead of using strdup!
temp = list->mb_name;
if (temp.lower()=="inbox")
continue;
if (temp.lower()==account->getPrefix().lower())
continue;
if ( (bflags = list->mb_flag) ) {
selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
no_inferiors = true;
}
}
}
del = list->mb_delimiter;
folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
}
} else {
qDebug("error fetching folders ");
}
if (result) mailimap_list_result_free( result );
return folders;
}
RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
{
RecMail * m = 0;
mailimap_msg_att_item *item=0;
clistcell *current,*c,*cf;
mailimap_msg_att_dynamic*flist;
mailimap_flag_fetch*cflag;
int size = 0;
QBitArray mFlags(7);
QStringList addresslist;
if (!m_att) {
return m;
}
m = new RecMail();
for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
current = c;
size = 0;
item = (mailimap_msg_att_item*)current->data;
if ( !item )
continue;
if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
if (!flist || !flist->att_list) {
continue;
}
cf = flist->att_list->first;
- if( ! cf )
+ if( cf ) {
for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
cflag = (mailimap_flag_fetch*)cf->data;
if( ! cflag )
- qDebug("imap:not cflag ");
+ qDebug("imap:NO cflag ");
+ else {
if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
switch (cflag->fl_flag->fl_type) {
case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
mFlags.setBit(FLAG_ANSWERED);
break;
case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
mFlags.setBit(FLAG_FLAGGED);
break;
case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
mFlags.setBit(FLAG_DELETED);
break;
case MAILIMAP_FLAG_SEEN: /* \Seen flag */
mFlags.setBit(FLAG_SEEN);
break;
case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
mFlags.setBit(FLAG_DRAFT);
break;
case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
break;
case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
break;
default:
break;
}
} else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
mFlags.setBit(FLAG_RECENT);
}
}
+ }
+ }
+ //qDebug(" continue");
continue;
}
if ( item->att_data.att_static == NULL )
continue;
if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
if ( head == NULL )
continue;
if ( head->env_date != NULL ) {
m->setDate(head->env_date);
//struct mailimf_date_time result;
struct mailimf_date_time* date;// = &result;
struct mailimf_date_time **re = &date;
size_t length = m->getDate().length();
size_t index = 0;
if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) {
+ //qDebug("parseDateTime ");
QDateTime dt = Genericwrapper::parseDateTime( date );
QString ret;
if ( dt.date() == QDate::currentDate () )
ret = KGlobal::locale()->formatTime( dt.time(),true);
else {
ret = KGlobal::locale()->formatDateTime( dt,true,true);
}
m->setDate( ret );
char tmp[20];
snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() );
//qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date);
m->setIsoDate( QString( tmp ) );
mailimf_date_time_free ( date );
} else {
m->setIsoDate(head->env_date);
}
}
if ( head->env_subject != NULL )
m->setSubject(convert_String((const char*)head->env_subject));
//m->setSubject(head->env_subject);
if (head->env_from!=NULL) {
addresslist = address_list_to_stringlist(head->env_from->frm_list);
if (addresslist.count()) {
m->setFrom(addresslist.first());
}
}
if (head->env_to!=NULL) {
addresslist = address_list_to_stringlist(head->env_to->to_list);
m->setTo(addresslist);
}
if (head->env_cc!=NULL) {
addresslist = address_list_to_stringlist(head->env_cc->cc_list);
m->setCC(addresslist);
}
if (head->env_bcc!=NULL) {
addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
m->setBcc(addresslist);
}
/* reply to address, eg. email. */
if (head->env_reply_to!=NULL) {
addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
if (addresslist.count()) {
m->setReplyto(addresslist.first());
}
}
if (head->env_in_reply_to!=NULL) {
QString h(head->env_in_reply_to);
while (h.length()>0 && h[0]=='<') {
h.remove(0,1);
}
while (h.length()>0 && h[h.length()-1]=='>') {
h.remove(h.length()-1,1);
}
if (h.length()>0) {
m->setInreply(QStringList(h));
}
}
if (head->env_message_id != NULL) {
m->setMsgid(QString(head->env_message_id));
}
} else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
#if 0
mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
qDebug("time %s ",da.toString().latin1() );
#endif
} else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
size = item->att_data.att_static->att_data.att_rfc822_size;
}
}
/* msg is already deleted */
if (mFlags.testBit(FLAG_DELETED) && m) {
delete m;
m = 0;
}
if (m) {
m->setFlags(mFlags);
m->setMsgsize(size);
}
return m;
}
RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
{
RecBodyP body = new RecBody();
const char *mb;
int err = MAILIMAP_NO_ERROR;
clist *result = 0;
clistcell *current;
mailimap_fetch_att *fetchAtt = 0;
mailimap_fetch_type *fetchType = 0;
mailimap_set *set = 0;
mailimap_body*body_desc = 0;
mb = mail->getMbox().latin1();
login();
if (!m_imap) {
return body;
}
err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return body;
}
/* the range has to start at 1!!! not with 0!!!! */
set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
fetchAtt = mailimap_fetch_att_new_bodystructure();
fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
err = mailimap_fetch( m_imap, set, fetchType, &result );
mailimap_set_free( set );
mailimap_fetch_type_free( fetchType );
if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
mailimap_msg_att * msg_att;
msg_att = (mailimap_msg_att*)current->data;
mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
QValueList<int> path;
body_desc = item->att_data.att_static->att_data.att_body;
traverseBody(mail,body_desc,body,0,path);
} else {
- //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
+ qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response );
}
if (result) mailimap_fetch_list_free(result);
return body;
}
QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
{
QStringList l;
QString from;
bool named_from;
clistcell *current = NULL;
mailimap_address * current_address=NULL;
if (!list) {
return l;
}
unsigned int count = 0;
for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
from = "";
named_from = false;
current_address=(mailimap_address*)current->data;
if (current_address->ad_personal_name){
from+=convert_String((const char*)current_address->ad_personal_name);
from+=" ";
named_from = true;
}
if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
from+="<";
}
if (current_address->ad_mailbox_name) {
from+=QString(current_address->ad_mailbox_name);
from+="@";
}
if (current_address->ad_host_name) {
from+=QString(current_address->ad_host_name);
}
if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
from+=">";
}
l.append(QString(from));
if (++count > 99) {
break;
}
}
return l;
}
encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
{
encodedString*res=new encodedString;
int err;
mailimap_fetch_type *fetchType;
mailimap_set *set;
clistcell*current,*cur;
mailimap_section_part * section_part = 0;
mailimap_section_spec * section_spec = 0;
mailimap_section * section = 0;
mailimap_fetch_att * fetch_att = 0;
login();
if (!m_imap) {
return res;
}
if (!internal_call) {
err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return res;
}
}
set = mailimap_set_new_single(mail->getNumber());
clist*id_list = 0;
/* if path == empty then its a request for the whole rfc822 mail and generates
a "fetch <id> (body[])" statement on imap server */
if (path.count()>0 ) {
id_list = clist_new();
for (unsigned j=0; j < path.count();++j) {
uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
*p_id = path[j];
clist_append(id_list,p_id);
}
section_part = mailimap_section_part_new(id_list);
section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
}
section = mailimap_section_new(section_spec);
fetch_att = mailimap_fetch_att_new_body_section(section);
fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
clist*result = 0;
err = mailimap_fetch( m_imap, set, fetchType, &result );
mailimap_set_free( set );
mailimap_fetch_type_free( fetchType );
if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
mailimap_msg_att * msg_att;
msg_att = (mailimap_msg_att*)current->data;
mailimap_msg_att_item*msg_att_item;
for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
/* detach - we take over the content */
msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
}
}
}
} else {
;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
}
if (result) mailimap_fetch_list_free(result);
return res;
}
/* current_recursion is for recursive calls.
current_count means the position inside the internal loop! */
void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
int current_recursion,QValueList<int>recList,int current_count)
{
if (!body || current_recursion>=10) {
return;
}
switch (body->bd_type) {
case MAILIMAP_BODY_1PART:
{
QValueList<int>countlist = recList;
countlist.append(current_count);
RecPartP currentPart = new RecPart();
mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
QString id("");
currentPart->setPositionlist(countlist);
for (unsigned int j = 0; j < countlist.count();++j) {
id+=(j>0?" ":"");
id+=QString("%1").arg(countlist[j]);
}
//odebug << "ID = " << id.latin1() << "" << oendl;
currentPart->setIdentifier(id);
fillSinglePart(currentPart,part1);
/* important: Check for is NULL 'cause a body can be empty!
And we put it only into the mail if it is the FIRST part */
if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
size_t index = 0;
char*res = 0;
int err = MAILIMF_NO_ERROR;
QString charset = currentPart->searchParamter( "charset");
qDebug("CHARSET %s ",charset.latin1() );
if ( false ) {
//if ( !charset.isEmpty() ) {
target_body->setCharset( charset );
//err = mailmime_encoded_phrase_parse("iso-8859-1",
// text, strlen(text),&index, "iso-8859-1",&res);
err = mailmime_encoded_phrase_parse(charset.latin1(),
body_text.latin1(), body_text.length(),&index, "utf-8",&res);
if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
//qDebug("res %d %s ", index, res);
body_text = QString::fromUtf8(res);
}
if (res) free(res);
}
//qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() );
target_body->setDescription(currentPart);
target_body->setBodytext(body_text);
if (countlist.count()>1) {
target_body->addPart(currentPart);
}
} else {
target_body->addPart(currentPart);
}
if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
}
}
break;
case MAILIMAP_BODY_MPART:
{
QValueList<int>countlist = recList;
clistcell*current=0;
mailimap_body*current_body=0;
unsigned int ccount = 1;
mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
current_body = (mailimap_body*)current->data;
if (current_body->bd_type==MAILIMAP_BODY_MPART) {
RecPartP targetPart = new RecPart();
targetPart->setType("multipart");
fillMultiPart(targetPart,mailDescription);
countlist.append(current_count);
targetPart->setPositionlist(countlist);
target_body->addPart(targetPart);
QString id("");
for (unsigned int j = 0; j < countlist.count();++j) {
id+=(j>0?" ":"");
id+=QString("%1").arg(countlist[j]);
}
// odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
}
traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
if (current_body->bd_type==MAILIMAP_BODY_MPART) {
countlist = recList;
}
++ccount;
}
}
break;
default:
break;
}
}
void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
{
if (!Description) {
return;
}
switch (Description->bd_type) {
case MAILIMAP_BODY_TYPE_1PART_TEXT:
target_part->setType("text");
fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
break;
case MAILIMAP_BODY_TYPE_1PART_BASIC:
fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
break;
case MAILIMAP_BODY_TYPE_1PART_MSG:
target_part->setType("message");
fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
break;
default:
break;
}
}
void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
{
if (!which) {
return;
}
QString sub;
sub = which->bd_media_text;
//odebug << "Type= text/" << which->bd_media_text << "" << oendl;
target_part->setSubtype(sub.lower());
target_part->setLines(which->bd_lines);
fillBodyFields(target_part,which->bd_fields);
}
void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
{
if (!which) {
return;
}
target_part->setSubtype("rfc822");
//odebug << "Message part" << oendl;
/* we set this type to text/plain */
target_part->setLines(which->bd_lines);
fillBodyFields(target_part,which->bd_fields);
}
void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
{
if (!which) return;
QString sub = which->bd_media_subtype;
target_part->setSubtype(sub.lower());
if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
clistcell*cur = 0;
mailimap_single_body_fld_param*param=0;
for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
param = (mailimap_single_body_fld_param*)cur->data;
if (param) {
target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
}
}
}
}
void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
{
if (!which) {
return;
}
QString type,sub;
switch (which->bd_media_basic->med_type) {
case MAILIMAP_MEDIA_BASIC_APPLICATION:
type = "application";
break;
case MAILIMAP_MEDIA_BASIC_AUDIO:
type = "audio";
break;
case MAILIMAP_MEDIA_BASIC_IMAGE:
type = "image";
break;
case MAILIMAP_MEDIA_BASIC_MESSAGE:
type = "message";
break;
case MAILIMAP_MEDIA_BASIC_VIDEO:
type = "video";
break;
case MAILIMAP_MEDIA_BASIC_OTHER:
default:
if (which->bd_media_basic->med_basic_type) {
type = which->bd_media_basic->med_basic_type;
} else {
type = "";
}
break;
}
if (which->bd_media_basic->med_subtype) {
sub = which->bd_media_basic->med_subtype;
} else {
sub = "";
}
// odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
target_part->setType(type.lower());
target_part->setSubtype(sub.lower());
fillBodyFields(target_part,which->bd_fields);
}
void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
{
if (!which) return;
if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
clistcell*cur;
mailimap_single_body_fld_param*param=0;
for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
param = (mailimap_single_body_fld_param*)cur->data;
if (param) {
target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
}
}
}
mailimap_body_fld_enc*enc = which->bd_encoding;
QString encoding("");
switch (enc->enc_type) {
case MAILIMAP_BODY_FLD_ENC_7BIT:
encoding = "7bit";
break;
case MAILIMAP_BODY_FLD_ENC_8BIT:
encoding = "8bit";
break;
case MAILIMAP_BODY_FLD_ENC_BINARY:
encoding="binary";
break;
case MAILIMAP_BODY_FLD_ENC_BASE64:
encoding="base64";
break;
case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
encoding="quoted-printable";
break;
case MAILIMAP_BODY_FLD_ENC_OTHER:
default:
if (enc->enc_value) {
char*t=enc->enc_value;
encoding=QString(enc->enc_value);
enc->enc_value=0L;
free(t);
}
}
if (which->bd_description) {
target_part->setDescription(QString(which->bd_description));
}
target_part->setEncoding(encoding);
target_part->setSize(which->bd_size);
}
void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
{
//#if 0
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err;
login();
//#endif
if (!m_imap) {
return;
}
int iii = 0;
int count = target.count();
// qDebug("imap remove count %d ", count);
mMax = count;
progress( i18n("Delete"));
QProgressBar wid ( count );
wid.setCaption( i18n("Deleting ..."));
wid.show();
while (iii < count ) {
Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
wid.setProgress( iii );
wid.raise();
qApp->processEvents();
RecMailP mail = (*target.at( iii ));
//#if 0
//qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
flist = mailimap_flag_list_new_empty();
mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
store_flags = mailimap_store_att_flags_new_set_flags(flist);
set = mailimap_set_new_single(mail->getNumber());
err = mailimap_store(m_imap,set,store_flags);
mailimap_set_free( set );
mailimap_store_att_flags_free(store_flags);
if (err != MAILIMAP_NO_ERROR) {
// odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
return;
}
// odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
/* should we realy do that at this moment? */
// err = mailimap_expunge(m_imap);
//if (err != MAILIMAP_NO_ERROR) {
// Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
// }
//#endif
//deleteMail( mail);
++iii;
}
//qDebug("Deleting imap mails... ");
err = mailimap_expunge(m_imap);
if (err != MAILIMAP_NO_ERROR) {
Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
}
}
void IMAPwrapper::deleteMail(const RecMailP&mail)
{
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err;
login();
if (!m_imap) {
return;
}
err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
flist = mailimap_flag_list_new_empty();
mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
store_flags = mailimap_store_att_flags_new_set_flags(flist);
set = mailimap_set_new_single(mail->getNumber());
err = mailimap_store(m_imap,set,store_flags);
mailimap_set_free( set );
mailimap_store_att_flags_free(store_flags);
if (err != MAILIMAP_NO_ERROR) {
// odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
return;
}
// odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
/* should we realy do that at this moment? */
err = mailimap_expunge(m_imap);
if (err != MAILIMAP_NO_ERROR) {
Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
}
//qDebug("IMAPwrapper::deleteMail 2");
}
void IMAPwrapper::answeredMail(const RecMailP&mail)
{
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err;
login();
if (!m_imap) {
return;
}
err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
flist = mailimap_flag_list_new_empty();
mailimap_flag_list_add(flist,mailimap_flag_new_answered());
store_flags = mailimap_store_att_flags_new_add_flags(flist);
set = mailimap_set_new_single(mail->getNumber());
err = mailimap_store(m_imap,set,store_flags);
mailimap_set_free( set );
mailimap_store_att_flags_free(store_flags);
if (err != MAILIMAP_NO_ERROR) {
// odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
return;
}
}
QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
{
QString body("");
encodedString*res = fetchRawPart(mail,path,internal_call);
encodedString*r = decode_String(res,enc);
delete res;
if (r) {
if (r->Length()>0) {
body = r->Content();
}
delete r;
}
return body;
}
QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
{
return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
}
encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
{
encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
encodedString*r = decode_String(res,part->Encoding());
delete res;
return r;
}
encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
{
return fetchRawPart(mail,part->Positionlist(),false);
}
int IMAPwrapper::deleteAllMail(const FolderP&folder)
{
login();
if (!m_imap) {
return 0;
}
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err = selectMbox(folder->getName());
if ( err != MAILIMAP_NO_ERROR ) {
return 0;
}
int last = m_imap->imap_selection_info->sel_exists;
if (last == 0) {
Global::statusMessage(i18n("Mailbox has no mails!"));
return 0;
}
flist = mailimap_flag_list_new_empty();
mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
store_flags = mailimap_store_att_flags_new_set_flags(flist);
set = mailimap_set_new_interval( 1, last );
err = mailimap_store(m_imap,set,store_flags);
mailimap_set_free( set );
mailimap_store_att_flags_free(store_flags);
if (err != MAILIMAP_NO_ERROR) {
Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
return 0;
}
// odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
/* should we realy do that at this moment? */
err = mailimap_expunge(m_imap);
if (err != MAILIMAP_NO_ERROR) {
Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
return 0;
}
// odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
return 1;
}
int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
{
if (folder.length()==0) return 0;
login();
if (!m_imap) {return 0;}
QString pre = account->getPrefix();
if (delemiter.length()>0 && pre.findRev(delemiter)!=((int)pre.length())-1) {
pre+=delemiter;
}
if (parentfolder) {
pre += parentfolder->getDisplayName()+delemiter;
}
pre+=folder;
if (getsubfolder) {
if (delemiter.length()>0) {
pre+=delemiter;
} else {
Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre));
return 0;
}
}
// odebug << "Creating " << pre.latin1() << "" << oendl;
int res = mailimap_create(m_imap,pre.latin1());
if (res != MAILIMAP_NO_ERROR) {
Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
return 0;
}
return 1;
}
int IMAPwrapper::deleteMbox(const FolderP&folder)
{
if (!folder) return 0;
login();
if (!m_imap) {return 0;}
int res = mailimap_delete(m_imap,folder->getName());
if (res != MAILIMAP_NO_ERROR) {
Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
return 0;
}
return 1;
}
void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
{
mailimap_status_att_list * att_list =0;
mailimap_mailbox_data_status * status=0;
clistiter * cur = 0;
int r = 0;
target_stat.message_count = 0;
target_stat.message_unseen = 0;
target_stat.message_recent = 0;
login();
if (!m_imap) {
return;
}
att_list = mailimap_status_att_list_new_empty();
if (!att_list) return;
r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
for (cur = clist_begin(status->st_info_list);
cur != NULL ; cur = clist_next(cur)) {
mailimap_status_info * status_info;
status_info = (mailimap_status_info *)clist_content(cur);
switch (status_info->st_att) {
case MAILIMAP_STATUS_ATT_MESSAGES:
target_stat.message_count = status_info->st_value;
break;
case MAILIMAP_STATUS_ATT_RECENT:
target_stat.message_recent = status_info->st_value;
break;
case MAILIMAP_STATUS_ATT_UNSEEN:
target_stat.message_unseen = status_info->st_value;
break;
}
}
} else {
// odebug << "Error retrieving status" << oendl;
}
if (status) mailimap_mailbox_data_status_free(status);
if (att_list) mailimap_status_att_list_free(att_list);
}
void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
{
login();
if (!m_imap) return;
if (!msg) return;
int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
if (r != MAILIMAP_NO_ERROR) {
Global::statusMessage("Error storing mail!");
}
}
MAILLIB::ATYPE IMAPwrapper::getType()const
{
return account->getType();
}
const QString&IMAPwrapper::getName()const
{
// odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
return account->getAccountName();
}
encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
{
// dummy
QValueList<int> path;
return fetchRawPart(mail,path,false);
}
void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
{
if (targetWrapper != this || maxSizeInKb > 0 ) {
mMax = 0;
progress( i18n("Copy"));
AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
//qDebug("IMAPwrapper::mvcpAllMails::Using generic");
// odebug << "Using generic" << oendl;
return;
}
mailimap_set *set = 0;
login();
if (!m_imap) {
return;
}
int err = selectMbox(fromFolder->getName());
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
Global::statusMessage( i18n("Copying mails on server...") );
int last = m_imap->imap_selection_info->sel_exists;
set = mailimap_set_new_interval( 1, last );
err = mailimap_copy(m_imap,set,targetFolder.latin1());
mailimap_set_free( set );
if ( err != MAILIMAP_NO_ERROR ) {
QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response);
Global::statusMessage(error_msg);
// odebug << error_msg << oendl;
return;
}
if (moveit) {
deleteAllMail(fromFolder);
}
}
void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
{
if (targetWrapper != this) {
// odebug << "Using generic" << oendl;
AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
return;
}
mailimap_set *set = 0;
login();
if (!m_imap) {
return;
}
int err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return;
}
set = mailimap_set_new_single(mail->getNumber());
err = mailimap_copy(m_imap,set,targetFolder.latin1());
mailimap_set_free( set );
if ( err != MAILIMAP_NO_ERROR ) {
QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response);
Global::statusMessage(error_msg);
// odebug << error_msg << oendl;
return;
}
if (moveit) {
deleteMail(mail);
}
}
diff --git a/kmicromail/viewmailbase.cpp b/kmicromail/viewmailbase.cpp
index c4731a7..d21696a 100644
--- a/kmicromail/viewmailbase.cpp
+++ b/kmicromail/viewmailbase.cpp
@@ -1,104 +1,104 @@
// CHANGED 2004-08-06 Lutz Rogowski
#include <qtextbrowser.h>
#include <qlistview.h>
#include <qaction.h>
#include <qlabel.h>
#include <qvbox.h>
#include <qtoolbar.h>
#include <qmenubar.h>
#include <kiconloader.h>
//#include <qpe/resource.h>
#include <klocale.h>
#include "viewmailbase.h"
//#include "opendiag.h"
ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl)
: QMainWindow(parent, name, fl)
{
setToolBarsMovable(false);
toolbar = new QToolBar(this);
menubar = new QMenuBar( toolbar );
mailmenu = new QPopupMenu( menubar );
menubar->insertItem( i18n( "Mail" ), mailmenu );
toolbar->setHorizontalStretchable(true);
addToolBar(toolbar);
reply = new QAction(i18n("Reply"),SmallIcon("reply"), 0, 0, this);
reply->addTo(toolbar);
reply->addTo(mailmenu);
forward = new QAction(i18n("Forward"),SmallIcon("forward"), 0, 0, this);
forward->addTo(toolbar);
forward->addTo(mailmenu);
attachbutton = new QAction(i18n("Attachments"),SmallIcon("attach"), 0, 0, this, 0, true);
attachbutton->addTo(toolbar);
attachbutton->addTo(mailmenu);
connect(attachbutton, SIGNAL(toggled(bool)), SLOT(slotChangeAttachview(bool)));
showHtml = new QAction( i18n( "Show Html" ), SmallIcon( "html" ), 0, 0, this, 0, true );
showHtml->addTo( toolbar );
showHtml->addTo( mailmenu );
deleteMail = new QAction(i18n("Delete Mail"),SmallIcon("trash"), 0, 0, this);
deleteMail->addTo(toolbar);
deleteMail->addTo(mailmenu);
- nextMail = new QAction(i18n("Show next mail"),SmallIcon("add"), 0, 0, this);
+ nextMail = new QAction(i18n("Show next mail"),SmallIcon("enter"), 0, 0, this);
QLabel *spacer = new QLabel(toolbar);
nextMail->addTo(toolbar);
nextMail->addTo(mailmenu);
closeMail = new QAction(i18n("Close"),SmallIcon("exit"), 0, 0, this);
//QLabel *spacer = new QLabel(toolbar);
spacer->setBackgroundMode(QWidget::PaletteButton);
toolbar->setStretchableWidget(spacer);
closeMail->addTo(toolbar);
closeMail->addTo(mailmenu);
QVBox *view = new QVBox(this);
setCentralWidget(view);
attachments = new QListView(view);
attachments->setMinimumHeight(90);
attachments->setMaximumHeight(90);
attachments->setAllColumnsShowFocus(true);
attachments->addColumn("Mime Type", 60);
attachments->addColumn(i18n("Description"), 100);
attachments->addColumn(i18n("Filename"), 80);
attachments->addColumn(i18n("Size"), 80);
attachments->setSorting(-1);
attachments->hide();
browser = new QTextBrowser(view);
// openDiag = new OpenDiag(view);
// openDiag->hide();
}
void ViewMailBase::slotChangeAttachview(bool state)
{
if (state) attachments->show();
else attachments->hide();
}
void ViewMailBase::keyPressEvent ( QKeyEvent * e )
{
if( e->key()==Qt::Key_Escape ) {
close();
e->accept();
return;
}
QWidget::keyPressEvent(e);
}