I am trying to save a whole mailbox onto disk using the JavaMail API (in essence, perform a full backup_. I can successfully read all the relevant folders into memory and then sever the connection to my mail server. What I can't figure out is how to actually store the folders and/or individual messages if need be on my disk.
I've tried searching around and came up with an interesting link (below) but can't figure this out. Does anyone have any advice on where to get started? I appreciate it, thanks
http://www.oracle.com/technetwork/java/javamail/faq/index.html#serialize
quick note: I tried using a class that contained an ArrayList of type Folder(JavaMail class) and make that serializable, but I still had an exception thrown when I tried to write to disk. I've been working on this problem for about two days now and I could use some pointers. Thanks!
You found the FAQ, but you missed this entry:
How do I store mail messages on my local disk?
And, as the FAQ entry you found says, you can't just serialize the Message objects, let alone the Folder objects.
If all this seems too complicated for you, the simplest approach might be to get an IMAP server that you run on your local machine, then copy the messages from your remote IMAP server to your local IMAP server. The JavaMail FAQ has pointers to IMAP servers you can install locally, and a little web searching will turn up more. JavaMail also comes with a demo program (populate.java) for copying folders.
Related
I've been searching for hours and I could not find an answer to this: Can you upload files to Oracle Cloud's ObjectStorage using MultiPartUpload via a PreAutheticated Request? I know it's possible in just in one go.
I basically need to allow users to upload large files to Object Storage through a Java client and I would like to do it via PAR's. If it is possible, how would that happen? Meaning, do you call the CreateMultiPartUpload first and the upload the parts via the PAR? Do you call the CreateMultiPartUpload with the PAR?
It is not possible to use multipart uploads with a PAR today, unfortunately. We do hope to make this available very soon, though.
hope you are well!
I need to get contact list from Outlook Exchange. The problem is that I have to use Java and I totally don't know where to start. Can anyone tell me what I have to do firstly?
How can I programmaticaly connect to Outlook?
If you are running on Windows you can probably use JaWin. It is an open source library that wraps COM object and provides you a Java API to access them. As far as I remember its distribution contains example of how to connect to MS Exchange server.
Other similar packages I know are
Jintegra (costs some money)
Jinterop (open source too)
Both libraries implement DCOM protocol in Java, so you can run application that uses them on any platform and connect to exchange server.
Other way is to use POP3 or SMTP protocol also supported by Exchange. There are a lot of packages that support them, e.g. JavaMail.
And the last way: if your application is running on client side, i.e. on the client's computer it can parse files created by outlook itself. I do not remember where these files are stored but I remember that many years ago I have discovered the issue and saw that all emails are stored in file system in clear text format.
EDIT: Recently I found out JACOB: other library that uses JNI (like JaWin).
I am currently looking into copying public folders and the containing emails from a MS exchange server 2003 to a local directory in window explorer, in the same structure, so I will then have the directories and the .msg files on my local drive.
I have researched this, but unsure what route to go down. MAPI, Webdav, IMAP, Javamail etc.
I will be creating a Java app to do the copying also. Also open to any other software development recommendations (Perl, C++)
What would be the best protocol to do this and also anyone got any links where I can do some more research on this subject?
Many thanks
JavaMail can't create .msg files, which are a proprietary Microsoft format, so if that's a key part of your requirements you'll need to look at something else.
If a .eml file (effectively a MIME format file) or a Unix mail format file would be sufficient, you can consider JavaMail.
JavaMail includes a demo program that copies a mailbox hierarchy from one store to another.
There are several options for storing messages locally.
Run an IMAP server on the local machine. This is probably the easiest.
Use a local store provider, such as the JavaMail mbox provider or another such provider from the JavaMail Third Party Products page.
Write your own code to store each message to disk using the MimeMessage.writeTo method.
Hope that helps.
Say I have DemoServer project that only logs anything and I created another project say LogServer. So here's what I want to do; I will run both project simultaneously, as the DemoServer is running it will just keep on logging anything and in the LogServer project it should be able to access the logs that the DemoServer generates and save it to a new text file every 1 minute. Since this is the first time I'm doing this I find it hard to figure out how will the two project communicate? Can someone explain in detail how can i achieve this? Please also post links that might help me solve my problem.
I'd go with a local socket which is quite straightforward to implement in Java and can be later used also when DemoServer and LogServer are on different machines.
Developing it should be quite easy:
create your own LogMessage class
create a simple client/server infrastructure by using TCP sockets, take a look here
wrap the socket streams by using ObjectInputStream and ObjectOutputStream to be able to use serialization
just send logs by encapsulating them in messages from one process to the other and you are done
I would suggest you dig into oVirt source code (you can git clone the source) and see what we do with the log collector application.
There are many options to solve your problem -
A. Have your application log into a shared storage (i.e - nfs share) - one that both it and the log server can access. A cron job will run a periodic script that will copy the files that were last accessed, let's say - one hour ago, into a folder, that the the log server can access.
B. Use log4j and write your own Appender that will send the stuff you want log server to collect also to log server (via a file as suggested in section A, or via any other mean) - this way you will be able to contol on a category level basis what stuff the Log server can actually read
I have written a nice program in Java that connects to a gmail account and download atachments sent to it. Once an attachment has been downloaded, it is marked as read and is not downloaded ever again. This program will have to run in multiple instances with each program downloading unique attachments so that a single attachment is never downloaded twice. The problem is that at the moment if the attachment is of a decent size, one program is still downloading it, when another instance connects and also starts to download the attachment before it has been marked as read.
I have tried checking and setting various flags and checking whether the folder is open, nothing seems to work. Any solutions?
Update: Thank you for the quick answers, sadly IMAP is not an option due to other reasons.
Consider using IMAP instead - it is designed for client-server interaction.
From RFC1939 (Post Office Protocol - Version 3):
POP3 is not intended to provide
extensive manipulation operations of
mail on the server; normally, mail is
downloaded and then deleted. A more advanced (and complex) protocol, IMAP4, is discussed in RFC1730.
I don't think POP3 is made for multiple simultaneous access.
Ask yourself this: do i really need multiple processes accessing the same mailbox?
If you do, you'll have to find a way to have these processes communicate to each other.
Use a common database or server process to coordinate actions.
IMAP does have more options, but i'm not sure if you can "lock" a single mail to mark it as being processed.
As the others have mentioned, POP3 isn't really intended for this kind of scenario.
If you absolutely have to use POP3, I'd suggest downloading all the e-mail to an intermediate server which sorts the messages and makes them available for each of the other clients.
It sounds like you're just trying to distribute the processing of the e-mails. If that's the case, you can just have each client connect to your intermediate server to retrieve the next available message.
I'm not sure what your constraints are, but you may even want to consider receiving the attachments some other way besides e-mail. If people are uploading files, you could set up a web form that automatically sends each file to the next available instance of your application for processing.
If you need to stay with a POP3 connection, you could keep a local database of previously downloaded message ids. Then new instances could check against that before downloading again. The best solution is just to use IMAP, though, as IMAP is able to set the read/unread flags before downloading.
You could mark the mail as read before starting the download, and then start downloading it.