I want the sender address come from component instead of global default or project specific. I have come up with the idea to take the component lead and make that user the sender. This is only for our support project which seperates different customers by components.
I have found my way to edit IssueMailQueueItem.java to enable this feature. But I have a problem extracting the email address from the component lead. And due to difficulties to Debug at runtime I asks if someone have a word of wisdom in this matter.
This is my code so far. Far from complete. But it should work. And yes if it's more than one component it will loop around until the end.
------
...
<address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">// Get default project email</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">String emailSender = OFBizPropertyUtils.getPropertySet(project).getString(ProjectKeys.EMAIL_SENDER);</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;"> </address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">// Collect components to issue and iterate through</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">final Collection<ProjectComponent> components = issue.getComponentObjects();</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">for (Iterator iterator = components.iterator(); iterator.hasNext(); )</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">{</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">// Get component lead</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">ProjectComponent component = (ProjectComponent) iterator.next();</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">String componentLeadName = component.getLead();</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;"> </address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">if (componentLeadName != null && componentLeadName != "")</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">{</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">User componentLeadUser = ComponentManager.getInstance().getUserUtil().getUserObject(componentLeadName);</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">emailSender = (componentLeadUser != null ? componentLeadUser.getEmailAddress() : emailSender);</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">}</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;"> }</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;"> </address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">final String sender = emailSender;</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">...</address><address style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; word-wrap: break-word; background-position: initial initial; background-repeat: initial initial; border-width: 0px; padding: 0px;">-----</address>What am I doing wrong? What am I missing? Is there any other way to handle this feature request?
Community moderators have prevented the ability to post new answers.
I finally went for the solution to take in the description from the component. Analysis the given description for a [mail][/mail] tag and takes the text in between. In this case a email address. Use that address as the sender.
It's a better solution because it leaves the component lead alone. If there will be one in the future. I can be nice and post the final code here.
// Get default project or jira email
String emailSender = OFBizPropertyUtils.getPropertySet(project).getString(ProjectKeys.EMAIL_SENDER);
final String projectKey = issue.getProjectObject().getKey();if (projectKey.equals("SUP"))
{
// Collect components that relates the issue and iterate through
final Collection<ProjectComponent> components = issue.getComponentObjects();
for (Iterator iterator = components.iterator(); iterator.hasNext(); )
{
// Get component lead and description
ProjectComponent component = (ProjectComponent) iterator.next();
String componentDescription = component.getDescription();
if (componentDescription != null)
{
// Extract an email address between the [mail][/mail] tags
String emailPattern = null;
Pattern MY_PATTERN = Pattern.compile("\\[mail](.*?)\\[/mail]");
Matcher m = MY_PATTERN.matcher(componentDescription.toLowerCase());
// Get the string that matched the pattern
while (m.find()) { emailPattern = m.group(1); }
// Did we get an email? If so save it.
emailSender = (emailPattern != null ? emailPattern : emailSender);
}
}
}
final String sender = emailSender;
I feel sorry for the component leads, who would start getting all the email replies, rather than the system capturing them, but if it works for you..
As for difficulties debugging Jira, remote socket debugging should work flawlessly, a somewhat verbose guide is here:http://www.scribd.com/doc/18984333/Configuring-Eclipse-for-Debugging-JIRA-Plugins
@echo Jamies comment ( I would comment, but the system is telling me I have 228 chars left, but when commenting, I get an eror: No more than 600 characters on comment body)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The component lead is going to be a dummy user. No one will use the user. But i am thinking about to just use "getDescription()" and use some kind of tags to extract the components sender address.
The replies bounces to the same address [support@....] and get processed by procmail. And sorted to the correct folder.
I am not doing a plugin. I am using the external-source folder to implement my changes. I have only done a HelloWorld gadget plugin so far. So due to timepressure i had no choice. But thanks for the guide. Now i can setup a proper development enviroment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The problem here was stupid. The components lead email was wrongly set at first. Thereafter I tried to debug a working code with forcing the sender string to the subject but only got null back. Therefore I didnt know if my code gave null or if it was my poor try to "debug" by using the subject was wrong.
Long story short. The given code works.
Note to self: check component lead email address before starting asking about help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What's the problem? How doesn't it work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.