return sendFile(switchboard, email, file);
}
private MsnFileTransfer sendFile(MsnSwitchboard switchboard, Email email, File file)
{
MsnslpRequest req = new MsnslpRequest();
MsnFileInviteMessage invite = new MsnFileInviteMessage()
{
protected void receivedResponse(MsnSession session, MsnIncomingMessage response)
{
if((getOffset() + getCurrentLength()) < getTotalLength())
{
binaryHeader.rewind();
setOffset(getCurrentLength());
long currLen = getTotalLength() - getCurrentLength();
if(currLen > MsnP2PDataMessage.MAX_DATA_LENGTH)
setCurrentLength(MsnP2PDataMessage.MAX_DATA_LENGTH);
else
setCurrentLength((int)currLen);
OutgoingMSG[] outgoingOkMessages = toOutgoingMsg(
session.getMessenger().getActualMsnProtocol());
for (OutgoingMSG outgoingOkMessage : outgoingOkMessages)
{
session.sendSynchronousMessage(outgoingOkMessage);
}
}
}
};
invite.setSlpMessage(req);
int lastRandomIdentifier = NumberUtils.getIntRandom();
// Set the destination for the message (the MsnObject creator)
invite.setP2PDest(email.getEmailAddress());
// Set the binary Header
invite.setIdentifier(MsnP2PBaseIdGenerator.getInstance().getNextId());
invite.setFlag(MsnP2PMessage.FLAG_OLD_NONE);
invite.setField7(lastRandomIdentifier);
invite.setField8(0);
invite.setField9(0);
// Set body
req.setRequestMethod(MsnFileInviteMessage.METHOD_INVITE);
req.setRequestURI("MSNMSGR:" + email.getEmailAddress());
req.setTo("<msnmsgr:" + email.getEmailAddress() + ">");
req.setFrom("<msnmsgr:" +
session.getMessenger().getOwner().getEmail().getEmailAddress() + ">");
req.setVia(
"MSNSLP/1.0/TLP ;branch=" + generateNewCallId());
req.setCSeq(0);
req.setCallId(generateNewCallId());
req.setMaxForwards(0);
req.setContentType("application/x-msnmsgr-sessionreqbody");
StringHolder body = new StringHolder();
body.setProperty(MsnFileInviteMessage.KEY_GUID_EUF,
MsnFileInviteMessage.GUID_EUF);
body.setProperty("SessionID", lastRandomIdentifier);
body.setProperty("AppID", 2);
try
{
body.setProperty(MsnP2PInvitationMessage.KEY_CONTEXT,
MsnFileContextParser.getEncodedContext(file));
}
catch (UnsupportedEncodingException ex)
{
logger.error("", ex);
}
req.setBody(body.toString() +
JmlConstants.LINE_SEPARATOR + "\0");
// Get the size of the message to be setted
int slpMessageLength = Charset.encodeAsByteArray(req.toString()).length;
invite.setTotalLength(slpMessageLength);
if(slpMessageLength > MsnP2PDataMessage.MAX_DATA_LENGTH)
{
invite.setCurrentLength(MsnP2PDataMessage.MAX_DATA_LENGTH);