Overriding Tigase OfflineMessages class - java

I'm developing a chat application using Tigase server in the background for providing the XMPP communication. Besides that I'm using smack/asmack as a library in my application.
With every message send between the users, for the sake of the functionalities I want to implement I'm including package extensions via smack's Presence.setProperty() method,which are correctly send if both of the users are online. When one of the users is offline the Tigase server saves that message and then delivers it when the user becomes online again. The thing is that Tigase don't save the message including the packet extensions, so when the user is online again it receives only "parts" of the message send.
I found the Tigase source and found the place in the OfflineMessages class part of the xmpp.impl package, where I need to insert a line of code in order for msgoffline plugin to save the offline messages using extensions.
What is the easiest way to override the OfflineMessages class in Tigase jar file, without building the whole source code of the project?
I'm using Tigase-5.1.5-b3164 version on ubuntu server and Eclipse as IDE.

I do not know Smack library, hence I do not know what Presence.setProperty() method does. But if it does something to a presence packet (adding an extra payload to the presence status) then this will not be saved to offline message storage because.... presences are not stored in offline message storage.
If you want to modify OfflineMessages to make it store more different data than it stores now (like a specific presence packets) then there is a method: savePacketForOffLineUser with a big IF at the beginning. This is where the decision is made on what to store in an offline storage.
But, please be careful not to store ALL presences, it will kill your service and your database.
The best way to add your own plugins is to make a copy of the existing Tigase plugin (OfflineMessgae), modify it to your preferences, change a name of the plugin and ID of the plugin. Then you just put a jar with your code into Tigase jars directory and modify configuration to load your plying instead of the default one. This way you do not have to recompile Tigase sources and will be also easier for you to update to a new version.

Related

Is there a way to check where from app is installed

In my project I want to know from what website or android market, my application has been downloaded and installed.
Now I see two ways:
1) Use mobile browser storage to save location
2) Generate application for each site in the system
Both of them enough for my project, but I want to know if there is another legal ways through Play market
PackageManager.getInstallerPackageName() will give you the package name of the app which installed the app with the package name passed in as a String.
You're looking for Google Play Campaign Measurements
Google Play Campaign Measurement allows you to see which campaigns and
traffic sources are sending users to download your app from the Google
Play Store.
You can create multiple apk files, one for every distribution channel you have.
In your project, create a config.json which contains the information you want to know about the installation and current version of the installed apk file of your application. The contents of the file, varies based on the distribution channel. For example, for the version you want to upload to Google Play, it can contain :
{
"channel" : "google-play-store",
"campaign_name" : "fall 2016"
}
Now, when the user installs and runs your application for the first time, read this config.json and send this information to a remote webservice of your own, to collect statistics.

Javamail library, tracking specific emails

I am developing a Java app that reads all the emails from GMAIL and save them run time on objects of self made Class that holds some of the attributes of the email. Now I want to delete an email object and when I do that I want it to be removed from the internet as well. In order to do so I will need some information to query the GMAIL account to delete that particular email I am referring to. Is there a possible way to do that? Maybe by saving the header and then searching for that? I couldn't find a good way to do it.
I assume you are accessing GMAIL with IMAP. Then you could store the Message, call Message.setFlag(Flag.DELETED) then expunge the Folder, or search the Folder yourself. Or maybe you can search the Google Gmail api and find a better way. For example you can use the unique message ID
UPDATE this is a google project that can help you: java-gmail-imap. There is also a companion project for OAuth authentication (needed for run the sample)
I'd recommend you to take a look on James.
The Apache James Project delivers a rich set of open source modules and libraries, written in Java, related to Internet mail communication which build into an advanced enterprise mail server.
It depends on the time span between when you access the message and when you want to delete it. If it's short, and the folder is still open, you can just set the DELETED flag and close the folder to expunge the message.
But I'm assuming that you need to locate the message some time later. In that case, you should learn about IMAP UIDs. See the UIDFolder interface in JavaMail and the IMAP spec for details. In essence, you need to keep track of the folder's UIDVALIDITY value and the message's UID value. When you come back to the folder, you can make sure it's the same folder by checking the UIDVALIDITY value and then look up the message based on its UID.

Using own Java software´s custom update implementation

I have a server, and Client that are working fine, they transfer file to each other and handle commands with success. The thing is that once connected to the server, the server can ask the Client to update itself.
Since I did everything using sockets with a TCP connection, and I am NOT able to use java web start, I am looking for a way I can update the software.
One thing I thought was:
Making the java call another java software and close itself. Then the other java software, would connect to the server again and waits for the update request, so it could replace all files from the current version (lib directory and the jar main file - Im using Netbeans).
Maybe I could just send the connection Object to the Software that would update, but the main only accpets String.
So I ask two questions here:
Is this a good solution? Or is there a better one?
If I do that, how can I send the Client Object of my proto from one application to another?
I would suggest keep a property file on server having latest version of app.
Each time you start the app compare version if its updatable then download all new updates in a temp dir
After SUCCESSFUL download invoke another small application to copy those files to your lib file in order to update your app actually
At the end prompt user that app has been updated and launch the newly updated app. i would say.

Getting multiple Java pop3 clients to work with GMail

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.

Automated processing of an Email in Java

Just got a request from my boss for an application I'm working on. Basically we're getting an email address setup for an external client to submit excel files to.
What I need is a way to automatically pick up any email sent to this address, so I can take the attachment, process it and save it to a folder.
Any information of even where to start would be helpful.\
Note: We're using a lotus notes server to do this, but a generic way would be more helpful (If possible).
Email -> mailserver ->[something] -> file-on-disk.
File on disk is pretty easy to parse, use JavaMail.
The [something] could be:
listener for smtp connections (overkill)!
Pop3/imap client
Maildir/Mailbox
Edit: since I first wrote this answer, Wiser has moved and now claims to only be a unit testing tool, so take the answer below with a pinch of salt...
Svrist's answer is good, but if you want to avoid his middle step (the mailserver that writes the mail to disk for later pickup by the Java system) you can use Wiser.
Wiser lets you start an in-Java mailserver:
Wiser wiser = new Wiser();
wiser.setPort(2500);
wiser.start();
Then you can just poll it periodically for mail:
for (WiserMessage message : wiser.getMessages())
{
String envelopeSender = message.getEnvelopeSender();
String envelopeReceiver = message.getEnvelopeReceiver();
MimeMessage mess = message.getMimeMessage();
// mail processing goes here
}
Use a mail in database (your Domino administrator can set that up for you but it's in the help file as well).
In that database, you can create an agent that runs periodically to process all new documents. That agent will use the EmbeddedObjects property of the NotesRichTextItem class and the ExtractFile method of the NotesEmbeddedObject class to get a handle on the file attachment and extract it to the location you specify.
For example, this script goes through all the file attachments, object links, and embedded objects in the Body item of a document. Each time it finds a file attachment, it detaches the file to the SAMPLES directory on the C drive and removes the attachment from the document
Dim doc As NotesDocument
Dim rtitem As Variant
'...set value of doc...
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
Call o.ExtractFile( "c:\samples\" & o.Source )
Call o.Remove
Call doc.Save( False, True )
End If
End Forall
End If
I've done quite a bit lately with Java agents on Domino servers. The Domino 8.5 server supports Java 6 and its embedded so it won't take someone with a bit of Domino development experience long to put together an agent that runs when new mail arrives. In LotusScript its even easier but that needs more specialised skills which you'd probably need to get a contractor in to provide.
The limitation your likely to encounter concerns the extracted file, you can easily place it on the Domino server's file structure but you may be limited by the OS security from placing it on a different server.
Lotus Notes/Domino stores mail in a Notes database. There are APIs available for getting documents (emails), reading field values (From, Subject), and detaching files.
APIs include
-LotusScript (VB variant, available within the Notes database)
-Java (from within or external to the database)
-C API (external)
-Same API available through COM server
You can create a "scheduled agent" within the database (using LotusScript or Java) that can locate documents created since it last ran, locate the attachments, and extract them. The agent will need to be signed with an ID that has the appropriate permissions on the server, including those required to write to the file system and initiate any other processes.
External to the database, you can use any API except LotusScript to log-in to the server/mail database, and follow a similar process, e.g. extracting the files locally on a client or separate server. C API and COM require a notes client install, but Java applications can be set up to run via CORBA/DIIOP without a full install.
Consult the Domino Designer help (or IBM's website for C API) for more information.
As to a "generic way" to do this, if you are accessing data in Notes and needing to extract attachments, I believe these APIs are your best option. If you envision porting the application to another mail system, consider decoupling the API routines via an "interface" so you only need to add a new implementation of that interface to support a new mail system.
You can access Notes Documents relatively easily using DIIOP, would be a lot easier than going down the C Api road...
Try POP3Client in the Net Commons package; it'll let your Java program check for new mail for a particular account at whatever interval you want (every few minutes? hourly?), and get/delete messages as desired.
SMTP/POP3 can be enabled on the Domino server. Worked with this before and gotten Squirrel Mail running with it. SMTP is a bit resource intensive, but well worth the effort because then you don't have to descend into LotusLand to get things working. Just write a small Java CLI program that will check a specific email box (POP3 or SMTP), and parse through the messages, pulling the attachments and placing them where needed.
Plenty of documentation and examples here:
http://java.sun.com/products/javamail/
The techniques that you develop taking this approach will be more widely applicable in your future career than anything Lotus/Domino specific.
No matter what you do, you'll need an understanding of the Lotus Notes data structures. The good news is that a fully automated solution can be built in Notes very easily.
Your best bet is to have it built within Notes, and it can be set up to run automatically whenever new mail is received. Gary's answer is dead on, but without any experience, it would probably be hard to figure out how to implement it yourself. On the other hand, it really shouldn't take any competent Notes programmer more than an hour or two to set it up.

Categories